org.eclipse.net4j.util.io

## Class DigestWriter

- java.lang.Object
- - java.io.Writer
  - - java.io.FilterWriter
    - - org.eclipse.net4j.util.io.DigestWriter

- All Implemented Interfaces:
    Closeable, Flushable, Appendable, AutoCloseable

      public class DigestWriter
      extends FilterWriter

  Since:
    3.1
  Author:
    Eike Stepper

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected MessageDigest` | `digest` The message digest associated with this stream.

    - ### Fields inherited from class java.io.FilterWriter

      `out`

    - ### Fields inherited from class java.io.Writer

      `lock`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `DigestWriter(Writer writer, MessageDigest digest)` Creates a digest writer, using the specified writer and message digest.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `MessageDigest` | `getMessageDigest()` Returns the message digest associated with this writer.
    `void` | `on(boolean on)` Turns the digest function on or off.
    `void` | `setMessageDigest(MessageDigest digest)` Associates the specified message digest with this writer.
    `String` | `toString()` Prints a string representation of this digest output stream and its associated message digest object.
    `void` | `write(char[] cbuf, int off, int len)`
    `void` | `write(int c)`
    `void` | `write(String str, int off, int len)`

    - ### Methods inherited from class java.io.FilterWriter

      `close, flush`

    - ### Methods inherited from class java.io.Writer

      `append, append, append, write, write`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### digest

          protected MessageDigest digest

      The message digest associated with this stream.

  - ### Constructor Detail

    - #### DigestWriter

          public DigestWriter(Writer writer,
                              MessageDigest digest)

      Creates a digest writer, using the specified writer and message digest.
      Parameters:
        `writer` - the writer.
        `digest` - the message digest to associate with this writer.

  - ### Method Detail

    - #### getMessageDigest

          public MessageDigest getMessageDigest()

      Returns the message digest associated with this writer.
      Returns:
        the message digest associated with this writer.
      See Also:
        `setMessageDigest(java.security.MessageDigest)`

    - #### setMessageDigest

          public void setMessageDigest(MessageDigest digest)

      Associates the specified message digest with this writer.
      Parameters:
        `digest` - the message digest to be associated with this writer.
      See Also:
        `getMessageDigest()`

    - #### write

          public void write(int c)
                     throws IOException

      Overrides:
        `write` in class `FilterWriter`
      Throws:
        `IOException`

    - #### write

          public void write(char[] cbuf,
                            int off,
                            int len)
                     throws IOException

      Overrides:
        `write` in class `FilterWriter`
      Throws:
        `IOException`

    - #### write

          public void write(String str,
                            int off,
                            int len)
                     throws IOException

      Overrides:
        `write` in class `FilterWriter`
      Throws:
        `IOException`

    - #### on

          public void on(boolean on)

      Turns the digest function on or off. The default is on. When it is on, a call to one of the `write` methods results in an update on the message digest. But when it is off, the message digest is not updated.
      Parameters:
        `on` - true to turn the digest function on, false to turn it off.

    - #### toString

          public String toString()

      Prints a string representation of this digest output stream and its associated message digest object.
      Overrides:
        `toString` in class `Object`

Copyright (c) 2014 Eike Stepper (Berlin, Germany) and others.
All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html