SlideShare a Scribd company logo
1 of 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

More Related Content

What's hot

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 JavaPawanMM
 
Introduction to Thrift
Introduction to ThriftIntroduction to Thrift
Introduction to ThriftDvir Volk
 
Jsp client request
Jsp   client requestJsp   client request
Jsp client requestchauhankapil
 
Java networking programs - theory
Java networking programs - theoryJava networking programs - theory
Java networking programs - theoryMukesh Tekwani
 
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 2009jarfield
 
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 ComparisonIgor Anishchenko
 
Apache thrift-RPC service cross languages
Apache thrift-RPC service cross languagesApache thrift-RPC service cross languages
Apache thrift-RPC service cross languagesJimmy Lai
 
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...Guillaume Laforge
 

What's hot (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
 

Viewers also liked

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 ArchitectureNew Era University
 
Input Output Organization
Input Output OrganizationInput Output Organization
Input Output OrganizationKamal Acharya
 
Computer architecture
Computer architectureComputer architecture
Computer architectureRishabha Garg
 
Input Output - Computer Architecture
Input Output - Computer ArchitectureInput Output - Computer Architecture
Input Output - Computer ArchitectureMaruf Abdullah (Rion)
 
Input Output Interfaces
Input Output InterfacesInput Output Interfaces
Input Output InterfacesDarling Jemima
 

Viewers also liked (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
 

Similar to J2ME IO Classes

CHAPTER 5 mechanical engineeringasaaa.pptx
CHAPTER 5 mechanical engineeringasaaa.pptxCHAPTER 5 mechanical engineeringasaaa.pptx
CHAPTER 5 mechanical engineeringasaaa.pptxSadhilAggarwal
 
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.pptxYashrajMohrir
 
KScope14 Jython Scripting
KScope14 Jython ScriptingKScope14 Jython Scripting
KScope14 Jython ScriptingAlithya
 
Network programming in Java
Network programming in JavaNetwork programming in Java
Network programming in JavaTushar B Kute
 
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 Kafkamarius_bogoevici
 
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 3Joe Walker
 
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)Itzik Kotler
 
15network Programming Clients
15network Programming Clients15network Programming Clients
15network Programming ClientsAdil Jafri
 
Network Programming Clients
Network Programming ClientsNetwork Programming Clients
Network Programming ClientsAdil Jafri
 
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 MINAtrustinlee
 
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 ScalaYevgeniy Brikman
 
[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é
 
Network Programming in Java
Network Programming in JavaNetwork Programming in Java
Network Programming in JavaTushar B Kute
 
Lambdas & Streams
Lambdas & StreamsLambdas & Streams
Lambdas & StreamsC4Media
 
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 programgovindjha339843
 
Java- JDBC- Mazenet Solution
Java- JDBC- Mazenet SolutionJava- JDBC- Mazenet Solution
Java- JDBC- Mazenet SolutionMazenetsolution
 
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.pptxDrYogeshDeshmukh1
 
Basic html5 and javascript
Basic html5 and javascriptBasic html5 and javascript
Basic html5 and javascriptwendy017
 
Network programming in Java
Network programming in JavaNetwork programming in Java
Network programming in JavaTushar B Kute
 

Similar to 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
 

More from Rohan Chandane

Agile Maturity Model, Certified Scrum Master!
Agile Maturity Model, Certified Scrum Master!Agile Maturity Model, Certified Scrum Master!
Agile Maturity Model, Certified Scrum Master!Rohan Chandane
 
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 CourseRohan Chandane
 
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 Rohan Chandane
 
Agile :what i learnt so far
Agile :what i learnt so farAgile :what i learnt so far
Agile :what i learnt so farRohan Chandane
 
Sencha / ExtJS : Object Oriented JavaScript
Sencha / ExtJS : Object Oriented JavaScriptSencha / ExtJS : Object Oriented JavaScript
Sencha / ExtJS : Object Oriented JavaScriptRohan Chandane
 
TIBCO General Interface - CSS Guide
TIBCO General Interface - CSS GuideTIBCO General Interface - CSS Guide
TIBCO General Interface - CSS GuideRohan Chandane
 
Blogger's Park Presentation (Blogging)
Blogger's Park Presentation (Blogging)Blogger's Park Presentation (Blogging)
Blogger's Park Presentation (Blogging)Rohan Chandane
 
Java2 MicroEdition-J2ME
Java2 MicroEdition-J2MEJava2 MicroEdition-J2ME
Java2 MicroEdition-J2MERohan Chandane
 

More from 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
 

Recently uploaded

Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...apidays
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
AI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAnitaRaj43
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...apidays
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontologyjohnbeverley2021
 
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 WorkerThousandEyes
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKJago de Vreede
 
JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard37
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMKumar Satyam
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)Samir Dash
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 

Recently uploaded (20)

Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
AI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by Anitaraj
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
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
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptx
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDM
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 

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