Java Doc for LineNumberInputStream.java in  » 6.0-JDK-Core » io-nio » java » io » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Home
Java Source Code / Java Documentation
1.6.0 JDK Core
2.6.0 JDK Modules
3.6.0 JDK Modules com.sun
4.6.0 JDK Modules com.sun.java
5.6.0 JDK Modules sun
6.6.0 JDK Platform
7.Ajax
8.Apache Harmony Java SE
9.Aspect oriented
10.Authentication Authorization
11.Blogger System
12.Build
13.Byte Code
14.Cache
15.Chart
16.Chat
17.Code Analyzer
18.Collaboration
19.Content Management System
20.Database Client
21.Database DBMS
22.Database JDBC Connection Pool
23.Database ORM
24.Development
25.EJB Server
26.ERP CRM Financial
27.ESB
28.Forum
29.Game
30.GIS
31.Graphic 3D
32.Graphic Library
33.Groupware
34.HTML Parser
35.IDE
36.IDE Eclipse
37.IDE Netbeans
38.Installer
39.Internationalization Localization
40.Inversion of Control
41.Issue Tracking
42.J2EE
43.J2ME
44.JBoss
45.JMS
46.JMX
47.Library
48.Mail Clients
49.Music
50.Net
51.Parser
52.PDF
53.Portal
54.Profiler
55.Project Management
56.Report
57.RSS RDF
58.Rule Engine
59.Science
60.Scripting
61.Search Engine
62.Security
63.Sevlet Container
64.Source Control
65.Swing Library
66.Template Engine
67.Test Coverage
68.Testing
69.UML
70.Web Crawler
71.Web Framework
72.Web Mail
73.Web Server
74.Web Services
75.Web Services apache cxf 2.2.6
76.Web Services AXIS2
77.Wiki Engine
78.Workflow Engines
79.XML
80.XML UI
Java Source Code / Java Documentation » 6.0 JDK Core » io nio » java.io 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   java.io.InputStream
      java.io.FilterInputStream
         java.io.LineNumberInputStream

LineNumberInputStream
public class LineNumberInputStream extends FilterInputStream (Code)
This class is an input stream filter that provides the added functionality of keeping track of the current line number.

A line is a sequence of bytes ending with a carriage return character ('\r'), a newline character ('\n'), or a carriage return character followed immediately by a linefeed character. In all three cases, the line terminating character(s) are returned as a single newline character.

The line number begins at 0, and is incremented by 1 when a read returns a newline character.
author:
   Arthur van Hoff
version:
   1.34, 05/05/07
See Also:   java.io.LineNumberReader
since:
   JDK1.0



Field Summary
 intlineNumber
    
 intmarkLineNumber
    
 intmarkPushBack
    
 intpushBack
    

Constructor Summary
public  LineNumberInputStream(InputStream in)
     Constructs a newline number input stream that reads its input from the specified input stream.

Method Summary
public  intavailable()
     Returns the number of bytes that can be read from this input stream without blocking.
public  intgetLineNumber()
     Returns the current line number.
public  voidmark(int readlimit)
     Marks the current position in this input stream.
public  intread()
     Reads the next byte of data from this input stream.
public  intread(byte b, int off, int len)
     Reads up to len bytes of data from this input stream into an array of bytes.
public  voidreset()
     Repositions this stream to the position at the time the mark method was last called on this input stream.
public  voidsetLineNumber(int lineNumber)
     Sets the line number to the specified argument.
public  longskip(long n)
     Skips over and discards n bytes of data from this input stream.

Field Detail
lineNumber
int lineNumber(Code)



markLineNumber
int markLineNumber(Code)



markPushBack
int markPushBack(Code)



pushBack
int pushBack(Code)




Constructor Detail
LineNumberInputStream
public LineNumberInputStream(InputStream in)(Code)
Constructs a newline number input stream that reads its input from the specified input stream.
Parameters:
  in - the underlying input stream.




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

Note that if the underlying input stream is able to supply k input characters without blocking, the LineNumberInputStream can guarantee only to provide k/2 characters without blocking, because the k characters from the underlying input stream might consist of k/2 pairs of '\r' and '\n', which are converted to just k/2 '\n' characters. the number of bytes that can be read from this input streamwithout blocking.
exception:
  IOException - if an I/O error occurs.
See Also:   java.io.FilterInputStream.in




getLineNumber
public int getLineNumber()(Code)
Returns the current line number. the current line number.
See Also:   LineNumberInputStream.setLineNumber



mark
public void mark(int readlimit)(Code)
Marks the current position in this input stream. A subsequent call to the reset method repositions this stream at the last marked position so that subsequent reads re-read the same bytes.

The mark method of LineNumberInputStream remembers the current line number in a private variable, and then calls the mark method of the underlying input stream.
Parameters:
  readlimit - the maximum limit of bytes that can be read beforethe mark position becomes invalid.
See Also:   java.io.FilterInputStream.in
See Also:   java.io.LineNumberInputStream.reset




read
public int read() throws IOException(Code)
Reads the next byte of data from this input stream. The value byte is returned as an int in the range 0 to 255. 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.

The read method of LineNumberInputStream calls the read method of the underlying input stream. It checks for carriage returns and newline characters in the input, and modifies the current line number as appropriate. A carriage-return character or a carriage return followed by a newline character are both converted into a single newline character. the next byte of data, or -1 if the end of thisstream is reached.
exception:
  IOException - if an I/O error occurs.
See Also:   java.io.FilterInputStream.in
See Also:   java.io.LineNumberInputStream.getLineNumber




read
public int read(byte b, int off, int len) throws IOException(Code)
Reads up to len bytes of data from this input stream into an array of bytes. This method blocks until some input is available.

The read method of LineNumberInputStream repeatedly calls the read method of zero arguments to fill in the byte array.
Parameters:
  b - the buffer into which the data is read.
Parameters:
  off - the start offset of the data.
Parameters:
  len - the maximum number of bytes read. the total number of bytes read into the buffer, or-1 if there is no more data because the end ofthis stream has been reached.
exception:
  IOException - if an I/O error occurs.
See Also:   java.io.LineNumberInputStream.read




reset
public void reset() throws IOException(Code)
Repositions this stream to the position at the time the mark method was last called on this input stream.

The reset method of LineNumberInputStream resets the line number to be the line number at the time the mark method was called, and then calls the reset method of the underlying input stream.

Stream marks are intended to be used in situations where you need to read ahead a little to see what's in the stream. Often this is most easily done by invoking some general parser. If the stream is of the type handled by the parser, it just chugs along happily. If the stream is not of that type, the parser should toss an exception when it fails, which, if it happens within readlimit bytes, allows the outer code to reset the stream and try another parser.
exception:
  IOException - if an I/O error occurs.
See Also:   java.io.FilterInputStream.in
See Also:   java.io.LineNumberInputStream.mark(int)




setLineNumber
public void setLineNumber(int lineNumber)(Code)
Sets the line number to the specified argument.
Parameters:
  lineNumber - the new line number.
See Also:   LineNumberInputStream.getLineNumber



skip
public long skip(long n) throws IOException(Code)
Skips over and discards n bytes of data from this input stream. The skip method may, for a variety of reasons, end up skipping over some smaller number of bytes, possibly 0. The actual number of bytes skipped is returned. If n is negative, no bytes are skipped.

The skip method of LineNumberInputStream creates a byte array and then repeatedly reads into it until n bytes have been read or the end of the stream has been reached.
Parameters:
  n - the number of bytes to be skipped. the actual number of bytes skipped.
exception:
  IOException - if an I/O error occurs.
See Also:   java.io.FilterInputStream.in




Fields inherited from java.io.FilterInputStream
protected volatile InputStream in(Code)(Java Doc)

Methods inherited from java.io.FilterInputStream
public int available() throws IOException(Code)(Java Doc)
public void close() throws IOException(Code)(Java Doc)
public synchronized void mark(int readlimit)(Code)(Java Doc)
public boolean markSupported()(Code)(Java Doc)
public int read() throws IOException(Code)(Java Doc)
public int read(byte b) throws IOException(Code)(Java Doc)
public int read(byte b, int off, int len) throws IOException(Code)(Java Doc)
public synchronized void reset() throws IOException(Code)(Java Doc)
public long skip(long n) throws IOException(Code)(Java Doc)

Methods inherited from java.io.InputStream
public int available() throws IOException(Code)(Java Doc)
public void close() throws IOException(Code)(Java Doc)
public synchronized void mark(int readlimit)(Code)(Java Doc)
public boolean markSupported()(Code)(Java Doc)
abstract public int read() throws IOException(Code)(Java Doc)
public int read(byte b) throws IOException(Code)(Java Doc)
public int read(byte b, int off, int len) throws IOException(Code)(Java Doc)
public synchronized void reset() throws IOException(Code)(Java Doc)
public long skip(long n) throws IOException(Code)(Java Doc)

Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.