squint
Class DataOutputChannel

java.lang.Object
  extended by java.io.OutputStream
      extended by squint.DataOutputChannel
All Implemented Interfaces:
java.io.Closeable, java.io.DataOutput, java.io.Flushable

public class DataOutputChannel
extends java.io.OutputStream
implements java.io.DataOutput

A DataOutputChannel is a stream designed to provide mechanisms to store or transmit data using distinct binary encoding schemes for various types of data (i.e. not just ASCII or UniCode). Objects of this class are used by the TCPConnection class for the "out" stream associated with a TCPConnection. It is also possible to create a DataOutputStream that provides a means to place data in a disk file. The interface to a DataOutputChannel is desiged to be very similar to the interface to a standard DataOutputStream, except that the methods of this class never throw checked exceptions. This makes it possible to use this class without inserting try/catch constructs around code that uses the class.


Constructor Summary
DataOutputChannel(java.io.File f)
          Create a DataOutputStream to store data within a file given a File object describing the desired file.
DataOutputChannel(java.io.OutputStream dest)
          Create a DataOutputStream given an OutputStream to use to actually perform data transfer.
DataOutputChannel(java.lang.String fileName)
          Create a DataOutputStream given a pathname within the local file system that identifies the desired file.
 
Method Summary
 void close()
          Close the stream.
 void flush()
          Force any data pending transmission to be send through the network
 void write(byte[] buffer)
          Sends all the bytes in array buffer through the channel.
 void write(byte[] data, int offset, int len)
          Send part of a sequence of bytes of data through the channel starting at a particular offset within the sequence.
 void write(int data)
          Sends the single byte of data found in the low order eight bits of the parameter value through the channel.
 void writeBoolean(boolean data)
          Send a single boolean value (1 byte) through the channel.
 void writeByte(int data)
          Sends the single byte of data found in the low order eight bits of the parameter value through the channel.
 void writeBytes(java.lang.String data)
          Send all of the characters in a String through the connection as a sequence of bytes.
 void writeChar(int data)
          Send a single character of data, which is comprised of two bytes, through the channel.
 void writeChars(java.lang.String data)
          Send every character in the string s, through the channel, in order, two bytes per character.
 void writeDouble(double data)
          Send a double value, which is comprised of eight bytes, through the channel.
 void writeFloat(float data)
          Send a float value, which is comprised of four bytes, through the channel.
 void writeInt(int data)
          Send an int value, which is comprised of four bytes, through the channel.
 void writeLong(long data)
          Send a long value, which is comprised of eight bytes, through the channel.
 void writeShort(int data)
          Send a single 2 byte integer value (short) through the channel.
 void writeUTF(java.lang.String data)
          Send two bytes of length information through the channel, followed by the modified UTF-8 representation of every character in the parameter string.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DataOutputChannel

public DataOutputChannel(java.io.File f)
Create a DataOutputStream to store data within a file given a File object describing the desired file.

Parameters:
f - the file to be written.

DataOutputChannel

public DataOutputChannel(java.lang.String fileName)
Create a DataOutputStream given a pathname within the local file system that identifies the desired file. Since the file name provided must be a complete path, in most situations the programmer will want to use a JFileChooser or similar mechanism to deteremine the full path name associated with a file selected by the user.

Parameters:
fileName - the full path name of the file to be written through the stream.

DataOutputChannel

public DataOutputChannel(java.io.OutputStream dest)
Create a DataOutputStream given an OutputStream to use to actually perform data transfer. This constructor is used to create the "out" streams associated with TCPConnections. While it can be use in other contexts, it is more likely that novice programmers will use one of the other constructors provided with this class.

Parameters:
dest - the underlying OutputStream through which the data will pass.
Method Detail

flush

public void flush()
Force any data pending transmission to be send through the network

Specified by:
flush in interface java.io.Flushable
Overrides:
flush in class java.io.OutputStream

close

public void close()
Close the stream.

Specified by:
close in interface java.io.Closeable
Overrides:
close in class java.io.OutputStream

writeBytes

public void writeBytes(java.lang.String data)
Send all of the characters in a String through the connection as a sequence of bytes.

Specified by:
writeBytes in interface java.io.DataOutput
Parameters:
data - the string of values to be sent

writeChars

public void writeChars(java.lang.String data)
Send every character in the string s, through the channel, in order, two bytes per character.

Specified by:
writeChars in interface java.io.DataOutput
Parameters:
data - the value to be sent

write

public void write(int data)
Sends the single byte of data found in the low order eight bits of the parameter value through the channel.

Specified by:
write in interface java.io.DataOutput
Specified by:
write in class java.io.OutputStream
Parameters:
data - the value to be sent

writeByte

public void writeByte(int data)
Sends the single byte of data found in the low order eight bits of the parameter value through the channel.

Specified by:
writeByte in interface java.io.DataOutput
Parameters:
data - the value to be sent

writeChar

public void writeChar(int data)
Send a single character of data, which is comprised of two bytes, through the channel.

Specified by:
writeChar in interface java.io.DataOutput
Parameters:
data - the value to be sent

writeShort

public void writeShort(int data)
Send a single 2 byte integer value (short) through the channel.

Specified by:
writeShort in interface java.io.DataOutput
Parameters:
data - the value to be sent

writeInt

public void writeInt(int data)
Send an int value, which is comprised of four bytes, through the channel.

Specified by:
writeInt in interface java.io.DataOutput
Parameters:
data - the value to be sent

writeLong

public void writeLong(long data)
Send a long value, which is comprised of eight bytes, through the channel.

Specified by:
writeLong in interface java.io.DataOutput
Parameters:
data - the value to be sent

writeFloat

public void writeFloat(float data)
Send a float value, which is comprised of four bytes, through the channel.

Specified by:
writeFloat in interface java.io.DataOutput
Parameters:
data - the value to be sent

writeDouble

public void writeDouble(double data)
Send a double value, which is comprised of eight bytes, through the channel.

Specified by:
writeDouble in interface java.io.DataOutput
Parameters:
data - the value to be sent

writeBoolean

public void writeBoolean(boolean data)
Send a single boolean value (1 byte) through the channel.

Specified by:
writeBoolean in interface java.io.DataOutput
Parameters:
data - the value to be sent

writeUTF

public void writeUTF(java.lang.String data)
Send two bytes of length information through the channel, followed by the modified UTF-8 representation of every character in the parameter string.

Specified by:
writeUTF in interface java.io.DataOutput
Parameters:
data - the string to be sent

write

public void write(byte[] buffer)
Sends all the bytes in array buffer through the channel.

Specified by:
write in interface java.io.DataOutput
Overrides:
write in class java.io.OutputStream
Parameters:
buffer - array of bytes to be send

write

public void write(byte[] data,
                  int offset,
                  int len)
Send part of a sequence of bytes of data through the channel starting at a particular offset within the sequence.

Specified by:
write in interface java.io.DataOutput
Overrides:
write in class java.io.OutputStream
Parameters:
data - the sequence of bytes
offset - the starting position within the sequence
len - the number of bytes to send