IO In Java

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

1 comments

Comments 1 - 1 of 1 previous next Post a comment

Post a comment
Embed Video
Edit your comment Cancel

2 Favorites

IO In Java - Presentation Transcript

  1. I/O In Java Parag Shah Adaptive Software Solutions http://www.adaptivesoftware.biz http://www.adaptivelearningonline.net
  2. Agenda
    • Files
    • Streams
    • Serialization
    • Tokenization
  3. Overview
    • What should an IO system encompass?
      • Abstractions for the following
        • Communicating with various sources and sinks of I/O
            • Console
            • Files
            • Network sockets...
        • Doing the I/O in multiple ways
            • Character
            • Binary
            • Buffered...
    • Approach taken by Java for the IO system
  4. Vocabulary
    • Streams
    • Buffers
    • Readers
    • Writers
  5. Standard IO
    • Reading from StandardInput (see Echo.java)
        • System.in (Raw IOStream)
    • Writing to Standard Output
        • System.out (PrintStream)
    • Standard Error
        • System.err (PrintStream)
    • Redirecting standard IO [see: Redirecting.java]
  6. A Simple Example
    • System.out.println();
    • System is a class
    • out is a static attribute of system
    • out is of type PrintStream
  7. A Simple Example contd.
    • System.in.read();
    • BufferedReader br = new BufferedInputStream(new InputStreamReader(System.in));
    • System is a class
    • in is a static attribute of system
    • in is of type InputStream
    • InputStreamReader converts an InputStream to the Reader hierarchy
    • BufferedReader adds buffering and line reading capabilities to the Reader
  8. Files & Directories
    • The File class is an abstract represention of file and directory pathnames
    • It does NOT represent a file
    • see FileExample.java
    • RandomAccessFile does represent a file
      • Can read or write at arbitrary locations
  9. Streams
    • What are Streams?
        • Arbitrary data source/destination
        • Details of the device is abstracted
    • InputStream
        • Data input source
        • Abstract class java.io.InputStream
    • OutputStream
        • Data output destination
        • Abstract class java.io.OutputStream
  10. InputStream
    • Various sources of data
        • Array of bytes
        • String object
        • File
        • Pipe
  11. InputStream
    • See [StreamExample.java]
  12. OutputStream
    • Data Sinks
        • ByteArray
        • File
        • Pipe
  13. OutputStream
    • See [StreamExample.java]
  14. FilterInputStream
    • Used to format/filter data being read from an InputStream
    • Types of FilterInputStream
      • DataInputStream
      • BufferedInputStream
      • LineNumberInputStream
      • PushbackInputStream
  15. FilterOutputStream
    • Used to write formatted/filtered data to an OutputStream
    • Types of FilterOutputStream
      • DataOutputStream
      • PrintStream
      • BufferedOutputStream
  16. Readers & Writers
    • Purpose of Readers & Writers
        • Input/Output Stream are for byte based I/O
        • Readers for unicode based char I/O
    • Modifying stream behaviour
        • FilterReader
        • FilterWriter (abstract class with no subclasses)
  17. The Reader Hierarchy
    • The Reader Hierarchy
  18. The Writer Hierarchy
    • The Writer Hierarchy
  19. IO Best Practices
    • Best Practice
        • Use Readers / Writers for character IO
        • Use Input/OutputStream for byte based IO
        • For reading/writing data in a portable manner use DataInput(Output)Stream
        • Use buffering
        • Always close the streams
  20. Object Serialization - 1
    • What is serialization
    • When do we need serialization
  21. Object Serialization - 2
    • Serializing objects
      • ObjectOutputStream
    • Deserializing objects
      • ObjectInputStream
    • Remember no constructors are called
    • see [SerializationExample.java]
  22. Object Serialization - 3
    • Controlling serialization
      • The Serializable interface
      • The transient keyword
      • The Externalizable interface
  23. Tokenizing
    • What are tokens?
    • StringTokenizer
    • StreamTokenizer
  24. String Tokenizer
    • Tokenizes a String
    • We must define delimiting characters
    • Throws an Exception if we go beyond the String size.
    • See [StringTokenizingExample.java]
    • It is recommended to use the split() method in String
    • See [StringSplitExample.java]
  25. Stream Tokenizer
    • Tokenizes an input stream
    • Parsing process is controlled by a table and flags
    • Each byte read from the input stream is regarded as a character in the range 'u0000' through 'u00FF'
  26. Stream Tokenizer
    • The character value is used to look up five possible attributes of the character
      • White space
      • Alphabetic
      • Numeric
      • String quote
      • Comment character
    • Each character can have zero or more of these attributes
  27. Stream Tokenizer
    • Each tokenizer has four flags :-
      • Whether line terminators are to be returned as tokens or treated as white space that merely separates tokens.
      • Whether C-style comments are to be recognized and skipped.
      • Whether C++-style comments are to be recognized and skipped.
      • Whether the characters of identifiers are converted to lowercase.
  28. Using Stream Tokenizer
    • Create an instance of StreamTokenizer
    • Set up tables and flags
    • Loop through the stream calling nextToken until a TT_EOF is returned.
    • See [StreamTokenizingExample.java]
  29. Summary
    • Streams
    • Types of Input & Output streams
    • The decorator design pattern
    • The need for so many stream classes
    • Serialization
    • Tokenizing
  30. Where to Get More Information
    • Thinking In Java By Bruce Eckel
    • Sun Java Trail
      • http://java.sun.com/docs/books/tutorial/essential/io/index.html

+ paragparag, 3 years ago

custom

2589 views, 2 favs, 2 embeds more stats

More info about this document

© All Rights Reserved

Go to text version

  • Total Views 2589
    • 2585 on SlideShare
    • 4 from embeds
  • Comments 1
  • Favorites 2
  • Downloads 31
Most viewed embeds
  • 2 views on http://indijava.in
  • 2 views on http://www.indijava.in

more

All embeds
  • 2 views on http://indijava.in
  • 2 views on http://www.indijava.in

less

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

Cancel
File a copyright complaint
Having problems? Go to our helpdesk?

Categories

Tags