org.apache.jdo.impl.fostore
Class FOStoreOutput

java.lang.Object
  extended byorg.apache.jdo.impl.fostore.FOStoreOutput
All Implemented Interfaces:
java.io.DataOutput

class FOStoreOutput
extends java.lang.Object
implements java.io.DataOutput

Extend ByteArrayOutputStream so that we can get ahold of the byte array and current position, and can make sure we have enough space to write an object. We also allow getting and changing the current position. Also, implement DataOutput so that we can write easily to this output.

Author:
Dave Bristor

Nested Class Summary
(package private)  class FOStoreOutput.LocalByteArrayOutputStream
           
 
Field Summary
private  boolean closed
           
private  java.io.DataOutputStream dos
           
private static org.apache.jdo.util.I18NHelper msg
          I18N support.
private  FOStoreOutput.LocalByteArrayOutputStream stream
           
 
Constructor Summary
(package private) FOStoreOutput()
           
 
Method Summary
private  void assertNotClosed()
           
(package private)  int beginStash()
          Write a nonsense int value at the current position, and return that position for later use with endStash
 void close()
          Close the stream.
(package private)  void endStash(int value, int pos)
          Write the given value at the given position, and reset the position to what it was before the write occurred.
(package private)  byte[] getBuf()
          Provides no-copy access to the buffer.
(package private)  int getPos()
          Provides the stream's current writing position.
 void reset()
          Reset the stream.
(package private)  void setPos(int pos)
          Allows for setting the current writing position.
 void write(byte[] b)
           
 void write(byte[] b, int off, int len)
           
 void write(int b)
           
 void writeBoolean(boolean v)
           
 void writeByte(int v)
           
 void writeBytes(java.lang.String s)
           
 void writeChar(int v)
           
 void writeChars(java.lang.String s)
           
 void writeDouble(double v)
           
 void writeFloat(float v)
           
 void writeInt(int v)
           
 void writeLong(long v)
           
 void writeShort(int v)
           
 void writeUTF(java.lang.String str)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

closed

private boolean closed

stream

private final FOStoreOutput.LocalByteArrayOutputStream stream

dos

private final java.io.DataOutputStream dos

msg

private static final org.apache.jdo.util.I18NHelper msg
I18N support.

Constructor Detail

FOStoreOutput

FOStoreOutput()
Method Detail

close

public void close()
Close the stream. The stream can no longer be written.


reset

public void reset()
Reset the stream. Discard the current contents, and reset the count to 0 and the current position to 0. The current buffer is retained.


getBuf

byte[] getBuf()
Provides no-copy access to the buffer.

Returns:
The byte array representing this stream. Not a copy.

beginStash

int beginStash()
         throws java.io.IOException
Write a nonsense int value at the current position, and return that position for later use with endStash

Returns:
Position in this output for later use in writing a 'real' value.
Throws:
java.io.IOException
See Also:
endStash(int, int)

endStash

void endStash(int value,
              int pos)
        throws java.io.IOException
Write the given value at the given position, and reset the position to what it was before the write occurred.

Parameters:
value - Value to be written
pos - Position in this output at which value is to be written
Throws:
java.io.IOException
See Also:
beginStash()

getPos

int getPos()
Provides the stream's current writing position.

Returns:
The current writing position of the stream.

setPos

void setPos(int pos)
      throws java.io.IOException
Allows for setting the current writing position.

Parameters:
pos - Position at which future write operations will take place.
Throws:
java.io.IOException

write

public void write(byte[] b)
           throws java.io.IOException
Specified by:
write in interface java.io.DataOutput
Throws:
java.io.IOException

write

public void write(int b)
           throws java.io.IOException
Specified by:
write in interface java.io.DataOutput
Throws:
java.io.IOException

write

public void write(byte[] b,
                  int off,
                  int len)
           throws java.io.IOException
Specified by:
write in interface java.io.DataOutput
Throws:
java.io.IOException

writeBoolean

public void writeBoolean(boolean v)
                  throws java.io.IOException
Specified by:
writeBoolean in interface java.io.DataOutput
Throws:
java.io.IOException

writeByte

public void writeByte(int v)
               throws java.io.IOException
Specified by:
writeByte in interface java.io.DataOutput
Throws:
java.io.IOException

writeBytes

public void writeBytes(java.lang.String s)
                throws java.io.IOException
Specified by:
writeBytes in interface java.io.DataOutput
Throws:
java.io.IOException

writeChar

public void writeChar(int v)
               throws java.io.IOException
Specified by:
writeChar in interface java.io.DataOutput
Throws:
java.io.IOException

writeChars

public void writeChars(java.lang.String s)
                throws java.io.IOException
Specified by:
writeChars in interface java.io.DataOutput
Throws:
java.io.IOException

writeDouble

public void writeDouble(double v)
                 throws java.io.IOException
Specified by:
writeDouble in interface java.io.DataOutput
Throws:
java.io.IOException

writeFloat

public void writeFloat(float v)
                throws java.io.IOException
Specified by:
writeFloat in interface java.io.DataOutput
Throws:
java.io.IOException

writeInt

public void writeInt(int v)
              throws java.io.IOException
Specified by:
writeInt in interface java.io.DataOutput
Throws:
java.io.IOException

writeLong

public void writeLong(long v)
               throws java.io.IOException
Specified by:
writeLong in interface java.io.DataOutput
Throws:
java.io.IOException

writeShort

public void writeShort(int v)
                throws java.io.IOException
Specified by:
writeShort in interface java.io.DataOutput
Throws:
java.io.IOException

writeUTF

public void writeUTF(java.lang.String str)
              throws java.io.IOException
Specified by:
writeUTF in interface java.io.DataOutput
Throws:
java.io.IOException

assertNotClosed

private void assertNotClosed()