Class EncryptedInputStream

java.lang.Object
  extended byjava.io.InputStream
      extended byjava.io.FilterInputStream
          extended byEncryptedInputStream

public class EncryptedInputStream
extends FilterInputStream


Field Summary
private  int blocksize
           
private  byte[] buf
           
private  boolean DEBUG
           
private static int DEFAULT_BUFFER_SIZE
           
private  int end
           
private  boolean HIT_EOF
           
private  Object key
           
private static int KEY_SIZE
           
private  int pos
           
 
Fields inherited from class java.io.FilterInputStream
in
 
Fields inherited from class java.io.InputStream
 
Constructor Summary
EncryptedInputStream(InputStream input)
          Creates an EncryptedInputStream with the default buffer size
EncryptedInputStream(InputStream input, int bufsize)
          Create an EncryptedInputStream with the given input stream and buffer size
 
Method Summary
 int available()
          Return number of bytes available to read.
 void close()
           
private  void ensureOpen()
          Make sure the stream is still open
private  void fill()
          Read from the underlying input stream and decrypt the data.
 boolean markSupported()
          Return true if this stream supports mark and reset.
 int read()
          Read the next byte of data from the input stream.
 int read(byte[] b, int off, int len)
          Read up to b.length bytes of data into a byte array.
private  Object readKey()
          Read the key from the keyfile
 
Methods inherited from class java.io.FilterInputStream
mark, read, reset, skip
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_BUFFER_SIZE

private static final int DEFAULT_BUFFER_SIZE
See Also:
Constant Field Values

KEY_SIZE

private static final int KEY_SIZE
See Also:
Constant Field Values

DEBUG

private final boolean DEBUG
See Also:
Constant Field Values

HIT_EOF

private boolean HIT_EOF

buf

private byte[] buf

pos

private int pos

end

private int end

blocksize

private int blocksize

key

private Object key
Constructor Detail

EncryptedInputStream

public EncryptedInputStream(InputStream input)
                     throws Exception
Creates an EncryptedInputStream with the default buffer size

Parameters:
input - Underlying input stream

EncryptedInputStream

public EncryptedInputStream(InputStream input,
                            int bufsize)
                     throws Exception
Create an EncryptedInputStream with the given input stream and buffer size

Parameters:
input - the underlying input stream
bufsize - the buffer size (in bytes)
Method Detail

fill

private void fill()
           throws IOException
Read from the underlying input stream and decrypt the data. Put the decrypted data into the buffer. any read() call will bump along the pos variable, this should truncate the array to cut off any data before the pos.

Throws:
IOException

readKey

private Object readKey()
                throws Exception
Read the key from the keyfile

Returns:
the key object.
Throws:
Exception

available

public int available()
Return number of bytes available to read. This will only return > 0 if there's more than 16 bytes in the buffer, so it can decrypt data.

Returns:
number of bytes available.

read

public int read()
         throws IOException
Read the next byte of data from the input stream. Returns -1 if the end of the stream has been reached. This method blocks until a byte can be read.

Returns:
the byte read, or -1 if end of stream.
Throws:
IOException

read

public int read(byte[] b,
                int off,
                int len)
         throws IOException
Read up to b.length bytes of data into a byte array. Like read(), this will block until data is available. - Wrapper around read(byte[], int off, int len)

Parameters:
b - byte array buffer into which the data is read.
Throws:
IOException

ensureOpen

private void ensureOpen()
                 throws IOException
Make sure the stream is still open

Throws:
IOException

markSupported

public boolean markSupported()
Return true if this stream supports mark and reset. This stream does not yet support mark and reset, so it will always return false.


close

public void close()
           throws IOException
Throws:
IOException