SlideShare una empresa de Scribd logo
1 de 12
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

Más contenido relacionado

Similar a Byte arrayinputstream.50

Character stream classes introd .51
Character stream classes introd  .51Character stream classes introd  .51
Character stream classes introd .51
myrajendra
 
Various io stream classes .47
Various io stream classes .47Various io stream classes .47
Various io stream classes .47
myrajendra
 
Various io stream classes .47
Various io stream classes .47Various io stream classes .47
Various io stream classes .47
myrajendra
 
Java input output package
Java input output packageJava input output package
Java input output package
Sujit Kumar
 
Computer science input and output BASICS.pptx
Computer science input and output BASICS.pptxComputer science input and output BASICS.pptx
Computer science input and output BASICS.pptx
RathanMB
 
Character stream classes .52
Character stream classes .52Character stream classes .52
Character stream classes .52
myrajendra
 

Similar a Byte arrayinputstream.50 (20)

Character stream classes introd .51
Character stream classes introd  .51Character stream classes introd  .51
Character stream classes introd .51
 
Various io stream classes .47
Various io stream classes .47Various io stream classes .47
Various io stream classes .47
 
Various io stream classes .47
Various io stream classes .47Various io stream classes .47
Various io stream classes .47
 
L21 io streams
L21 io streamsL21 io streams
L21 io streams
 
Input & output
Input & outputInput & output
Input & output
 
Chapter 13_m5JAVANOTESAPPLETS,INPUT.pptx
Chapter 13_m5JAVANOTESAPPLETS,INPUT.pptxChapter 13_m5JAVANOTESAPPLETS,INPUT.pptx
Chapter 13_m5JAVANOTESAPPLETS,INPUT.pptx
 
Java input output package
Java input output packageJava input output package
Java input output package
 
Java Input Output (java.io.*)
Java Input Output (java.io.*)Java Input Output (java.io.*)
Java Input Output (java.io.*)
 
Computer science input and output BASICS.pptx
Computer science input and output BASICS.pptxComputer science input and output BASICS.pptx
Computer science input and output BASICS.pptx
 
Character stream classes .52
Character stream classes .52Character stream classes .52
Character stream classes .52
 
Java program file I/O
Java program file I/OJava program file I/O
Java program file I/O
 
Using Input Output
Using Input OutputUsing Input Output
Using Input Output
 
CHAPTER 5 mechanical engineeringasaaa.pptx
CHAPTER 5 mechanical engineeringasaaa.pptxCHAPTER 5 mechanical engineeringasaaa.pptx
CHAPTER 5 mechanical engineeringasaaa.pptx
 
bufferoverflow-151214121251 presentation
bufferoverflow-151214121251 presentationbufferoverflow-151214121251 presentation
bufferoverflow-151214121251 presentation
 
Buffer overflow
Buffer overflowBuffer overflow
Buffer overflow
 
Stream In Java.pptx
Stream In Java.pptxStream In Java.pptx
Stream In Java.pptx
 
Java IO, Serialization
Java IO, Serialization Java IO, Serialization
Java IO, Serialization
 
Session 22 - Java IO, Serialization
Session 22 - Java IO, SerializationSession 22 - Java IO, Serialization
Session 22 - Java IO, Serialization
 
0301502 ADVANCED JAVA_UNIT_1.pdf
0301502 ADVANCED JAVA_UNIT_1.pdf0301502 ADVANCED JAVA_UNIT_1.pdf
0301502 ADVANCED JAVA_UNIT_1.pdf
 
Advanced programming ch2
Advanced programming ch2Advanced programming ch2
Advanced programming ch2
 

Más de myrajendra (20)

Fundamentals
FundamentalsFundamentals
Fundamentals
 
Data type
Data typeData type
Data type
 
Hibernate example1
Hibernate example1Hibernate example1
Hibernate example1
 
Jdbc workflow
Jdbc workflowJdbc workflow
Jdbc workflow
 
2 jdbc drivers
2 jdbc drivers2 jdbc drivers
2 jdbc drivers
 
3 jdbc api
3 jdbc api3 jdbc api
3 jdbc api
 
4 jdbc step1
4 jdbc step14 jdbc step1
4 jdbc step1
 
Dao example
Dao exampleDao example
Dao example
 
Sessionex1
Sessionex1Sessionex1
Sessionex1
 
Internal
InternalInternal
Internal
 
3. elements
3. elements3. elements
3. elements
 
2. attributes
2. attributes2. attributes
2. attributes
 
1 introduction to html
1 introduction to html1 introduction to html
1 introduction to html
 
Headings
HeadingsHeadings
Headings
 
Forms
FormsForms
Forms
 
Css
CssCss
Css
 
Views
ViewsViews
Views
 
Views
ViewsViews
Views
 
Views
ViewsViews
Views
 
Starting jdbc
Starting jdbcStarting jdbc
Starting jdbc
 

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