Further progress. Heeya!
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
//
|
||||
// $Id: FrameTest.java,v 1.1 2001/05/22 21:51:29 mdb Exp $
|
||||
|
||||
package com.samskivert.cocktail.cher.io.test;
|
||||
|
||||
import java.io.*;
|
||||
import com.samskivert.cocktail.cher.io.*;
|
||||
|
||||
public class FrameTest
|
||||
{
|
||||
public static void writeFrames (OutputStream out)
|
||||
throws IOException
|
||||
{
|
||||
FramingOutputStream fout = new FramingOutputStream();
|
||||
DataOutputStream dout = new DataOutputStream(fout);
|
||||
|
||||
// create a few frames and write them to the output stream
|
||||
dout.writeUTF("This is a test.");
|
||||
dout.writeUTF("This is only a test.");
|
||||
dout.writeUTF("If this were not a test, there would be " +
|
||||
"meaningful data in this frame and someone " +
|
||||
"would probably be enjoying themselves.");
|
||||
fout.writeFrameAndReset(out);
|
||||
|
||||
dout.writeUTF("Now is the time for all good men to come to the " +
|
||||
"aid of their country.");
|
||||
dout.writeUTF("Every good boy deserves fudge.");
|
||||
dout.writeUTF("The quick brown fox jumped over the lazy cow.");
|
||||
fout.writeFrameAndReset(out);
|
||||
|
||||
dout.writeUTF("Third time is the charm.");
|
||||
fout.writeFrameAndReset(out);
|
||||
}
|
||||
|
||||
public static void readFrames (InputStream in)
|
||||
throws IOException
|
||||
{
|
||||
FramedInputStream fin = new FramedInputStream();
|
||||
DataInputStream din = new DataInputStream(fin);
|
||||
|
||||
// read the first frame
|
||||
fin.readFrame(in);
|
||||
System.out.println(din.readUTF());
|
||||
System.out.println(din.readUTF());
|
||||
System.out.println(din.readUTF());
|
||||
System.out.println("This should be -1: " + fin.read());
|
||||
|
||||
// read the second frame
|
||||
fin.readFrame(in);
|
||||
System.out.println(din.readUTF());
|
||||
System.out.println(din.readUTF());
|
||||
System.out.println(din.readUTF());
|
||||
System.out.println("This should be -1: " + fin.read());
|
||||
|
||||
// read the third frame
|
||||
fin.readFrame(in);
|
||||
System.out.println(din.readUTF());
|
||||
System.out.println("This should be -1: " + fin.read());
|
||||
}
|
||||
|
||||
public static void main (String[] args)
|
||||
{
|
||||
try {
|
||||
ByteArrayOutputStream bout = new ByteArrayOutputStream();
|
||||
writeFrames(bout);
|
||||
|
||||
byte[] data = bout.toByteArray();
|
||||
ByteArrayInputStream bin = new ByteArrayInputStream(data);
|
||||
readFrames(bin);
|
||||
|
||||
} catch (IOException ioe) {
|
||||
ioe.printStackTrace(System.err);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user