SlideShare a Scribd company logo
ByteArrayInputStream class




      http://improvejava.blogspot.in/   1
Objectives

On completion of this period, you would be able to
 learn
   •   Other I/O stream classes
   •   ByteArrayInputStream
   •   ByteArrayOutputStream
   •   BufferedInputStream
   •   BufferedOutputStream




                       http://improvejava.blogspot.in/   2
Recap

In the last class, you have studied about the types
   Stream Class
• Byte Streams are two types
   1. InputStream class
   2. OutputStream class
• FileInputStream and FileOutputStream are the
  subclasses of byte stream
• Let us explore some more stream classes


                     http://improvejava.blogspot.in/   3
ByteArrayInputStream class

• Data stored in memory is handled by
  ByteArrayInputStream
• This class is used to read bytes from a memory
• Objects of this class are used to create input stream
  with memory buffers as data source
• Constructors
   • ByteArrayInputStream(byte array[ ])
   • ByteArrayInputStream(byte array[ ], int start, int
     numBytes)

                      http://improvejava.blogspot.in/     4
ByteArrayOutputStream class

• Data stored in memory is handled by
  ByteArrayOutputStream
• This class is used to write bytes into memory
• Objects of this class are used to create output stream
  with memory buffers as data sink
• Constructors
   •   ByteArrayOutputStream( )
   •   ByteArrayOutputStream(int numBytes)
   •   In the first form, a buffer of 32 bytes is created.
   •    In the second, a buffer is created with a size equal to that
       specified by numBytes

                         http://improvejava.blogspot.in/               5
Filtered Byte Stream class
• Byte streams access the data in byte form
• Raw bytes can not be used for any useful purpose
• For converting bytes to useful forms such as char,
  string, int, etc filtered streams are used
• Streams that can take other stream as arguments are
  called filtered streams
• FilterInputStream
   • BufferedInputStream is a subclass of it
• FilterOutputStream
   • BufferedOutputStream is a subclass of it
 In many practical situations only filtered streams are
  useful
                      http://improvejava.blogspot.in/   6
BufferedInputStream class

• This is a subclass of FilterInpuStream
• This class is used to increase the efficiency of reading
  bytes from an input stream
• Fetching a byte and sending it to the destination one
  after the another is a time consuming process
• Instead, bytes can be read and stored in buffer
  memory before sending it to the destination
• Once the buffer is full, the bytes can be sent to the
  destination
                    http://improvejava.blogspot.in/      7
BufferedOutputStream class

• This class is a subclass of FilterOutputStream
• This class is used to send buffered bytes to an
  underlying output stream in an efficient way
Constructors
   • BufferedOutputStream(OutputStream outputStream)
   • BufferedOutputStream(OutputStream outputStream, int bufSize)
• The first form creates a buffered stream using a buffer
  of 512 bytes. In the second form,
• the size of the buffer is passed in bufSize.

                        http://improvejava.blogspot.in/             8
Summary

• Data stored in memory is handled by
  ByteArrayInputStream and is used to read bytes
  from a memory
• ByteArrayOutputStream is used to write bytes into
  memory
• FilteredStreams are used for converting bytes to
  useful forms such as char, string, int, etc



                  http://improvejava.blogspot.in/     9
Quiz

1. ---- is used to read bytes from a memory

   A.   ByteArrayOutputStream
   B.   ByteArrayInputStream
   C.   Reader
   D.   None




                     http://improvejava.blogspot.in/   10
Quiz

2. --- is used to write bytes into memory

   A.   ByteArrayInputStream
   B.   ByteArrayOutputStream
   C.   Writer
   D.   None




                     http://improvejava.blogspot.in/   11
Frequently Asked Questions

1. Write about ByteArrayInput and ByteArrayOutput
   streams
2. Write about FilteredByte Streams




                  http://improvejava.blogspot.in/   12

More Related Content

Similar to Byte arrayinputstream.50 (20)

PPT
Various io stream classes .47
myrajendra
 
PPT
Various io stream classes .47
myrajendra
 
PPT
Character stream classes introd .51
myrajendra
 
TXT
Inputstream
Rajasekhar Reddy
 
TXT
Inputstream
Rajasekhar Reddy
 
PPTX
Java Input Output (java.io.*)
Om Ganesh
 
PPT
Character stream classes .52
myrajendra
 
PPT
Itp 120 Chapt 19 2009 Binary Input & Output
phanleson
 
DOC
Web Technology Web Technology Notes Streams Network Principles and SocketsUni...
uthayashangar1
 
PPTX
Input & output
SAIFUR RAHMAN
 
PDF
Programming language JAVA Input output opearations
2025183005
 
PPTX
Stream In Java.pptx
ssuser9d7049
 
PPS
Java session14
Niit Care
 
PDF
Monhocvecaujahetvagiuplaptunhhayhonha.pdf
cuchuoi83ne
 
PPTX
2.1 (1) (1).pptx new new new new newner o
nikhildogra44
 
PDF
0301502 ADVANCED JAVA_UNIT_1.pdf
jaydesai523137
 
PPTX
Java programming Chapter 4.pptx
ssusera0d3d2
 
PDF
Java IO
UTSAB NEUPANE
 
PPTX
Java Input and Output
Ducat India
 
Various io stream classes .47
myrajendra
 
Various io stream classes .47
myrajendra
 
Character stream classes introd .51
myrajendra
 
Inputstream
Rajasekhar Reddy
 
Inputstream
Rajasekhar Reddy
 
Java Input Output (java.io.*)
Om Ganesh
 
Character stream classes .52
myrajendra
 
Itp 120 Chapt 19 2009 Binary Input & Output
phanleson
 
Web Technology Web Technology Notes Streams Network Principles and SocketsUni...
uthayashangar1
 
Input & output
SAIFUR RAHMAN
 
Programming language JAVA Input output opearations
2025183005
 
Stream In Java.pptx
ssuser9d7049
 
Java session14
Niit Care
 
Monhocvecaujahetvagiuplaptunhhayhonha.pdf
cuchuoi83ne
 
2.1 (1) (1).pptx new new new new newner o
nikhildogra44
 
0301502 ADVANCED JAVA_UNIT_1.pdf
jaydesai523137
 
Java programming Chapter 4.pptx
ssusera0d3d2
 
Java IO
UTSAB NEUPANE
 
Java Input and Output
Ducat India
 

More from myrajendra (20)

PPT
Fundamentals
myrajendra
 
PPT
Data type
myrajendra
 
PPTX
Hibernate example1
myrajendra
 
PPTX
Jdbc workflow
myrajendra
 
PPTX
2 jdbc drivers
myrajendra
 
PPTX
3 jdbc api
myrajendra
 
PPTX
4 jdbc step1
myrajendra
 
PPTX
Dao example
myrajendra
 
PPTX
Sessionex1
myrajendra
 
PPTX
Internal
myrajendra
 
PPTX
3. elements
myrajendra
 
PPTX
2. attributes
myrajendra
 
PPTX
1 introduction to html
myrajendra
 
PPTX
Headings
myrajendra
 
PPTX
Forms
myrajendra
 
PPT
Css
myrajendra
 
PPTX
Views
myrajendra
 
PPTX
Views
myrajendra
 
PPTX
Views
myrajendra
 
PPT
Starting jdbc
myrajendra
 
Fundamentals
myrajendra
 
Data type
myrajendra
 
Hibernate example1
myrajendra
 
Jdbc workflow
myrajendra
 
2 jdbc drivers
myrajendra
 
3 jdbc api
myrajendra
 
4 jdbc step1
myrajendra
 
Dao example
myrajendra
 
Sessionex1
myrajendra
 
Internal
myrajendra
 
3. elements
myrajendra
 
2. attributes
myrajendra
 
1 introduction to html
myrajendra
 
Headings
myrajendra
 
Forms
myrajendra
 
Views
myrajendra
 
Views
myrajendra
 
Views
myrajendra
 
Starting jdbc
myrajendra
 
Ad

Byte arrayinputstream.50

  • 1. ByteArrayInputStream class http://improvejava.blogspot.in/ 1
  • 2. Objectives On completion of this period, you would be able to learn • Other I/O stream classes • ByteArrayInputStream • ByteArrayOutputStream • BufferedInputStream • BufferedOutputStream http://improvejava.blogspot.in/ 2
  • 3. Recap In the last class, you have studied about the types Stream Class • Byte Streams are two types 1. InputStream class 2. OutputStream class • FileInputStream and FileOutputStream are the subclasses of byte stream • Let us explore some more stream classes http://improvejava.blogspot.in/ 3
  • 4. ByteArrayInputStream class • Data stored in memory is handled by ByteArrayInputStream • This class is used to read bytes from a memory • Objects of this class are used to create input stream with memory buffers as data source • Constructors • ByteArrayInputStream(byte array[ ]) • ByteArrayInputStream(byte array[ ], int start, int numBytes) http://improvejava.blogspot.in/ 4
  • 5. ByteArrayOutputStream class • Data stored in memory is handled by ByteArrayOutputStream • This class is used to write bytes into memory • Objects of this class are used to create output stream with memory buffers as data sink • Constructors • ByteArrayOutputStream( ) • ByteArrayOutputStream(int numBytes) • In the first form, a buffer of 32 bytes is created. • In the second, a buffer is created with a size equal to that specified by numBytes http://improvejava.blogspot.in/ 5
  • 6. Filtered Byte Stream class • Byte streams access the data in byte form • Raw bytes can not be used for any useful purpose • For converting bytes to useful forms such as char, string, int, etc filtered streams are used • Streams that can take other stream as arguments are called filtered streams • FilterInputStream • BufferedInputStream is a subclass of it • FilterOutputStream • BufferedOutputStream is a subclass of it In many practical situations only filtered streams are useful http://improvejava.blogspot.in/ 6
  • 7. BufferedInputStream class • This is a subclass of FilterInpuStream • This class is used to increase the efficiency of reading bytes from an input stream • Fetching a byte and sending it to the destination one after the another is a time consuming process • Instead, bytes can be read and stored in buffer memory before sending it to the destination • Once the buffer is full, the bytes can be sent to the destination http://improvejava.blogspot.in/ 7
  • 8. BufferedOutputStream class • This class is a subclass of FilterOutputStream • This class is used to send buffered bytes to an underlying output stream in an efficient way Constructors • BufferedOutputStream(OutputStream outputStream) • BufferedOutputStream(OutputStream outputStream, int bufSize) • The first form creates a buffered stream using a buffer of 512 bytes. In the second form, • the size of the buffer is passed in bufSize. http://improvejava.blogspot.in/ 8
  • 9. Summary • Data stored in memory is handled by ByteArrayInputStream and is used to read bytes from a memory • ByteArrayOutputStream is used to write bytes into memory • FilteredStreams are used for converting bytes to useful forms such as char, string, int, etc http://improvejava.blogspot.in/ 9
  • 10. Quiz 1. ---- is used to read bytes from a memory A. ByteArrayOutputStream B. ByteArrayInputStream C. Reader D. None http://improvejava.blogspot.in/ 10
  • 11. Quiz 2. --- is used to write bytes into memory A. ByteArrayInputStream B. ByteArrayOutputStream C. Writer D. None http://improvejava.blogspot.in/ 11
  • 12. Frequently Asked Questions 1. Write about ByteArrayInput and ByteArrayOutput streams 2. Write about FilteredByte Streams http://improvejava.blogspot.in/ 12