Class PassphraseEncryptedInputStream

java.lang.Object
java.io.InputStream
com.unboundid.util.PassphraseEncryptedInputStream
All Implemented Interfaces:
Closeable, AutoCloseable

This class provides an InputStream implementation that can read encrypted data written by the PassphraseEncryptedOutputStream. It will use a provided password in conjunction with a PassphraseEncryptedStreamHeader that will either be read from the beginning of the stream or provided in the constructor.
  • Constructor Details

  • Method Details

    • read

      public int read() throws IOException
      Retrieves a single byte of decrypted data read from the underlying input stream.
      Specified by:
      read in class InputStream
      Returns:
      A value that is between 0 and 255 representing the byte that was read, or -1 to indicate that the end of the input stream has been reached.
      Throws:
      IOException - If a problem is encountered while reading or decrypting the data.
    • read

      public int read(@NotNull byte[] b) throws IOException
      Reads decrypted data and writes it into the provided byte array.
      Overrides:
      read in class InputStream
      Parameters:
      b - The byte array into which the decrypted data will be placed, starting with an index of zero. It must not be null or empty.
      Returns:
      The number of bytes added to the provided buffer, or -1 if the end of the input stream has been reached and there is no more data to read.
      Throws:
      IOException - If a problem is encountered while reading or decrypting the data.
    • read

      public int read(@NotNull byte[] b, int offset, int length) throws IOException
      Reads decrypted data and writes it into the specified portion of the provided byte array.
      Overrides:
      read in class InputStream
      Parameters:
      b - The byte array into which the decrypted data will be placed. It must not be null or empty.
      offset - The position in the provided array at which to begin adding the decrypted data. It must be greater than or equal to zero and less than the length of the provided array.
      length - The maximum number of bytes to be added to the given array. This must be greater than zero, and the sum of the offset and length must be less than or equal to the length of the provided array.
      Returns:
      The number of bytes added to the provided buffer, or -1 if the end of the input stream has been reached and there is no more data to read.
      Throws:
      IOException - If a problem is encountered while reading or decrypting the data.
    • skip

      public long skip(long maxBytesToSkip) throws IOException
      Skips over and discards up to the specified number of bytes of decrypted data obtained from the underlying input stream.
      Overrides:
      skip in class InputStream
      Parameters:
      maxBytesToSkip - The maximum number of bytes to skip.
      Returns:
      The number of bytes that were actually skipped.
      Throws:
      IOException - If a problem is encountered while skipping data from the stream.
    • available

      public int available() throws IOException
      Retrieves an estimate of the number of decrypted byte that are available to read from the underlying stream without blocking. Note that some implementations always return a value of zero, so a return value of zero does not necessarily mean that there is no data available to read.
      Overrides:
      available in class InputStream
      Returns:
      An estimate of the number of decrypted bytes that are available to read from the underlying stream without blocking.
      Throws:
      IOException - If a problem is encountered while attempting to determine the number of bytes available to read.
    • close

      public void close() throws IOException
      Closes this input stream and the underlying stream.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Overrides:
      close in class InputStream
      Throws:
      IOException - If a problem is encountered while closing the stream.
    • markSupported

      public boolean markSupported()
      Indicates whether this input stream supports the use of the mark(int) and reset() methods.
      Overrides:
      markSupported in class InputStream
      Returns:
      true if this input stream supports the mark and reset methods, or false if not.
    • mark

      public void mark(int readLimit)
      Marks the current position in this input stream so that the caller may return to that spot (and re-read the data) using the reset() method. Use the markSupported() method to determine whether this feature is supported for this input stream.
      Overrides:
      mark in class InputStream
      Parameters:
      readLimit - The maximum number of bytes expected to be read between the mark and the call to the reset method.
    • reset

      public void reset() throws IOException
      Attempts to reset the position of this input stream to the position of the last call to mark(int). Use the markSupported() method to determine whether this feature is supported for ths input stream.
      Overrides:
      reset in class InputStream
      Throws:
      IOException - If a problem is encountered while performing the reset (e.g., no mark has been set, if too much data has been read since setting the mark, or if the mark and reset methods are not supported).
    • getEncryptionHeader

      Retrieves an encryption header with details about the encryption used when the data was originally written.
      Returns:
      An encryption header with details about the encryption used when the data was originally written.