org.spaceroots.jarmor
Class Base32Decoder

java.lang.Object
  extended byjava.io.InputStream
      extended byjava.io.FilterInputStream
          extended byorg.spaceroots.jarmor.AbstractDecoder
              extended byorg.spaceroots.jarmor.Base32Decoder

public class Base32Decoder
extends org.spaceroots.jarmor.AbstractDecoder

This class decodes a text stream containing into a binary stream.

The Base32 encoding is suitable when binary data needs to be transmitted or stored as text, when case insensitivity is needed. It is defined in RFC 3548 The Base16, Base32, and Base64 Data Encodings by S. Josefsson

Author:
Luc Maisonobe
See Also:
Base32Encoder

Field Summary
protected  byte[] encoded
          Encoded bytes buffer.
protected  boolean endReached
          End indicator.
protected  int nEncoded
          Number of bytes already in the encoded array.
 
Fields inherited from class java.io.FilterInputStream
in
 
Constructor Summary
Base32Decoder(InputStream in)
          Create a decoder wrapping a source of encoded data.
Base32Decoder(InputStream in, boolean strictRFCCompliance)
          Create a decoder wrapping a source of encoded data.
 
Method Summary
 int available()
          Get the number of bytes that can be read from this input stream without blocking.
 void close()
          Close the stream.
protected  int filterBytes()
          Filter some bytes from the underlying stream.
 boolean markSupported()
          Check if the FilterInputStream.mark(int) and FilterInputStream.reset() methods are supported.
protected  void putFilteredByte(int b)
          Put a filtered byte in the buffer.
 int read()
          Reads the next byte of data from this input stream.
 int read(byte[] b, int off, int len)
          Reads up to len bytes of data from this input stream into an array of bytes.
protected  int readEncodedBytes()
          Read new encoded bytes.
 long skip(long n)
          Skips over and discards n bytes of data from the input stream.
 
Methods inherited from class java.io.FilterInputStream
mark, read, reset
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

encoded

protected byte[] encoded
Encoded bytes buffer.


nEncoded

protected int nEncoded
Number of bytes already in the encoded array.


endReached

protected boolean endReached
End indicator.

Constructor Detail

Base32Decoder

public Base32Decoder(InputStream in)
Create a decoder wrapping a source of encoded data.

The decoder built using this constructor will strictly obey RFC 3548. This means that if some encoded bytes do not belong to the Base32 alphabet, an IOException will be thrown at read time.

Note that calling this constructor is equivalent to calling Base32Decoder(in, -true).

Parameters:
in - source of encoded data to decode

Base32Decoder

public Base32Decoder(InputStream in,
                     boolean strictRFCCompliance)
Create a decoder wrapping a source of encoded data.

If the decoder built using this constructor strictly obeys RFC 3548 and some encoded bytes do not belong to the Base32 alphabet, then an IOException will be thrown at read time.

Note that calling this constructor with strictRFCComplianceset to true is equivalent to calling the one argument constructor.

Parameters:
in - source of encoded data to decode
strictRFCCompliance - if true, characters outside of the Base32 alphabet will trigger an IOException at read time, otherwise they will be silently ignored
Method Detail

filterBytes

protected int filterBytes()
                   throws IOException
Filter some bytes from the underlying stream.

Returns:
number of bytes inserted in the filtered bytes buffer or -1 if the underlying stream has no bytes left
Throws:
IOException - if the underlying stream throws one
See Also:
AbstractDecoder.putFilteredByte(int)

available

public int available()
              throws IOException
Get the number of bytes that can be read from this input stream without blocking.

Returns:
number of bytes that can be read from this input stream without blocking
Throws:
IOException - if the underlying stream throws one

read

public int read()
         throws IOException
Reads the next byte of data from this input stream.

Returns:
the next byte of data, or -1 if the end of the stream is reached.
Throws:
IOException - if the underlying stream throws one

read

public int read(byte[] b,
                int off,
                int len)
         throws IOException
Reads up to len bytes of data from this input stream into an array of bytes.

Parameters:
b - the buffer into which the data is read.
off - the start offset of the data.
len - the maximum number of bytes read.
Returns:
the total number of bytes read into the buffer, or -1 if there is no more data because the end of the stream has been reached
Throws:
IOException - if the underlying stream throws one

skip

public long skip(long n)
          throws IOException
Skips over and discards n bytes of data from the input stream.

Parameters:
n - the number of bytes to be skipped
Returns:
the actual number of bytes skipped
Throws:
IOException - if the underlying stream throws one

close

public void close()
           throws IOException
Close the stream.

Throws:
IOException - if the underlying stream throws one

markSupported

public boolean markSupported()
Check if the FilterInputStream.mark(int) and FilterInputStream.reset() methods are supported.

Returns:
always false

readEncodedBytes

protected int readEncodedBytes()
                        throws IOException
Read new encoded bytes.

Returns:
number of bytes read or -1 if the underlying stream has no bytes left
Throws:
IOException - if the underlying stream throws one

putFilteredByte

protected void putFilteredByte(int b)
Put a filtered byte in the buffer.

The filtered bytes buffer will be expanded if it already contains too many pending bytes.

Parameters:
b - byte to put in the filtered buffer


Copyright © 2005-2006 Luc Maisonobe. All Rights Reserved.