gnu.x11
Class RequestOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by java.io.FilterOutputStream
          extended by gnu.x11.RequestOutputStream
All Implemented Interfaces:
java.io.Closeable, java.io.Flushable

public class RequestOutputStream
extends java.io.FilterOutputStream

Used to create and manage requests to the X server.

Author:
Roman Kennke (roman@kennke.org)

Nested Class Summary
static class RequestOutputStream.SendMode
           
 
Field Summary
 byte[] buffer
          The request buffer.
 int index
          The current write index in the buffer.
 RequestObject request_object
          The request object.
 int seq_number
           
 
Fields inherited from class java.io.FilterOutputStream
out
 
Method Summary
 void begin_request(int opcode, int second_field, int request_length)
          Begins a new request.
 int current_opcode()
          Returns the opcode of the current request.
 boolean fits(int num_bytes)
          Determines if the buffer has room for the specified number of bytes.
 void flush()
          Flushes all the pending request data to the underlying stream.
 int get_int32(int index)
          Returns the INT32 value at the specified index in the buffer inside the current request.
 void increase_length(int i)
           
 int opcode()
          Returns the opcode of the current request or -1 if there is no request pending.
static int pad(int n)
          Returns the number of bytes that are needed to pad n bytes to fill a multiple of four.
 void send()
          Sends the current request to the underlying stream, without necessarily flushing the stream.
 int set_buffer_size(int size)
          Changes the buffer size.
 void set_index(int i)
          Sets the write index to i.
 long skip(long n)
           
 void update_length()
          Updates the length field of the request to reflect the current length.
 void write_bool(boolean b)
           
 void write_bytes(byte[] b)
           
 void write_double(double d)
           
 void write_float(float f)
           
 void write_int16(int v)
          Writes an INT16 value to the stream.
 void write_int32(int v)
          Writes an INT32 value to the stream.
 void write_int8(int v)
          Writes an INT8 value to the stream.
 void write_pad(int n)
          Skips p unused bytes, where p is pad(n). pad(n) is the number of bytes that are needed to fill a block multiple of 4.
 void write_string16(java.lang.String s)
          Writes a STRING16 to the stream.
 void write_string8(java.lang.String s)
          Writes a STRING8 value to the stream.
 void write(byte[] b)
          Writes the specified data to the stream.
 void write(byte[] b, int offs, int len)
          Writes the specified data to the stream.
 void write(int v)
          Writes one byte to the stream.
 
Methods inherited from class java.io.FilterOutputStream
close
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

buffer

public byte[] buffer
The request buffer. It always holds the current request. This can be accessed directly for modifications, like when the current request can be aggregated.


index

public int index
The current write index in the buffer. This always points to the next free location inside the buffer.


request_object

public RequestObject request_object
The request object. This is written to the stream when flushing.


seq_number

public int seq_number
Method Detail

set_buffer_size

public int set_buffer_size(int size)
Changes the buffer size.

Parameters:
size - the new buffer size
Returns:
the actually used buffer size

begin_request

public void begin_request(int opcode,
                          int second_field,
                          int request_length)
Begins a new request. This flushes all pending request data.

Parameters:
opcode - the opcode for the request
second_field - the second field for the request
request_length - the length of the request

send

public void send()
Sends the current request to the underlying stream, without necessarily flushing the stream.


current_opcode

public int current_opcode()
Returns the opcode of the current request.

Returns:
the opcode of the current request

set_index

public void set_index(int i)
Sets the write index to i.

Parameters:
i - the write index to set

write

public void write(int v)
           throws java.io.IOException
Writes one byte to the stream.

Overrides:
write in class java.io.FilterOutputStream
Parameters:
v -
Throws:
java.io.IOException

write

public void write(byte[] b)
Writes the specified data to the stream.

Overrides:
write in class java.io.FilterOutputStream
Parameters:
b - the data to write

write

public void write(byte[] b,
                  int offs,
                  int len)
Writes the specified data to the stream.

Overrides:
write in class java.io.FilterOutputStream
Parameters:
b - the data to write
offs - the start offset in the data array
len - the length of the data to write

flush

public void flush()
Flushes all the pending request data to the underlying stream.

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

write_bool

public void write_bool(boolean b)

write_int8

public void write_int8(int v)
Writes an INT8 value to the stream.

Parameters:
v - the value to write

write_int16

public void write_int16(int v)
Writes an INT16 value to the stream.

Parameters:
v - the value to write

write_int32

public void write_int32(int v)
Writes an INT32 value to the stream.

Parameters:
v - the value to write

get_int32

public int get_int32(int index)
Returns the INT32 value at the specified index in the buffer inside the current request.

Parameters:
index - the index
Returns:
the INT32 value at the specified index

write_float

public void write_float(float f)

write_double

public void write_double(double d)

write_string8

public void write_string8(java.lang.String s)
Writes a STRING8 value to the stream.

Parameters:
s - the string to write

write_string16

public void write_string16(java.lang.String s)
Writes a STRING16 to the stream.

Parameters:
s - the string to write

write_bytes

public void write_bytes(byte[] b)

skip

public long skip(long n)

write_pad

public void write_pad(int n)
Skips p unused bytes, where p is pad(n). pad(n) is the number of bytes that are needed to fill a block multiple of 4.

Parameters:
n - the number to be padded

pad

public static int pad(int n)
Returns the number of bytes that are needed to pad n bytes to fill a multiple of four.

Parameters:
n - the number of bytes the pad
Returns:
the number of pad bytes needed

opcode

public int opcode()
Returns the opcode of the current request or -1 if there is no request pending.

Returns:
the opcode of the current request or -1 if there is no request pending

fits

public boolean fits(int num_bytes)
Determines if the buffer has room for the specified number of bytes.

Parameters:
num_bytes - the number of bytes
Returns:
true if the buffer has space for the specified number of bytes, false otherwise

update_length

public void update_length()
Updates the length field of the request to reflect the current length.


increase_length

public void increase_length(int i)