Series: IO other streams

Java IO special streams usage

SequenceInputStream Java

SequenceInputStream Java is used to copy a number of source files to one destination file. Many input streams are concatenated and converted into a single stream and copied at a stretch to the destination file. Merging of multiple files can be done easily in Java using SequenceInputStream. SequenceInputStream is a good example to show that …

SequenceInputStream Java Read More »

ByteArrayOutputStream

The class ByteArrayOutputStream does just the opposite functionality of ByteArrayInputStream. The ByteArrayInputStream reads data from the array and now the ByteArrayOutputStream writes the data to the byte array. All the characters of the array can be written or a few also. In the following program, both functionalities are illustrated. import java.io.*; public class BAODemo { …

ByteArrayOutputStream Read More »

markSupported() mark() reset() Java

Rereading from the Same Position The same contents of a file can be again and again read by marking the position with the methods of StringBufferInputStream, inherited from its super class InputStream. A file can be reread (reading again) from a particular location. Here, the file position is marked; execution control is taken back to …

markSupported() mark() reset() Java Read More »

StringBufferInputStream Example

StringBufferInputStream Example: As in the earlier program, where the source of reading is a byte array in case of ByteArrayInputStream, now the source is a string buffer in case of StringBufferInputStream. That is, StringBufferInputStream reads from a string buffer (or the other way, string). StringBufferInputStream class methods and constructors are deprecated (observe the compiler message …

StringBufferInputStream Example Read More »

Give Line Numbers LineNumberInputStream

Give Line Numbers LineNumberInputStream Summary: By the end of this tutorial "Give Line Numbers LineNumberInputStream", you will come to know how to give line numbers using Java I/O streams. LineNumberInputStream is a subclass of FilterInputStream stream. We know each filter stream adds some extra functionality. The LineNumberInputStream does the extra work of adding line numbers …

Give Line Numbers LineNumberInputStream Read More »

PipedInputStream PipedOutputStream

PipedInputStream PipedOutputStream – Transferring Data between Processes What is pipe? A pipe is a transferring channel though which data flows. Pipe is a conduit to send data of an output stream to an input stream. Generally, a thread connected to PipedOutputStream sends data to another thread connected to PipedInputStream. To transfer data between two running …

PipedInputStream PipedOutputStream Read More »

StringReader Java

StringReader of character streams is equivalent to StringBufferInputStream of byte streams. We know earlier, the StringBufferInputStream methods are deprecated in favor of StringReader. Like StringBufferInputStream, the source of data for StringReader is a string. StringReader supports mark() and reset() methods, but StringBufferInputStream does not support. Being character stream, the StringReader operates on Unicode data. Following …

StringReader Java Read More »

LineNumberReader Java

The character stream LineNumberReader is equivalent to LineNumberInputStream on byte streams side. Being a subclass of BufferedReader, it can make use of all the methods of BufferedReader like readLine() to read a line. getLineNumber() method of this class can be used to give line numbers. Following is the class signature of LineNumberReader Java: public class …

LineNumberReader Java Read More »

CharArrayReader Read Character Array Java

The CharArrayReader is equivalent to ByteArrayInputStream. For ByteArrayInputStream, the source is a byte array and for CharArrayReader the source is a character array. The CharArrayReader reads characters from a character array either completely or partially starting from a offset. This classes supports mark() and reset() methods. Following is the class signature public class CharArrayReader extends …

CharArrayReader Read Character Array Java Read More »

PipedReader PipedWriter Example

Piping Data PipedReader PipedWriter Summary: By the end you read this tutorial "Piping Data PipedReader PipedWriter", you will understand passing data between two running processes or threads. The PipedReader and PipedWriter are character streams. Similar in byte streams are PipedInputStream and PipedOutputStream. These streams use a concept called pipe. Pipe is used to pass data …

PipedReader PipedWriter Example Read More »