Package chemaxon.marvin.io
Class PositionedInputStream
java.lang.Object
java.io.InputStream
java.io.FilterInputStream
java.io.BufferedInputStream
chemaxon.marvin.io.PositionedInputStream
- All Implemented Interfaces:
Closeable
,AutoCloseable
- Direct Known Subclasses:
MolInputStream
Positioned input stream that has the ability to set / get the
stream position as well as put back some parts already read.
- Since:
- Marvin 4.0, 02/25/2005
-
Field Summary
Modifier and TypeFieldDescriptionprotected Encoding
The encoding.protected boolean
protected ByteBuffer
Lines are read into this buffer.protected int
Column position of the next character to read.Fields inherited from class java.io.FilterInputStream
in
-
Constructor Summary
ModifierConstructorDescriptionConstructor.PositionedInputStream
(InputStream is, int size) Constructor.PositionedInputStream
(InputStream is, int size, String enc) Constructor.protected
PositionedInputStream
(InputStream is, int size, String enc, int initialChunkSize) Constructor.PositionedInputStream
(InputStream is, String enc) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionprotected final int
Reads a character and writes into the buffer.void
Disables the mark (if any) on this stream.final String
Deprecated, for removal: This API element is subject to removal in a future version.final Encoding
Gets the encoding.final long
Get the file pointer.final String
Deprecated, for removal: This API element is subject to removal in a future version.final int
Gets the current line number.protected int
getWord
(ByteBuffer bb, int i) boolean
Tests whether the stream is seekable.long
length()
Gets the file length.final void
Puts back the last line into the stream.final void
putBackLine
(int col) Puts back the last line into the stream.int
read()
Reads a character.int
read
(byte[] b, int off, int len) Reads a byte array.readLine()
Reads a line.void
reset()
Repositions this stream to the position at the time themark
method was last called on this input stream.protected final void
Resets file pointer to zero.void
seek
(long p, int lcount) Sets the file-pointer offset, measured from the beginning of this file, at which the next read or write occurs.protected void
void
setDesiredBufferSize
(int size) Sets desired buffer size.final void
setEncoding
(Encoding enc) Sets the encoding.final void
setEncoding
(String enc) Sets the encoding.protected void
setWord
(ByteBuffer bb, int i, int c) long
skip
(long n) Skips over and discards n bytes of data.boolean
skipLine()
Skips the next line.final void
Deprecated, for removal: This API element is subject to removal in a future version.Methods inherited from class java.io.BufferedInputStream
available, close, mark, markSupported
Methods inherited from class java.io.FilterInputStream
read
Methods inherited from class java.io.InputStream
nullInputStream, readAllBytes, readNBytes, readNBytes, skipNBytes, transferTo
-
Field Details
-
lineByteBuffer
Lines are read into this buffer.- See Also:
-
lineCurrentColumn
protected int lineCurrentColumnColumn position of the next character to read. -
keeporiginalLineEnding
protected boolean keeporiginalLineEnding -
encoding
The encoding.- Since:
- Marvin 5.0, 11/10/2007
-
-
Constructor Details
-
PositionedInputStream
Constructor. It tries to read 1024 bytes into the buffer and to recognize the character encoding.- Parameters:
is
- the original input stream- Throws:
IOException
-
PositionedInputStream
Constructor. It tries to read 1024 bytes into the buffer and to recognize the character encoding.- Parameters:
is
- the original input streamsize
- the buffer size- Throws:
IOException
-
PositionedInputStream
Constructor. It tries to read 1024 bytes into the buffer and to recognize the character encoding if it is not specified (null
).- Parameters:
is
- the original input streamenc
- the character encoding ornull
- Throws:
IOException
- Since:
- Marvin 3.5.5
-
PositionedInputStream
Constructor. It tries to read 1024 bytes into the buffer and to recognize the character encoding if it is not specified (null
).- Parameters:
is
- the original input streamsize
- the buffer sizeenc
- the character encoding ornull
- Throws:
IOException
- Since:
- Marvin 3.5.5
-
PositionedInputStream
protected PositionedInputStream(InputStream is, int size, String enc, int initialChunkSize) throws IOException Constructor.- Parameters:
is
- the original input streamsize
- the buffer sizeenc
- the character encoding or nullinitialChunkSize
- number of bytes to read in advance for encoding recognition- Throws:
IOException
- Since:
- Marvin 5.0, 11/10/2007
-
-
Method Details
-
setDesiredBufferSize
public void setDesiredBufferSize(int size) Sets desired buffer size.- Parameters:
size
- the desired buffer size
-
read
Reads a character. Warning! This method does not update the line number.- Overrides:
read
in classBufferedInputStream
- Returns:
- the character
- Throws:
IOException
- read error occurred
-
bufincRead
Reads a character and writes into the buffer. Increases the buffer size if it becomes full.- Returns:
- the character
- Throws:
IOException
- in case of read error
-
read
Reads a byte array. Warning! This method does not update the line number.- Overrides:
read
in classBufferedInputStream
- Parameters:
b
- the buffer into which the data is read.off
- the start offset of the datalen
- maximum number of bytes to 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
- read error occurred
-
skip
Skips over and discards n bytes of data. Warning! This method does not update the line number.- Overrides:
skip
in classBufferedInputStream
- Parameters:
n
- the number of bytes- Returns:
- the number of skipped bytes
- Throws:
IOException
- read error occurred
-
reset
Repositions this stream to the position at the time themark
method was last called on this input stream.- Overrides:
reset
in classBufferedInputStream
- Throws:
IOException
- if this stream has not been marked or if the mark has been invalidated.
-
clearMark
public void clearMark()Disables the mark (if any) on this stream. After calling this method,reset()
will fail, unlessBufferedInputStream.mark(int)
is called before that. -
startGrabLines
Deprecated, for removal: This API element is subject to removal in a future version.Starts grabbing lines. Lines will be grabbed while reading them at each readLine call. The resulting text will be separated by \n characters (UNIX line separator).- Since:
- Marvin 4.0, 01/05/2005
- See Also:
-
endGrabLines
Deprecated, for removal: This API element is subject to removal in a future version.Ends grabbing lines.- Returns:
- the grabbed lines
- Since:
- Marvin 4.0, 01/05/2005
-
getGrabbedLines
@Deprecated(forRemoval=true) @SubjectToRemoval(date=JUL_01_2026) public final String getGrabbedLines()Deprecated, for removal: This API element is subject to removal in a future version.Gets the grabbed lines.- Returns:
- the grabbed lines
- Since:
- Marvin 4.0, 01/05/2005
-
readLine
Reads a line.- Returns:
- the line without the line separator character(s)
- Throws:
IOException
- If an I/O error has occurred.
-
skipLine
Skips the next line. The skipped line is not stored and cannot be put back into the stream. Moreover, line grabbing is disabled.- Returns:
true
if a line was skipped successfully,false
at end of file- Throws:
IOException
- If an I/O error has occurred.- Since:
- Marvin 5.1.3, 10/18/2008
-
getWord
-
setWord
-
getLineCount
public final int getLineCount()Gets the current line number. Only lines read with readLine() are counted.- Returns:
- the line number
-
putBackLine
Puts back the last line into the stream. Also repositions the file pointer.- Throws:
IOException
- If an I/O error has occurred.- See Also:
-
putBackLine
Puts back the last line into the stream. Also repositions the file pointer.- Parameters:
col
- put back the substring starting at this column- Throws:
IOException
- If an I/O error has occurred.- Since:
- Marvin 5.0.1, 01/12/2008
- See Also:
-
resetFilePointer
protected final void resetFilePointer()Resets file pointer to zero. -
getFilePointer
public final long getFilePointer()Get the file pointer.- Returns:
- the file pointer
-
isSeekable
public boolean isSeekable()Tests whether the stream is seekable.- Returns:
- true if the stream is seekable, false otherwise
- Since:
- Marvin 4.1, 04/13/2006
-
seek
Sets the file-pointer offset, measured from the beginning of this file, at which the next read or write occurs.Seeking forward is always supported. If the stream is marked, then seeking backward until the marked position is also supported. Seeking further backward is only supported if
isSeekable()
returns true.- Parameters:
p
- the offset positionlcount
- the line count at the specified position- Throws:
IOException
- ifpos
is less than0
or if an I/O error occurs.- Since:
- Marvin 4.1, 04/13/2006
-
length
Gets the file length.- Returns:
- the file length
- Throws:
IOException
- if the file length cannot be determined- Since:
- Marvin 4.1, 04/18/2006
-
getEncoding
Gets the encoding.- Returns:
- the encoding or null
- Since:
- Marvin 5.0, 11/20/2007
-
setEncoding
Sets the encoding.- Parameters:
enc
- the encoding- Since:
- Marvin 5.0, 11/20/2007
-
setEncoding
Sets the encoding.- Parameters:
enc
- the encoding- Throws:
IllegalCharsetNameException
- if the encoding is illegalUnsupportedCharsetException
- if the encoding is unsupported
-
setByteOrder
-
getLastEOL
-