org.wings.io
Interface Device

All Known Implementing Classes:
CachingDevice, CountingDeviceDelegator, DeviceBuffer, GZIPCompressingDevice, NullDevice, OutputStreamDevice, ServletDevice, StringBuilderDevice

public interface Device

A general interface for a Output-Device. A Device is the destination, where the HTML-code is written to. This is like the 'Graphics' - device in GUI applications.

All the printing methods return the Device itself, to allow simple chaining:


    someDevice.print("foo").print("bar");
 

Usually, the underlying data sink of a Device would be some OutputStream, as it finally writes through some socket to the client browser. The Device, however, offers basically two methods for writing to the output: with print() and write() like methods. The print() like methods get character input that has to be converted to a byte-stream before it actually can be written to the underlying OutputStream, while the write() like methods directly handle arrays of bytes to do this. So if possible, try to always use the write() methods, if you can pre-calculate the byte-representation of the output (if you have some static Strings, for instance, consider using String.getBytes()).

Author:
Henner Zeller

Method Summary
 void close()
          close the Device.
 void flush()
          Flush this Device.
 boolean isSizePreserving()
          returns, whether this the size of data put into this device is the same as comes out.
 Device print(char c)
          Print a character.
 Device print(char[] c)
          Print a character array.
 Device print(char[] c, int start, int len)
          Print len characters from the specified char array starting at offset off to this Device.
 Device print(int i)
          Print an integer.
 Device print(Object o)
          Print any Object
 Device print(String s)
          Print a String.
 Device write(byte[] b)
          Writes b.length bytes from the specified byte array to this output stream.
 Device write(byte[] b, int off, int len)
          Writes len bytes from the specified byte array starting at offset off to this Device.
 Device write(int c)
          Writes the specified byte to this data output stream.
 

Method Detail

flush

void flush()
           throws IOException
Flush this Device.

Throws:
IOException

close

void close()
           throws IOException
close the Device.

Throws:
IOException

isSizePreserving

boolean isSizePreserving()
returns, whether this the size of data put into this device is the same as comes out. This is necessary to know if we want to send the content size: if we know the content size, but this device changes the size, we must not send it.

Returns:
'true', if this device leaves the size of the data going through it, untouched. This is usually true.

print

Device print(char c)
             throws IOException
Print a character.

Throws:
IOException

print

Device print(char[] c)
             throws IOException
Print a character array.

Throws:
IOException

print

Device print(char[] c,
             int start,
             int len)
             throws IOException
Print len characters from the specified char array starting at offset off to this Device.

Throws:
IOException

print

Device print(String s)
             throws IOException
Print a String.

Throws:
IOException

print

Device print(int i)
             throws IOException
Print an integer.

Throws:
IOException

print

Device print(Object o)
             throws IOException
Print any Object

Throws:
IOException

write

Device write(int c)
             throws IOException
Writes the specified byte to this data output stream.

Throws:
IOException

write

Device write(byte[] b)
             throws IOException
Writes b.length bytes from the specified byte array to this output stream.

Throws:
IOException

write

Device write(byte[] b,
             int off,
             int len)
             throws IOException
Writes len bytes from the specified byte array starting at offset off to this Device.

Throws:
IOException


wingS Swings ;-)