Java.io - SPLessons

Java.io StringBufferInputStream

Home > Lesson > Chapter 49
SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

Java.io StringBufferInputStream

Java.io StringBufferInputStream

shape Introduction

Generally for to read bytes of data byte array input stream or buffered input stream class are used. The Java.io StringBufferInputStream is similar to the buffered input stream but the thing is here the bytes reads are supplied in the form of contents of string. The oracle put down this class, so not used any more.

Class Declaration

shape Declaration

Java.io StringBufferInputStream class is declared below: Public class StringBufferInputStream extends InputStream

shape Fields

Java.io StringBufferInputStream class fields are:
  • Protected int Count : The field represents to the index to count input stream bytes which are valid.
  • Protected int pos : The field represents to the position of push back input stream buffer to read that coming byte.
  • Protected Sting Buffer : The field represents to string from the content of bytes reads.

Class Constructors

shape Table

Constructor Description
StringBufferInputStream(String s) The function of this constructor is to create the StringBufferInputStream instance and reads from the represented string.

Class Methods

shape Table

Method Description
void reset () The function of this method is to reset the current stream to read data from starting.
Long skip (long m) The function of this method is to skip the text or characters in this stream of ' m ' bytes.
int read() The function of this method is to read one byte of data from this stream.
int read(byte[] b, int off, int n) By using this method it reads the data up to 'n' bytes from the input stream into an array of bytes.

Inherited Methods

shape Description

From the following classes, methods are inherited the Java.io StringBufferInputStream class.
  • Java.io.Object
  • Java.io.InputStream

shape Example

The following is an example. SBIDemo.java [java]package java2; import java.io.*; public class SBIDemo { public static void main(String args[]) throws IOException { String comments = "Improve\nthe\ncontent\nwith\nyour\nvalueble\ncomments"; StringBufferInputStream sbis = new StringBufferInputStream(comments); DataInputStream dis = new DataInputStream(sbis); String str; while( ( str = dis.readLine() ) != null ) { System.out.println(str); } dis.close(); sbis.close(); } }[/java] The string comments is passed as parameter to StringBufferInputStream constructor. StringBufferInputStream is chained to DataInputStream. The readLine() method of DataInputStream reads each word delimited by \n in the string comments. Output The result will be as follows. [java] Improve the content with your valueble comments [/java]

Summary

shape Key Points

  • The string buffer input stream is similar to the buffered input stream but the thing is here the bytes reads are supplied in the form of contents of string.
  • The oracle put down this class, so not used any more.