Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 28

Streams :

What is a Stream

Types of Strams
Streams
InputStream OutputStream

Java Defines Two Types of Streams :

ByteStreams

Character Streams
ByteStreams :
Java’s Byte Stream classes are derived from two abstract
classes : 1) Input Stream and 2) OutputStream.
Each of these abstract classes has several sub classes.

Byte Streams provide an efficient way for handling input


and ouput of bytes. Byte Streams are used for reading
or writing binary data and For Binary Objects.
Character Strems :

Character streams provide a convenient means for handling input


and output of characters. They are unicode. Character streams
provide a convenient and efficient means for handling characters.

There are two kinds of character stream. 1) Reader.


2) Writer.
A Reader is an input character stream that reads a sequence of
Unicode characters. Character encoding are used by readers and
writers to convert between external encoding and internal unicode
characters.
Methods defined in InputStreams
int available()
void close()
int read()
int read(byte buffer[])
int read(byte buffer[],int start, int numbytes)
void reset()
int skip(long numbytes)
Methods defined in OutputStream class
void close()
void flush()
void write(int i)
void write(byte buffer[])
void write(byte buffer[], int index, int size)
Byte Stream Class Hierarchy
Object RandomAccessFile

File
OutputStream InputStream
DataOutputStream
FilterOutputStream
BufferedOutputStream

PrintStream
FileOutputStream

ObjectOutputStream

ByteArrayOutputStream

PipedOutputStream
Byte Stream Class Hierarchy
Object RandomAccessFile

File
OutputStream InputStream

DataInputStream FilterInputStream

BufferedInputStream FileInputStream

ByteArrayInputStream
LineNumberInputStream
ObjectInputStream
PushBackInputStream
PipedInputStream

SequenceInputStream

AudioInputStream
File Class
Constructors : File(String pathname)

Methods :- boolean canRead()


boolean canWrite()
int compareTo(File pathname)
boolean createNewFile()
boolean delete()
boolean exists()
String getName()
String getParent()
Sting getPath()
boolean isFile()
boolean isDirectory()
long length()
String[] list()
boolean mkdir()
boolean mkdirs()
boolean renameTo(File dest)
boolean setReadOnly()
Ex On FileInputStream & FileOutputStream

Ex On ByteArrayInputStream & ByteArrayOutputStream


Methods Supported by ByteArrayOutputStream

byte arr[] toByteArray()


void writeTo(OutputStream out)
Ex On DataInputStream & DataOutputStream
Methods Supported by DataInputStream

boolean readBoolean()
byte readByte()
char readChar()
double readDouble()
float readFloat()
int readInt()
short readShort()
long readLong()
String readUTF()
Methods Supported by DataOutputStream

void writeByte(int v)
void writeBoolean(boolean v)
void writeChar(int v)
void writeChars(String s)
void writeDouble(double v)
void writeFloat(float v)
void writeInt(int v)
void writeLong(long v)
void writeShort(int v)
void writeUTF(String s)
Ex On SequenceInputStream
Ex On RandomAccess File
boolean readBoolean()
byte readByte()
char readChar()
double readDouble()
float readFloat()
int readInt()
short readShort()
long readLong()
String readUTF()
int skipBytes(int n)
void skip(long pos)
long length()
void writeByte(int v)
void writeBoolean(boolean v)
void writeChar(int v)
void writeChars(String s)
void writeDouble(double v)
void writeFloat(float v)
void writeInt(int v)
void writeLong(long v)
void writeShort(int v)
void writeUTF(String s)
Character Stream Class Hierarchy:
Object

File
Writer Reader

OutputStreamWriter FileWriter

BufferedWriter

AudioFileWriter

FilterWriter

PipedWriter

PrintWriter

CharArrayWriter

StringWriter
Object

File
Writer Reader

PushBackReader FilterReader

LineNumberReader BufferedReader

CharArrayReader

PipedReader

StringReader

FileReader InputStreamReader
FileReader() & FileWriter()
CharArrayReader
Ex On CharArrayWriter

char arr[] toCharArray()


void writeTo(Writer out)
InputStreamReader()
Constructor :- InputStreamReader(InputStream is)
Ex On BufferedReader

String readLine()
Ex On BufferedWriter

void newLine() :- writes a line separator


Ex On PrinterWriter
PrintWriter append(Char c)
PrintWriter format(Stringt format,Object… args)
void print(char/double/int/boolean/float/long/Object/String)
PrintWriter printf(Stringt format,Object… args)
void println(char/double/int/booleanfloat/long/Object/String)
void write(String s)
void write(int c)
void write(char arr[])
Void write(char arr[],int start,int len)
Ex on ObjectOutputStream & ObjectInputStream
Methods in ObjectOutputStream
void writeByte(int v)
void writeBoolean(boolean v)
void writeChar(int v)
void writeChars(String s)
void writeDouble(double v)
void writeFloat(float v)
void writeInt(int v)
void writeLong(long v)
void writeShort(int v)
void writeUTF(String s)
void writeObject(Object o)
Methods in ObjectInputStream

boolean readBoolean()
byte readByte()
char readChar()
double readDouble()
float readFloat()
int readInt()
short readShort()
long readLong()
String readUTF()
int skipBytes(int n)
Object readObject()
Use of transient modifier in Seriablization
GZipInputStream & GZipOutputStream
Defined in java.util.zip package

Constructors :

GZipInputStream(InputStream in)
GZipOutputStream(OutputStream out)

You might also like