StreamTokenizer Break up a stream of text into pieces called tokens A token is the smallest unit recognized by a text parsing algorithm (words, symbols,

Slides:



Advertisements
Similar presentations
Lecture 15: I/O and Parsing
Advertisements

Formal Language, chapter 4, slide 1Copyright © 2007 by Adam Webber Chapter Four: DFA Applications.
Lecture 10: Networking using Socket Programming. Client-Server Model b The term server applies to any program that offers a service that can be reached.
Prepared By E. Musa Alyaman1 URLs, InetAddresses, and URLConnections Chapter 9.
Using Processing Stream. Predefined Streams System.in InputStream used to read bytes from the keyboard System.out PrintStream used to write bytes to the.
Java Sockets Source:
1 LECTURE#7: Console Input Overview l Introduction to Wrapper classes. l Introduction to Exceptions (Java run-time errors). l Console input using the BufferedReader.
Programming Applets How do Applets work ? This is an HTML page This is the applet’s code It has a link to an applet.
Programming TCP Clients. InetAddress Class An IP address identifies uniquely a host in the internet, which consists of 4 numbers (1 byte each one) in.
1 Java Networking CS , Spring 2008/9. 2 Today’s Menu Networking Basics  TCP, UDP, Ports, DNS, Client-Server Model TCP/IP in Java Sockets URL 
Internet Programming In Java. References Java.sun.com Java552 Many of the programs shown.
String Tokenization What is String Tokenization?
CIS – Spring Instructors: Geoffrey Fox, Bryan Carpenter Computational Science and.
Java sockets. From waiting.
StringBuffer class  Alternative to String class  Can be used wherever a string is used  More flexible than String  Has three constructors and more.
1 Text File I/O Overview l I/O streams l Opening a text file for reading l Reading a text file l Closing a stream l Reading numbers from a text file l.
Projekt współfinansowany przez Unię Europejską w ramach Europejskiego Funduszu Społecznego „Networking”
Programming TCP Clients. InetAddress Class An IP address identifies uniquely a host in the internet, which consists of 4 numbers (1 byte each one) in.
Strings and File I/O. Strings Java String objects are immutable Common methods include: –boolean equalsIgnoreCase(String str) –String toLowerCase() –String.
Networking Support In Java Nelson Padua-Perez Bill Pugh Department of Computer Science University of Maryland, College Park.
Java Review 2. The Agenda The following topics were highlighted to me as issues: –File IO (Rem) –Wrappers (Rem) –Interfaces (Rem) –Asymptotic Notation.
1 Java Networking – part I CS , Winter 2007/8.
CSE 341, S. Tanimoto Java networking- 1 Java Networking Motivation Network Layers Using Sockets A Tiny Server Applets URLs Downloading Images, MediaTracker.
1 Java Networking CS , Spring Today’s Menu Networking Basics  TCP, UDP, Ports, DNS, Client-Server Model TCP/IP in Java Sockets URL  The.
Networking Basics Computers running on the Internet communicate to each other using either the Transmission Control Protocol (TCP) or the User Datagram.
Ryerson University CPS Distributing Computing with Java.
Two Ways to Store Data in a File Text format Binary format.
Appendix F: Network Programming in Java ©SoftMoore ConsultingSlide 1.
Application Protocols: HTTP CSNB534 Semester 2, 2007/2008 Asma Shakil.
Recitation 1 CS0445 Data Structures Mehmud Abliz.
Import java.net.*; import java.io.*; public class LowPortScanner { public static void main(String[] args) { String host = "localhost"; if (args.length.
DBI Representation and Management of Data on the Internet.
Based on OOP with Java, by David J. Barnes Input-Output1 The java.io Package 4 Text files Reader and Writer classes 4 Byte stream files InputStream, FileInputStream,
Servlet Communication Other Servlets, HTML pages, objects shared among servlets on same server Servlets on another server with HTTP request of the other.
MIT AITI 2003 Lecture 15 Streams Input and Output data from/to other sources.
1 Recitation 8. 2 Outline Goals of this recitation: 1.Learn about loading files 2.Learn about command line arguments 3.Review of Exceptions.
Network Programming With Java Hilal Arslan Hale Müge Kıncak.
Lecture 9 Network programming. Manipulating URLs URL is an acronym for Uniform Resource Locator and is a reference (an address) to a resource on the Internet.
Chapter 9-Text File I/O. Overview n Text File I/O and Streams n Writing to a file. n Reading from a file. n Parsing and tokenizing. n Random Access n.
A DVANCED P ROGRAMMING USING J AVA N ETWORKING B ASICS Prepared by / Nael Alian University of Palestine 1.
NETWORK PROGRAMMING.
Networks Sockets and Streams. TCP/IP in action server ports …65535 lower port numbers ( ) are reserved port echo7 time13 ftp20 telnet23.
1 cs205: engineering software university of virginia fall 2006 Network Programming* * Just enough to make you dangerous Bill Cheswick’s map of the Internet.
1 StringTokenization Overview l StringTokenizer class l Some StringTokenizer methods l StringTokenizer examples.
VII. Sockets. 1. What is a Socket? A socket is one end-point of a two-way communication link between two programs running on the network. Socket classes.
CS101 Lab “File input/Output”. File input, output File : binary file, text file READ/WRITE class of “text file” - File Reading class : FileReader, BufferedReader.
5-Dec-15 Sequential Files and Streams. 2 File Handling. File Concept.
– Advanced Programming P ROGRAMMING IN Lecture 22 Input and Output System.
CS 1312 Introduction to Object Oriented Programming Lecture 10 Java’s String class Java File I/O.
CSI 3125, Preliminaries, page 1 Java I/O. CSI 3125, Preliminaries, page 2 Java I/O Java I/O (Input and Output) is used to process the input and produce.
Java Programming II Java Network (I) Java Programming II.
1 Lecture 9: Network programming. 2 Manipulating URLs URL is an acronym for Uniform Resource Locator and is a reference (an address) to a resource on.
URL Programming Mimi Opkins CECS277. What is a URL?  URL is an acronym for Uniform Resource Locator and is a reference (an address) to a resource on.
Java Input/Output. Java Input/output Input is any information that is needed by your program to complete its execution. Output is any information that.
Strings and File I/O. Strings Java String objects are immutable Common methods include: –boolean equalsIgnoreCase(String str) –String toLowerCase() –String.
Spring/2002 Distributed Software Engineering C:\unocourses\4350\slides\DefiningThreads 1 Java API for distributed computing.
Network Programming James Atlas July 10, James Atlas - CISC3702 Review Multi-Threaded Programming Multi-Threaded Programming  Processes  Threads.
Working with URLs CSIE, National University of Tainan.
Source: Java Sockets Source:
Network Programming Introduction
Strings and File I/O.
CHAPTER 5 JAVA FILE INPUT/OUTPUT
„Networking”.
URL in Java C343 Lab (Week 13).
Reading and Writing Text Files
Networking.
មជ្ឈមណ្ឌលកូរ៉េ សហ្វវែរ អេច អ ឌី
Uniform Resource Locator: URL
Programming TCP Clients
Presentation transcript:

StreamTokenizer Break up a stream of text into pieces called tokens A token is the smallest unit recognized by a text parsing algorithm (words, symbols, etc…) nextToken() returns the next token in the stream

Constants: end-of-file, end-of-line, parsed floating point number, and parsed word (whitespace) pushBack(): pushes the token back onto the stream. Can specify how tokens are recognized Reader r = new BufferedReader(new InputStreamReader(is)); StreamTokenizer st = new StreamTokenizer(r); Works very much like StringTokenizer

StringTokenizer(String str, String delim); str: Input string to tokenize delim: String containing delimitingcharacters. Default is “\t\n\r” Alternative for Project 2

Random Access Files java.io.RandomAccessFile Read arbitrary bytes, text, and primitive data types from or to any specified location in a file. new RandomAccessFile("farrago.txt", "rw"); seek(long pos): Used to select the position in the file ( pos )

skipBytes Moves the file pointer forward the specified number of bytes. seek Positions the file pointer just before the specified byte. getFilePointer Returns the current byte location of the file pointer.

URL Uniform Resource Locator and Java Class Protocol Identifier and resource protocol://resource URL gamelan = new URL(" Relative URL’s URL(URL baseURL, String relativeURL)

URL gamelan = new URL(" URL gamelanGames = new URL(gamelan, "Gamelan.game.html"); URL gamelanNetwork = new URL(gamelan, "Gamelan.net.html"); URL gamelanNetworkBottom = new URL(gamelanNetwork, "#BOTTOM"); URL gamelan = new URL("http", " 80, "pages/Gamelan.network.html"); try { URL myURL = new URL(...) } catch (MalformedURLException e) {... // exception handler code here... }

Parsing an URL getProtocol Returns the protocol identifier component of the URL. getHost Returns the host name component of the URL. getPort Returns the port number component of the URL. The getPort method returns an integer that is the port number. If the port is not set, getPort returns -1. getFile Returns the filename component of the URL. getRef Returns the reference component of the URL.

public class ParseURL { public static void main(String[] args) throws Exception { URL aURL = new URL(" books/tutorial/intro.html#DOWNLOADING"); System.out.println("protocol = " + aURL.getProtocol()); System.out.println("host = " + aURL.getHost()); System.out.println("filename = " + aURL.getFile()); System.out.println("port = " + aURL.getPort()); System.out.println("ref = " + aURL.getRef()); } protocol = http host = java.sun.com filename = /docs/books/tutorial/intro.html port = 80 ref = DOWNLOADING

import java.net.*; import java.io.*; public class URLReader { public static void main(String[] args) throws Exception { URL yahoo = new URL(" BufferedReader in = new BufferedReader( new InputStreamReader( yahoo.openStream())); String inputLine; while ((inputLine = in.readLine()) != null) System.out.println(inputLine); in.close(); } } import java.net.*; import java.io.*;

import java.net.*; import java.io.*; public class URLConnectionReader { public static void main(String[] args) throws Exception { URL yahoo = new URL(" URLConnection yc = yahoo.openConnection(); BufferedReader in = new BufferedReader( new InputStreamReader( yc.getInputStream())); String inputLine; while ((inputLine = in.readLine()) != null) System.out.println(inputLine); in.close(); }

import java.io.*; import java.net.*; public class Reverse { public static void main(String[] args) throws Exception { if (args.length != 1) { System.err.println("Usage: java Reverse string_to_reverse"); System.exit(1); } String stringToReverse = URLEncoder.encode(args[0]); //encode spaces and nonalphanumerics for network processing URL url = new URL(" URLConnection connection = url.openConnection(); //will we have an output to URL connection connection.setDoOutput(true);

PrintWriter out = new PrintWriter(connection.getOutputStream()); out.println("string=" + stringToReverse); out.close(); BufferedReader in = new BufferedReader( new InputStreamReader( connection.getInputStream())); String inputLine; while ((inputLine = in.readLine()) != null) System.out.println(inputLine); in.close(); }