Class CompressInputStream
- java.lang.Object
-
- java.io.InputStream
-
- org.mariadb.jdbc.client.socket.CompressInputStream
-
- All Implemented Interfaces:
Closeable,AutoCloseable
public class CompressInputStream extends InputStream
-
-
Constructor Summary
Constructors Constructor Description CompressInputStream(InputStream in, org.mariadb.jdbc.util.MutableInt compressionSequence)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intavailable()Returns an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking by the next invocation of a method for this input stream.voidclose()Closes this input stream and releases any system resources associated with the stream.voidmark(int readlimit)Marks the current position in this input stream.booleanmarkSupported()Tests if this input stream supports themarkandresetmethods.intread()Reads the next byte of data from the input stream.intread(byte[] b, int off, int len)Reads up tolenbytes of data from the input stream into an array of bytes.voidreset()Repositions this stream to the position at the time themarkmethod was last called on this input stream.longskip(long n)Skips over and discardsnbytes of data from this input stream.-
Methods inherited from class java.io.InputStream
nullInputStream, read, readAllBytes, readNBytes, readNBytes, transferTo
-
-
-
-
Constructor Detail
-
CompressInputStream
public CompressInputStream(InputStream in, org.mariadb.jdbc.util.MutableInt compressionSequence)
-
-
Method Detail
-
read
public int read(byte[] b, int off, int len) throws IOExceptionReads up tolenbytes of data from the input stream into an array of bytes. An attempt is made to read as many aslenbytes, but a smaller number may be read. The number of bytes actually read is returned as an integer.This method blocks until input data is available, end of file is detected, or an exception is thrown.
If
lenis zero, then no bytes are read and0is returned; otherwise, there is an attempt to read at least one byte. If no byte is available because the stream is at end of file, the value-1is returned; otherwise, at least one byte is read and stored intob.The first byte read is stored into element
b[off], the next one intob[off+1], and so on. The number of bytes read is, at most, equal tolen. Let k be the number of bytes actually read; these bytes will be stored in elementsb[off]throughb[off+k-1], leaving elementsb[off+k]throughb[off+len-1]unaffected.In every case, elements
b[0]throughb[off]and elementsb[off+len]throughb[b.length-1]are unaffected.The
read(b,off,len)method for classInputStreamsimply calls the methodread()repeatedly. If the first such call results in anIOException, that exception is returned from the call to theread(b,off,len)method. If any subsequent call toread()results in aIOException, the exception is caught and treated as if it were end of file; the bytes read up to that point are stored intoband the number of bytes read before the exception occurred is returned. The default implementation of this method blocks until the requested amount of input datalenhas been read, end of file is detected, or an exception is thrown. Subclasses are encouraged to provide a more efficient implementation of this method.- Overrides:
readin classInputStream- Parameters:
b- the buffer into which the data is read.off- the start offset in arraybat which the data is written.len- the maximum number of bytes to read.- Returns:
- the total number of bytes read into the buffer, or
-1if there is no more data because the end of the stream has been reached. - Throws:
IOException- If the first byte cannot be read for any reason other than end of file, or if the input stream has been closed, or if some other I/O error occurs.NullPointerException- Ifbisnull.IndexOutOfBoundsException- Ifoffis negative,lenis negative, orlenis greater thanb.length - off- See Also:
InputStream.read()
-
skip
public long skip(long n) throws IOExceptionSkips over and discardsnbytes of data from this input stream. Theskipmethod may, for a variety of reasons, end up skipping over some smaller number of bytes, possibly0. This may result from any of a number of conditions; reaching end of file beforenbytes have been skipped is only one possibility. The actual number of bytes skipped is returned. Ifnis negative, theskipmethod for classInputStreamalways returns 0, and no bytes are skipped. Subclasses may handle the negative value differently.The
skipmethod of this class creates a byte array and then repeatedly reads into it untilnbytes have been read or the end of the stream has been reached. Subclasses are encouraged to provide a more efficient implementation of this method. For instance, the implementation may depend on the ability to seek.- Overrides:
skipin classInputStream- Parameters:
n- the number of bytes to be skipped.- Returns:
- the actual number of bytes skipped.
- Throws:
IOException- if the stream does not support seek, or if some other I/O error occurs.
-
available
public int available() throws IOExceptionReturns an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking by the next invocation of a method for this input stream. The next invocation might be the same thread or another thread. A single read or skip of this many bytes will not block, but may read or skip fewer bytes.Note that while some implementations of
InputStreamwill return the total number of bytes in the stream, many will not. It is never correct to use the return value of this method to allocate a buffer intended to hold all data in this stream.A subclass' implementation of this method may choose to throw an
IOExceptionif this input stream has been closed by invoking theclose()method.The
availablemethod for classInputStreamalways returns0.This method should be overridden by subclasses.
- Overrides:
availablein classInputStream- Returns:
- an estimate of the number of bytes that can be read (or skipped over) from this input
stream without blocking or
0when it reaches the end of the input stream. - Throws:
IOException- if an I/O error occurs.
-
close
public void close() throws IOExceptionCloses this input stream and releases any system resources associated with the stream.The
closemethod ofInputStreamdoes nothing.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classInputStream- Throws:
IOException- if an I/O error occurs.
-
mark
public void mark(int readlimit)
Marks the current position in this input stream. A subsequent call to theresetmethod repositions this stream at the last marked position so that subsequent reads re-read the same bytes.The
readlimitarguments tells this input stream to allow that many bytes to be read before the mark position gets invalidated.The general contract of
markis that, if the methodmarkSupportedreturnstrue, the stream somehow remembers all the bytes read after the call tomarkand stands ready to supply those same bytes again if and whenever the methodresetis called. However, the stream is not required to remember any data at all if more thanreadlimitbytes are read from the stream beforeresetis called.Marking a closed stream should not have any effect on the stream.
The
markmethod ofInputStreamdoes nothing.- Overrides:
markin classInputStream- Parameters:
readlimit- the maximum limit of bytes that can be read before the mark position becomes invalid.- See Also:
InputStream.reset()
-
reset
public void reset() throws IOExceptionRepositions this stream to the position at the time themarkmethod was last called on this input stream.The general contract of
resetis:- If the method
markSupportedreturnstrue, then:- If the method
markhas not been called since the stream was created, or the number of bytes read from the stream sincemarkwas last called is larger than the argument tomarkat that last call, then anIOExceptionmight be thrown. - If such an
IOExceptionis not thrown, then the stream is reset to a state such that all the bytes read since the most recent call tomark(or since the start of the file, ifmarkhas not been called) will be resupplied to subsequent callers of thereadmethod, followed by any bytes that otherwise would have been the next input data as of the time of the call toreset.
- If the method
- If the method
markSupportedreturnsfalse, then:- The call to
resetmay throw anIOException. - If an
IOExceptionis not thrown, then the stream is reset to a fixed state that depends on the particular type of the input stream and how it was created. The bytes that will be supplied to subsequent callers of thereadmethod depend on the particular type of the input stream.
- The call to
The method
resetfor classInputStreamdoes nothing except throw anIOException.- Overrides:
resetin classInputStream- Throws:
IOException- if this stream has not been marked or if the mark has been invalidated.- See Also:
InputStream.mark(int),IOException
- If the method
-
markSupported
public boolean markSupported()
Tests if this input stream supports themarkandresetmethods. Whethermarkandresetare supported is an invariant property of a particular input stream instance. ThemarkSupportedmethod ofInputStreamreturnsfalse.- Overrides:
markSupportedin classInputStream- Returns:
trueif this stream instance supports the mark and reset methods;falseotherwise.- See Also:
InputStream.mark(int),InputStream.reset()
-
read
public int read() throws IOExceptionReads the next byte of data from the input stream. The value byte is returned as anintin the range0to255. If no byte is available because the end of the stream has been reached, the value-1is returned. This method blocks until input data is available, the end of the stream is detected, or an exception is thrown.A subclass must provide an implementation of this method.
- Specified by:
readin classInputStream- Returns:
- the next byte of data, or
-1if the end of the stream is reached. - Throws:
IOException- if an I/O error occurs.
-
-