All About Class ByteArrayInputStream in Java

0
19
Spread the love
  • 1
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
    1
    Share

ByteArrayInputStream in Java
ByteArrayInputStream in Java

ByteArrayInputStream in Java:

ByteArrayInputStream allows an application to create an input stream where the bytes read are supplied by the contents of a byte Array.ByteArrayInputStream is a subclass of InputStream where the data comes from a specified array of bytes values.The data may come from a file,a pipe or a socket. In other words this class allows a buffer in the memory to be used as an InputStream. The constructor takes the buffer as an argument from which it extracts the bytes Application can also read bytes from a String by using a StringBufferInputStream.We need to connect ByteArrayInputStream to a FilterInputStream object to provide a useful interface.

The structure of the class ByteArrayInputStream is given as:


public class java.io.ByteArrayInputStream extends java.io.InputStream{
//member elements:
protected byte buff[];
//the buffer consists of array of bytes containing the data.
protect int count;
//The index is greater than the last valid character in the input stream buffer.
protected int pos;
//the index of the next character to read from the input stream buffer.
protected int mark;
//Constructor
public ByteArrayInputStream(byte buf[]);
//creates a new byte array input stream which reads data from the specified byte array.
//The byte array is not copied
public ByteArrayInputStream(byte buf[],int offSet,int length);
//creates a new byte array input stream which reads data from the specified byte array upto
//length characters are to be read from the byte array starting at the indicated offSet.
//Methods:
public synchronized int available();
public synchronized int read();
public synchronized int read(byte b[],int offSet,int length);
public synchronized void reset();
public synchronized long skip(long l);
public void mark(int markpos); 
public boolean markSupported();
} 
Don't miss out!
Subscribe To Newsletter

Receive top technical news, lesson ideas, travel tips and more!

Invalid email address
Give it a try. You can unsubscribe at any time.

Spread the love
  • 1
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
    1
    Share

LEAVE A REPLY

Please enter your comment!
Please enter your name here