SlideShare uma empresa Scribd logo
1 de 23
J2ME I/O Classes

                     Rohan Chandane
             rohan.chandane@indiatimes.com



This notes are created by me, Rohan Chandane as learning material while pursuing MSc (CA) from SICSR. (CC) 2005-07
Basics
   CLDC-MIDP package for input/output
       java.io;
       javax.microedition.io;
   Contain classes
       For input/output (I/O)
       For networking I/O
   Contain Interface, (which MIDP adds)
       Including HttpConnection
               Defines methods and constants for HTTP connection
javax.microedition.io Package
   Networking support using
       The Generic Connection Framework
       Includes
           New socket
           UDP
           Serial connection types
           Secure connection types
           Push functionality
The Generic Connection
Framework (GCF)
   Class hierarchy of the Generic
    Connection Framework




     GCF is a set of interfaces defined within the javax.microedition.io package
Continued…
   Connection Interface is at root
   Supported by
       datagram (packet)
       stream connections
            Input stream
            Output stream
Interfaces
   7 main Interfaces
       Connection
       InputConnection
       OutputConnection
       DatagramConnection
       StreamConncetion
       StreamConnectionNotifier
       ContentConnection
In brief - Interfaces
   The Connection interface
       Most basic connection type
       It can only be opened and closed
   The InputConnection interface
       Representation of stream based input
        connection
   The OutputConnection interface
       Representation of stream based output
        connection
Continued…
   The DatagramConnection interface
       For sending and receiving UDP packet
        oriented data
       Following address scheme is used
            {protocol}://[{host}]:[{port}]
       Example
            A datagram connection for accepting datagrams
             datagram://:1234
            A datagram connection for sending to a server:
             datagram://123.456.789.12:1234
Continued…
   The StreamConncetion interface
       A two way stream connection to a device
       Include both input and output connection
       Combines the input and output connections
   The StreamConncetionNotifier interface
       Waits for a connection to be established
       Returns a StreamConnection on which a
        communication link has been established.
Continued…
   The ContentConnection interface
       Subinterface of StreamConnection
       Provides access to some of the basic meta
        data information provided by HTTP
        connections
Classes
   Connector class is used to open every
    type of connection in GCF
   open() method
       Connector Class method
       All connections are created using this static
        method
       Following syntax used
            Connector.Open(quot;protocol:address;parametersquot;);
Continued…
   Few examples
       HTTP Connection
              Connector.open(quot;http://java.sun.com/developerquot;);
       Datagram Connection
              Connector.open(quot;datagram://address:port#quot;);
       Communicate with a Port
              Connector.open(quot;comm:0;baudrate=9600');
       Open Files
              Connector.open(quot;file:/myFile.txtquot;);
       Socket Connection
              Connector.open(quot;socket://localhost:9000quot;);
Continued…
   CGF has 7 methods to open Connection
Connector (public class Connector)
  public static Connection open(String name)
  public static Connection open(String name)
  public static Connection open(String name, int mode, boolean timeouts)
  public static DataInputStream openDataInputStream(String name)
  public static DataOutputStream openDataOutputStream(String name)
  public static InputStream openInputStream(String name)
  public static OutputStream openOutputStream(String name)
Examples
// create ContentConnection
String url = quot;http://www.mysite.com/mypage.jspquot;
ContentConnection conn = (ContentConnection)Connector.open(url);

// with connection open input stream
InputStream is = conn.openInputStream();
Read Image from server
// create ContentConnection
String url = quot;http://www.mysite.com/mypage.jspquot;
ContentConnection conn = (ContentConnection)Connector.open(url);

// with connection open input stream
InputStream is = conn.openInputStream();

// ContentConnection include lengh method
int lenght = (int) Conn.getLength();
if(length != -1)
{
          byte imagebyte[] = new byte[length];
          is.read(imagebyte);
}
HTTP support in MIDP
   GCF class support for HTTP
Continued…
// Create a HttpConnection
String url = quot;http://www.mysite.com/mypage.jspquot;
HttpConnection conn = (HttpConnection)Connector.open(url)

// with connection open a input stream reader (java.io package class)
InputSteamReader doc = new InputStreamReader(conn.openInputStream());



// Create a Secure Http Connection
String url = quot;http://www.mysite.com/mypage.jspquot;
HttpsConnection conn = (HttpsConnection)Connector.open(url)

// with connection open a input stream reader (java.io package class)
InputSteamReader doc = new InputStreamReader(conn.openInputStream());
I/O Classes in J2ME
   I/O Class Library Package
       java.io
   11 Classes are mainly used
       InputStream
            Base class for inputstream
            To obtain input stream from source
            Input stream need to wait till web server
             delivers the data from web page
Continued…
    ByteArrayInputStream
        Input stream that reads data from the internal
         byte array
    DataInputStream
        Stream that enters data into primitive Java data
         type
    InputStreamReader
        Stream that reads data as text characters
Continued…
    Reader
        An abstract class that is used to enter stream
         of character
    OutputStream
        The base class for output stream
    ByteArrayOutputStream
        Output stream which write data into internal
         byte array
Continued…
    DataOutputStram
         Stream that holds data written for primitive
          data type
    OutputStreamReader
         Stream that writes data as text characters
    Writer
         An abstract class that is used to write streams
          of character
    PrintStream
         Output stream that enables the writing of
          primitive data types
InputStream
   Methods
       read()
            Reads data as byte integer, Returns -1 if end of
             input stream
       read(byte b[])
            Takes array of byte as input and store it in an
             array
       read(byte b[], int offset, int length)
            Accept array of byte, offset is exact position in
             array where we want to store input data,
             length is max number of byte to be read
OutputStream
   Methods
       write(int n)
            Used to write single byte of data
       write(byte b[])
            Allow to write array of bytes
       write(byte b[], int offset, int length)
            Accept array of byte, offset is exact position in
             array where we want to write data, length is
             max number of byte to be written

Mais conteúdo relacionado

Mais procurados

Introduction to Thrift
Introduction to ThriftIntroduction to Thrift
Introduction to Thrift
Dvir Volk
 
Teach your (micro)services talk Protocol Buffers with gRPC.
Teach your (micro)services talk Protocol Buffers with gRPC.Teach your (micro)services talk Protocol Buffers with gRPC.
Teach your (micro)services talk Protocol Buffers with gRPC.
Mihai Iachimovschi
 
HornetQ Presentation On JBoss World 2009
HornetQ Presentation On JBoss World 2009HornetQ Presentation On JBoss World 2009
HornetQ Presentation On JBoss World 2009
jarfield
 

Mais procurados (16)

Protocol Buffers
Protocol BuffersProtocol Buffers
Protocol Buffers
 
Session 24 - JDBC, Intro to Enterprise Java
Session 24 - JDBC, Intro to Enterprise JavaSession 24 - JDBC, Intro to Enterprise Java
Session 24 - JDBC, Intro to Enterprise Java
 
Protocol Buffers
Protocol BuffersProtocol Buffers
Protocol Buffers
 
Jug java7
Jug java7Jug java7
Jug java7
 
HTTP
HTTPHTTP
HTTP
 
Introduction to Thrift
Introduction to ThriftIntroduction to Thrift
Introduction to Thrift
 
Jsp client request
Jsp   client requestJsp   client request
Jsp client request
 
Java networking programs - theory
Java networking programs - theoryJava networking programs - theory
Java networking programs - theory
 
java networking
 java networking java networking
java networking
 
Teach your (micro)services talk Protocol Buffers with gRPC.
Teach your (micro)services talk Protocol Buffers with gRPC.Teach your (micro)services talk Protocol Buffers with gRPC.
Teach your (micro)services talk Protocol Buffers with gRPC.
 
HornetQ Presentation On JBoss World 2009
HornetQ Presentation On JBoss World 2009HornetQ Presentation On JBoss World 2009
HornetQ Presentation On JBoss World 2009
 
Networking in Java
Networking in JavaNetworking in Java
Networking in Java
 
Thrift vs Protocol Buffers vs Avro - Biased Comparison
Thrift vs Protocol Buffers vs Avro - Biased ComparisonThrift vs Protocol Buffers vs Avro - Biased Comparison
Thrift vs Protocol Buffers vs Avro - Biased Comparison
 
Apache thrift-RPC service cross languages
Apache thrift-RPC service cross languagesApache thrift-RPC service cross languages
Apache thrift-RPC service cross languages
 
Groovy DSLs, from Beginner to Expert - Guillaume Laforge and Paul King - Spri...
Groovy DSLs, from Beginner to Expert - Guillaume Laforge and Paul King - Spri...Groovy DSLs, from Beginner to Expert - Guillaume Laforge and Paul King - Spri...
Groovy DSLs, from Beginner to Expert - Guillaume Laforge and Paul King - Spri...
 
Google Protocol Buffers
Google Protocol BuffersGoogle Protocol Buffers
Google Protocol Buffers
 

Destaque (7)

Input output interface
Input output interfaceInput output interface
Input output interface
 
13. Computer Systems Input And Output Architecture
13. Computer Systems   Input And  Output Architecture13. Computer Systems   Input And  Output Architecture
13. Computer Systems Input And Output Architecture
 
Networking devices
Networking devicesNetworking devices
Networking devices
 
Input Output Organization
Input Output OrganizationInput Output Organization
Input Output Organization
 
Computer architecture
Computer architectureComputer architecture
Computer architecture
 
Input Output - Computer Architecture
Input Output - Computer ArchitectureInput Output - Computer Architecture
Input Output - Computer Architecture
 
Input Output Interfaces
Input Output InterfacesInput Output Interfaces
Input Output Interfaces
 

Semelhante a J2ME IO Classes

15network Programming Clients
15network Programming Clients15network Programming Clients
15network Programming Clients
Adil Jafri
 
Network Programming Clients
Network Programming ClientsNetwork Programming Clients
Network Programming Clients
Adil Jafri
 
[DSBW Spring 2009] Unit 02: Web Technologies (2/2)
[DSBW Spring 2009] Unit 02: Web Technologies (2/2)[DSBW Spring 2009] Unit 02: Web Technologies (2/2)
[DSBW Spring 2009] Unit 02: Web Technologies (2/2)
Carles Farré
 
Basic html5 and javascript
Basic html5 and javascriptBasic html5 and javascript
Basic html5 and javascript
wendy017
 

Semelhante a J2ME IO Classes (20)

CHAPTER 5 mechanical engineeringasaaa.pptx
CHAPTER 5 mechanical engineeringasaaa.pptxCHAPTER 5 mechanical engineeringasaaa.pptx
CHAPTER 5 mechanical engineeringasaaa.pptx
 
1.26 File Input-Output in JAVA.pptx
1.26 File Input-Output in JAVA.pptx1.26 File Input-Output in JAVA.pptx
1.26 File Input-Output in JAVA.pptx
 
KScope14 Jython Scripting
KScope14 Jython ScriptingKScope14 Jython Scripting
KScope14 Jython Scripting
 
T2
T2T2
T2
 
Network programming in Java
Network programming in JavaNetwork programming in Java
Network programming in Java
 
Developing real-time data pipelines with Spring and Kafka
Developing real-time data pipelines with Spring and KafkaDeveloping real-time data pipelines with Spring and Kafka
Developing real-time data pipelines with Spring and Kafka
 
What's new in DWR version 3
What's new in DWR version 3What's new in DWR version 3
What's new in DWR version 3
 
Hack Like It's 2013 (The Workshop)
Hack Like It's 2013 (The Workshop)Hack Like It's 2013 (The Workshop)
Hack Like It's 2013 (The Workshop)
 
15network Programming Clients
15network Programming Clients15network Programming Clients
15network Programming Clients
 
Network Programming Clients
Network Programming ClientsNetwork Programming Clients
Network Programming Clients
 
Rapid Network Application Development with Apache MINA
Rapid Network Application Development with Apache MINARapid Network Application Development with Apache MINA
Rapid Network Application Development with Apache MINA
 
Play Framework: async I/O with Java and Scala
Play Framework: async I/O with Java and ScalaPlay Framework: async I/O with Java and Scala
Play Framework: async I/O with Java and Scala
 
[DSBW Spring 2009] Unit 02: Web Technologies (2/2)
[DSBW Spring 2009] Unit 02: Web Technologies (2/2)[DSBW Spring 2009] Unit 02: Web Technologies (2/2)
[DSBW Spring 2009] Unit 02: Web Technologies (2/2)
 
Network Programming in Java
Network Programming in JavaNetwork Programming in Java
Network Programming in Java
 
Lambdas & Streams
Lambdas & StreamsLambdas & Streams
Lambdas & Streams
 
Networking.ppt(client/server, socket) uses in program
Networking.ppt(client/server, socket) uses in programNetworking.ppt(client/server, socket) uses in program
Networking.ppt(client/server, socket) uses in program
 
Java- JDBC- Mazenet Solution
Java- JDBC- Mazenet SolutionJava- JDBC- Mazenet Solution
Java- JDBC- Mazenet Solution
 
Unit No 5 Files and Database Connectivity.pptx
Unit No 5 Files and Database Connectivity.pptxUnit No 5 Files and Database Connectivity.pptx
Unit No 5 Files and Database Connectivity.pptx
 
Basic html5 and javascript
Basic html5 and javascriptBasic html5 and javascript
Basic html5 and javascript
 
Network programming in Java
Network programming in JavaNetwork programming in Java
Network programming in Java
 

Mais de Rohan Chandane

Agile :what i learnt so far
Agile :what i learnt so farAgile :what i learnt so far
Agile :what i learnt so far
Rohan Chandane
 
TIBCO General Interface - CSS Guide
TIBCO General Interface - CSS GuideTIBCO General Interface - CSS Guide
TIBCO General Interface - CSS Guide
Rohan Chandane
 

Mais de Rohan Chandane (13)

Agile Maturity Model, Certified Scrum Master!
Agile Maturity Model, Certified Scrum Master!Agile Maturity Model, Certified Scrum Master!
Agile Maturity Model, Certified Scrum Master!
 
Agile & Scrum, Certified Scrum Master! Crash Course
Agile & Scrum,  Certified Scrum Master! Crash CourseAgile & Scrum,  Certified Scrum Master! Crash Course
Agile & Scrum, Certified Scrum Master! Crash Course
 
An Introduction To Testing In AngularJS Applications
An Introduction To Testing In AngularJS Applications An Introduction To Testing In AngularJS Applications
An Introduction To Testing In AngularJS Applications
 
Agile :what i learnt so far
Agile :what i learnt so farAgile :what i learnt so far
Agile :what i learnt so far
 
Backbone js
Backbone jsBackbone js
Backbone js
 
Node js
Node jsNode js
Node js
 
Sencha / ExtJS : Object Oriented JavaScript
Sencha / ExtJS : Object Oriented JavaScriptSencha / ExtJS : Object Oriented JavaScript
Sencha / ExtJS : Object Oriented JavaScript
 
TIBCO General Interface - CSS Guide
TIBCO General Interface - CSS GuideTIBCO General Interface - CSS Guide
TIBCO General Interface - CSS Guide
 
Blogger's Park Presentation (Blogging)
Blogger's Park Presentation (Blogging)Blogger's Park Presentation (Blogging)
Blogger's Park Presentation (Blogging)
 
J2ME GUI Programming
J2ME GUI ProgrammingJ2ME GUI Programming
J2ME GUI Programming
 
Parsing XML in J2ME
Parsing XML in J2MEParsing XML in J2ME
Parsing XML in J2ME
 
J2ME RMS
J2ME RMSJ2ME RMS
J2ME RMS
 
Java2 MicroEdition-J2ME
Java2 MicroEdition-J2MEJava2 MicroEdition-J2ME
Java2 MicroEdition-J2ME
 

Último

CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 

Último (20)

Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 

J2ME IO Classes

  • 1. J2ME I/O Classes Rohan Chandane rohan.chandane@indiatimes.com This notes are created by me, Rohan Chandane as learning material while pursuing MSc (CA) from SICSR. (CC) 2005-07
  • 2. Basics  CLDC-MIDP package for input/output  java.io;  javax.microedition.io;  Contain classes  For input/output (I/O)  For networking I/O  Contain Interface, (which MIDP adds)  Including HttpConnection  Defines methods and constants for HTTP connection
  • 3. javax.microedition.io Package  Networking support using  The Generic Connection Framework  Includes  New socket  UDP  Serial connection types  Secure connection types  Push functionality
  • 4. The Generic Connection Framework (GCF)  Class hierarchy of the Generic Connection Framework GCF is a set of interfaces defined within the javax.microedition.io package
  • 5. Continued…  Connection Interface is at root  Supported by  datagram (packet)  stream connections  Input stream  Output stream
  • 6. Interfaces  7 main Interfaces  Connection  InputConnection  OutputConnection  DatagramConnection  StreamConncetion  StreamConnectionNotifier  ContentConnection
  • 7. In brief - Interfaces  The Connection interface  Most basic connection type  It can only be opened and closed  The InputConnection interface  Representation of stream based input connection  The OutputConnection interface  Representation of stream based output connection
  • 8. Continued…  The DatagramConnection interface  For sending and receiving UDP packet oriented data  Following address scheme is used  {protocol}://[{host}]:[{port}]  Example  A datagram connection for accepting datagrams datagram://:1234  A datagram connection for sending to a server: datagram://123.456.789.12:1234
  • 9. Continued…  The StreamConncetion interface  A two way stream connection to a device  Include both input and output connection  Combines the input and output connections  The StreamConncetionNotifier interface  Waits for a connection to be established  Returns a StreamConnection on which a communication link has been established.
  • 10. Continued…  The ContentConnection interface  Subinterface of StreamConnection  Provides access to some of the basic meta data information provided by HTTP connections
  • 11. Classes  Connector class is used to open every type of connection in GCF  open() method  Connector Class method  All connections are created using this static method  Following syntax used  Connector.Open(quot;protocol:address;parametersquot;);
  • 12. Continued…  Few examples  HTTP Connection  Connector.open(quot;http://java.sun.com/developerquot;);  Datagram Connection  Connector.open(quot;datagram://address:port#quot;);  Communicate with a Port  Connector.open(quot;comm:0;baudrate=9600');  Open Files  Connector.open(quot;file:/myFile.txtquot;);  Socket Connection  Connector.open(quot;socket://localhost:9000quot;);
  • 13. Continued…  CGF has 7 methods to open Connection Connector (public class Connector) public static Connection open(String name) public static Connection open(String name) public static Connection open(String name, int mode, boolean timeouts) public static DataInputStream openDataInputStream(String name) public static DataOutputStream openDataOutputStream(String name) public static InputStream openInputStream(String name) public static OutputStream openOutputStream(String name)
  • 14. Examples // create ContentConnection String url = quot;http://www.mysite.com/mypage.jspquot; ContentConnection conn = (ContentConnection)Connector.open(url); // with connection open input stream InputStream is = conn.openInputStream();
  • 15. Read Image from server // create ContentConnection String url = quot;http://www.mysite.com/mypage.jspquot; ContentConnection conn = (ContentConnection)Connector.open(url); // with connection open input stream InputStream is = conn.openInputStream(); // ContentConnection include lengh method int lenght = (int) Conn.getLength(); if(length != -1) { byte imagebyte[] = new byte[length]; is.read(imagebyte); }
  • 16. HTTP support in MIDP  GCF class support for HTTP
  • 17. Continued… // Create a HttpConnection String url = quot;http://www.mysite.com/mypage.jspquot; HttpConnection conn = (HttpConnection)Connector.open(url) // with connection open a input stream reader (java.io package class) InputSteamReader doc = new InputStreamReader(conn.openInputStream()); // Create a Secure Http Connection String url = quot;http://www.mysite.com/mypage.jspquot; HttpsConnection conn = (HttpsConnection)Connector.open(url) // with connection open a input stream reader (java.io package class) InputSteamReader doc = new InputStreamReader(conn.openInputStream());
  • 18. I/O Classes in J2ME  I/O Class Library Package  java.io  11 Classes are mainly used  InputStream  Base class for inputstream  To obtain input stream from source  Input stream need to wait till web server delivers the data from web page
  • 19. Continued…  ByteArrayInputStream  Input stream that reads data from the internal byte array  DataInputStream  Stream that enters data into primitive Java data type  InputStreamReader  Stream that reads data as text characters
  • 20. Continued…  Reader  An abstract class that is used to enter stream of character  OutputStream  The base class for output stream  ByteArrayOutputStream  Output stream which write data into internal byte array
  • 21. Continued…  DataOutputStram  Stream that holds data written for primitive data type  OutputStreamReader  Stream that writes data as text characters  Writer  An abstract class that is used to write streams of character  PrintStream  Output stream that enables the writing of primitive data types
  • 22. InputStream  Methods  read()  Reads data as byte integer, Returns -1 if end of input stream  read(byte b[])  Takes array of byte as input and store it in an array  read(byte b[], int offset, int length)  Accept array of byte, offset is exact position in array where we want to store input data, length is max number of byte to be read
  • 23. OutputStream  Methods  write(int n)  Used to write single byte of data  write(byte b[])  Allow to write array of bytes  write(byte b[], int offset, int length)  Accept array of byte, offset is exact position in array where we want to write data, length is max number of byte to be written