Package com.kitfox.svg.xml.cpx
Class CPXInputStream
- java.lang.Object
-
- java.io.InputStream
-
- java.io.FilterInputStream
-
- com.kitfox.svg.xml.cpx.CPXInputStream
-
- All Implemented Interfaces:
CPXConsts
,java.io.Closeable
,java.lang.AutoCloseable
public class CPXInputStream extends java.io.FilterInputStream implements CPXConsts
This class reads/decodes the CPX file format. This format is a simple compression/encryption transformer for XML data. This stream takes in encrypted XML and outputs decrypted. It does this by checking for a magic number at the start of the stream. If absent, it treats the stream as raw XML data and passes it through unaltered. This is to aid development in debugging versions, where the XML files will not be in CPX format. See http://java.sun.com/developer/technicalArticles/Security/Crypto/
-
-
Field Summary
Fields Modifier and Type Field Description (package private) byte[]
decryptBuffer
(package private) byte[]
head
(package private) int
headPtr
(package private) int
headSize
(package private) byte[]
inBuffer
(package private) java.util.zip.Inflater
inflater
(package private) boolean
reachedEOF
(package private) java.security.SecureRandom
sec
(package private) int
xlateMode
-
Fields inherited from interface com.kitfox.svg.xml.cpx.CPXConsts
MAGIC_NUMBER, XL_PLAIN, XL_ZIP_CRYPT
-
-
Constructor Summary
Constructors Constructor Description CPXInputStream(java.io.InputStream in)
Creates a new instance of CPXInputStream
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
available()
This method returns 1 if we've not reached EOF, 0 if we have.void
close()
Closes this input stream and releases any system resources associated with the stream.protected boolean
decryptChunk()
Call when inflater indicates that it needs more bytes.boolean
markSupported()
We do not allow markingint
read()
Reads the next byte of data from this input stream.int
read(byte[] b)
Reads up tobyte.length
bytes of data from this input stream into an array of bytes.int
read(byte[] b, int off, int len)
Reads up tolen
bytes of data from this input stream into an array of bytes.long
skip(long n)
Skips bytes by reading them into a cached buffer
-
-
-
Method Detail
-
markSupported
public boolean markSupported()
We do not allow marking- Overrides:
markSupported
in classjava.io.FilterInputStream
-
close
public void close() throws java.io.IOException
Closes this input stream and releases any system resources associated with the stream. This method simply performsin.close()
.- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Overrides:
close
in classjava.io.FilterInputStream
- Throws:
java.io.IOException
- if an I/O error occurs.- See Also:
FilterInputStream.in
-
read
public int read() throws java.io.IOException
Reads the next byte of data from this input stream. The value byte is returned as anint
in the range0
to255
. If no byte is available because the end of the stream has been reached, the value-1
is returned. This method blocks until input data is available, the end of the stream is detected, or an exception is thrown.This method simply performs
in.read()
and returns the result.- Overrides:
read
in classjava.io.FilterInputStream
- Returns:
- the next byte of data, or
-1
if the end of the stream is reached. - Throws:
java.io.IOException
- if an I/O error occurs.- See Also:
FilterInputStream.in
-
read
public int read(byte[] b) throws java.io.IOException
Reads up tobyte.length
bytes of data from this input stream into an array of bytes. This method blocks until some input is available.This method simply performs the call
read(b, 0, b.length)
and returns the result. It is important that it does not doin.read(b)
instead; certain subclasses ofFilterInputStream
depend on the implementation strategy actually used.- Overrides:
read
in classjava.io.FilterInputStream
- Parameters:
b
- the buffer into which the data is 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:
java.io.IOException
- if an I/O error occurs.- See Also:
FilterInputStream.read(byte[], int, int)
-
read
public int read(byte[] b, int off, int len) throws java.io.IOException
Reads up tolen
bytes of data from this input stream into an array of bytes. This method blocks until some input is available.This method simply performs
in.read(b, off, len)
and returns the result.- Overrides:
read
in classjava.io.FilterInputStream
- 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:
java.io.IOException
- if an I/O error occurs.- See Also:
FilterInputStream.in
-
decryptChunk
protected boolean decryptChunk() throws java.io.IOException
Call when inflater indicates that it needs more bytes.- Returns:
- - true if we decrypted more bytes to deflate, false if we encountered the end of stream
- Throws:
java.io.IOException
-
available
public int available()
This method returns 1 if we've not reached EOF, 0 if we have. Programs should not rely on this to determine the number of bytes that can be read without blocking.- Overrides:
available
in classjava.io.FilterInputStream
-
skip
public long skip(long n) throws java.io.IOException
Skips bytes by reading them into a cached buffer- Overrides:
skip
in classjava.io.FilterInputStream
- Throws:
java.io.IOException
-
-