IM269 Coursework 3: Lib.java
// IM269 - Coursework 3: RMI Client/Server
// Semester A, 7th December 1998
// Eamonn Martin (BSc Computing)
// Student ID: 96/D59682
// efm001@unl.ac.uk
// RMI Hit Counter Library
package hitter;
import java.io.*;
// General-purpose static methods
public class Lib {
// Read a line from an input stream (no newline appended)
public static String readLine(InputStream i) throws IOException {
String s = "";
for (int c; (c = i.read())!=-1; s += (char)c)
if ((char)c=='\n') return s; // Possibly an empty line
return (s.length() > 0) ? s : null; // Null if nothing read
}
// Write a line to an output stream (newline appended)
public static void writeLine(String s, OutputStream o) throws IOException {
for (int c=0; c < s.length(); ++c) o.write(s.charAt(c));
o.write('\n');
}
// Return the integer value of a string (or 0)
public static int intValue(String s) {
int c = 0;
try { c = (Integer.decode(s)).intValue(); }
catch (NumberFormatException e) {}
return c;
}
}
Go To: IM269: Programming The Internet