Class TSByteArrIO

java.lang.Object
  extended by java.io.OutputStream
      extended by TSByteArrIO
All Implemented Interfaces:
java.io.Closeable, java.io.Flushable, java.io.Serializable

 class TSByteArrIO
extends java.io.OutputStream
implements java.io.Serializable

.

======================================================================
 Class TSByteArrIO -- dynamic 'ByteArray'-Buffer for input and output.
 Although this class uses write/read-methods to fill/recover the data
   within the buffer, it really uses copy operations to do the job.
 This class also contains some (static) methods to change
     buffer-contents.
 Attention: This class was created using source-file of class
            'ByteArrayOutputStream'.

 Method-definition:
   'write' means: from source to BUFFER
            add new data at position 'count' within buffer
   'read'  means: from BUFFER to destination
            copy data, beginning at position 'cpos'/'0', to target
 But...
   'writeTo'  means: from BUFFER to file (Outputstream/File)
               copy data, beginning at current position ('cpos')
   'readFrom' means: from file (Inputstream/File) to Buffer
               copy data, append it at end of buffer
 ##TSByteArrIO (Eyecatcher)
======================================================================
 


Field Summary
private  byte[] buffer
           
private  int count
           
private  int cPos
           
protected static java.lang.String IdStr
           
private  int mark
           
protected static int ReadLoop
           
 
Constructor Summary
protected TSByteArrIO()
          .
protected TSByteArrIO(int bl)
          .
 
Method Summary
 int available()
          .
private  void chgBuffer(int len)
          .
protected  byte[] getBytes(int len)
          .
protected  byte[] getBytes(int len, int pos)
          .
protected  long getInt(int len)
          .
protected static long getInt(int len, byte[] src, int ofs)
          .
protected  long getInt(int len, int pos)
          .
protected  java.lang.String getString(int len)
          .
protected  java.lang.String putByte(int val, int pos)
          .
protected  int putBytes(byte[] src)
          .
protected  java.lang.String putInt(long val, int len)
          .
protected  java.lang.String putInt(long val, int len, int pos)
          .
protected  java.lang.String putString(java.lang.String s, boolean nol)
          .
protected  java.lang.String putString(java.lang.String s, int pos)
          .
 int read()
          .
 int readFrom(java.io.InputStream in, int len)
          .
protected  void reInit()
          .
protected  boolean reset(boolean clr)
          .
protected  int size()
          .
protected  long skip(long n)
          .
protected  java.lang.String toStr()
          .
 java.lang.String toString()
          .
protected  int unRead(int len)
          .
 void write(int cByte)
          .
 int write(java.lang.String s)
          .
 java.lang.String writeTo(java.io.OutputStream out)
          .
protected  java.lang.String writeTo(java.io.OutputStream out, int len)
          .
protected  boolean XXXmark(boolean clr)
          .
protected static java.lang.String XXXputInt(long val, int len, byte[] dst, int pos)
          .
protected  int XXXread(byte[] tgt, int len)
          .
protected  java.lang.String XXXreadFrom(java.io.File dat)
          .
 void XXXrewind()
          .
protected  boolean XXXsqueeze(int env)
          .
protected  java.lang.String XXXwriteTo(java.io.File dat)
          .
 
Methods inherited from class java.io.OutputStream
close, flush, write, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

IdStr

protected static final java.lang.String IdStr
See Also:
Constant Field Values

ReadLoop

protected static int ReadLoop

count

private int count

cPos

private int cPos

mark

private int mark

buffer

private volatile byte[] buffer
Constructor Detail

TSByteArrIO

protected TSByteArrIO()
.
=====================================================================
 Constructor: (1) Create Default-Entry
=====================================================================
  


TSByteArrIO

protected TSByteArrIO(int bl)
.
=====================================================================
 Constructor: (2) Create Standard-Entry
=====================================================================
  

Method Detail

available

public final int available()
.
=====================================================================
 Method "available"
 Returns the number of bytes that can be read from this buffer
   without blocking.
 ##available.TSByteArrIO (Eyecatcher)
=====================================================================
  


chgBuffer

private final void chgBuffer(int len)
.
=====================================================================
 Method "chgBuffer"
 Establish new/larger internal byte-buffer.
 ##chgBuffer.TSByteArrIO (Eyecatcher)
=====================================================================
  


getBytes

protected final byte[] getBytes(int len)
.
=====================================================================
 Method "getBytes"
 Get Sub-Array of current buffer and return it.
 Offset is taken from current input-position, which is incremented.
 ##getBytes.TSByteArrIO (Eyecatcher)
=====================================================================
  


getBytes

protected final byte[] getBytes(int len,
                                int pos)
.
=====================================================================
 Method "getBytes" (2. version)
 Get Sub-Array of current buffer and return it.
 Attention: Input-position is NOT modified.
 ##getBytes.TSByteArrIO (Eyecatcher)
=====================================================================
  


getInt

protected final long getInt(int len,
                            int pos)
.
=====================================================================
 Method "getInt"
 Get Integer-value from Byte-Array as 'long' assuming LE-Format
   (Little Endian).
 Method terminates program, if error occurred.
 Attention: Input-position is NOT modified.
 ##getInt.TSByteArrIO (Eyecatcher)
=====================================================================
  


getInt

protected final long getInt(int len)
.
=====================================================================
 Method "getInt" (2. version)
 Get Integer-value from Byte-Array as 'long' assuming LE-Format
   (Little Endian).
 Offset is taken from current input-position, which is incremented.
 ##getInt.TSByteArrIO (Eyecatcher)
=====================================================================
  


getInt

protected static final long getInt(int len,
                                   byte[] src,
                                   int ofs)
.
=====================================================================
 Method "getInt" (static version)
 Get back Integer-value from Byte-Array as 'long' assuming LE-Format
   (Little Endian).
 Method terminates program, if error occurred.
 ##getInt.TSByteArrIO (Eyecatcher)
=====================================================================
  


getString

protected final java.lang.String getString(int len)
.
=====================================================================
 Method "getString"
 Read Unicode-String from byte-array-buffer.
 If an error is found, 'null' is returned.
 ##getString.TSByteArrIO (Eyecatcher)
=====================================================================
  


XXXmark

protected final boolean XXXmark(boolean clr)
.
=====================================================================
 Method "mark"
 Handle control of position -- mark it.
 Returns 'false', if NO position was already marked.
 Attention: This method is copied from (and requested by) source of
            class 'ByteArrayInputStream'/'ByteArrayOutputStream'.
 --- Method is NOT referenced until now. (marked by 'XXX...') ---
 ##mark.TSByteArrIO (Eyecatcher)
=====================================================================
  


putByte

protected final java.lang.String putByte(int val,
                                         int pos)
.
=====================================================================
 Method "putByte"
 Write/Modify byte to/within output-buffer.
 Returns error-message if request fails ('null' if no error)
 Attention: method CANNOT add new bytes to buffer. It is only used
   to modify already written bytes. If a byte must be ADDED to the
   buffer, method 'write(byte)' should be used.
 This method equals 'putInt(val,1,pos)'.
 ##putByte.TSByteArrIO (Eyecatcher)
=====================================================================
  


putBytes

protected final int putBytes(byte[] src)
.
=====================================================================
 Method "putBytes"
 Add a Sub-Array of Bytes to current buffer and return length.
 Offset is taken from current output-position, which is incremented.
 ##putBytes.TSByteArrIO (Eyecatcher)
=====================================================================
  


putInt

protected final java.lang.String putInt(long val,
                                        int len)
.
=====================================================================
 Method "putInt"
 Write/Add Integer/unsigned Integer to output-buffer using LE-Format.
 New data is (completely) added to output-buffer.
 Returns error-message if request fails ('null' if no error).
 ##putInt.TSByteArrIO (Eyecatcher)
=====================================================================
  


putInt

protected final java.lang.String putInt(long val,
                                        int len,
                                        int pos)
.
=====================================================================
 Method "putInt" (2. version)
 Write/Modify Integer/unsigned Integer to/within output-buffer using
   LE-Format(little endian)
 Returns error-message if request fails ('null' if no error)

 New data is added to the buffer, if the target-field, which should
   be replaced, reaches beyond the border of valid data. However,
   the target field must start within (at end of) valid data.
 ##putInt.TSByteArrIO (Eyecatcher)
=====================================================================
  


XXXputInt

protected static final java.lang.String XXXputInt(long val,
                                                  int len,
                                                  byte[] dst,
                                                  int pos)
.
=====================================================================
 Method "putInt" (static version)
 Write/Modify Integer/unsigned Integer to/within target-array using
   LE-Format(little endian)
 Returns error-message if request fails ('null' if no error).
 --- Method is NOT referenced until now. (marked by 'XXX...') ---
 ##putInt.TSByteArrIO (Eyecatcher)
=====================================================================
  


putString

protected final java.lang.String putString(java.lang.String s,
                                           boolean nol)
.
=====================================================================
 Method "putString"
 Convert(add) Unicode-String to output-buffer ('Label' or data)
 Returns error-message if request fails ('null' if no error)
 If 'data' is written, a length-field (short) is inserted before
   the Unicode-String.
 ##putString.TSByteArrIO (Eyecatcher)
=====================================================================
  


putString

protected final java.lang.String putString(java.lang.String s,
                                           int pos)
.
=====================================================================
 Method "putString" (2. version)
 Convert(replace) Unicode-String within output-buffer.
 Returns error-message if request fails ('null' if no error)

 New data is added to the buffer, if the target-field, which should
   be replaced, reaches beyond the border of valid data. However,
   the target field must start within (at end of) valid data.
 ##putString.TSByteArrIO (Eyecatcher)
=====================================================================
  


read

public int read()
.
=====================================================================
 Method "read"
 Read byte (copy) from buffer and locate it into an integer.
 This method is requested by abstract class 'InputStream'.
 ##read.TSByteArrIO (Eyecatcher)
=====================================================================
  


XXXread

protected final int XXXread(byte[] tgt,
                            int len)
.
=====================================================================
 Method "read"
 Read/Copy part of the buffer to target-area due to specified length.
 --- Method is NOT referenced until now. (marked by 'XXX...') ---
 ##read.TSByteArrIO (Eyecatcher)
=====================================================================
  


readFrom

public int readFrom(java.io.InputStream in,
                    int len)
             throws java.io.IOException
.
=====================================================================
 Method "readFrom"
 Read data from an inputstream and copy them to the byte-array-buffer
  appending them.
 If needed, the size of the buffer is expanded.
 ##readFrom.TSByteArrIO (Eyecatcher)
=====================================================================
  

Throws:
java.io.IOException

XXXreadFrom

protected final java.lang.String XXXreadFrom(java.io.File dat)
.
=====================================================================
 Method "readFrom"
 Read complete sourcefile and copy it to byte-array-buffer
   appending it
 Returns error-message if request fails ('null' if no error).
 --- Method is NOT referenced until now. (marked by 'XXX...') ---
 ##readFrom.TSByteArrIO (Eyecatcher)
=====================================================================
  


reInit

protected void reInit()
.
=====================================================================
 Method "reInit"
 Clear buffer and reset any pointer.
 Attention: the current buffer is neither changed nor deleted.
 ##reInit.TSByteArrIO (Eyecatcher)
=====================================================================
  


reset

protected final boolean reset(boolean clr)
.
=====================================================================
 Method "reset"
 Handle control of position. (reset position to saved value)
 Returns 'false', if function was successful.
 Attention: This method is copied from (and requested by) source of
            class 'ByteArrayInputStream'/'ByteArrayOutputStream'.
 ##reset.TSByteArrIO (Eyecatcher)
=====================================================================
  


XXXrewind

public void XXXrewind()
.
=====================================================================
 Method "rewind"
 Reset current input-position to start of data-buffer.
 Attention: If 'squeeze' has been used, some data within the
            input-buffer may already be lost.
 --- Method is NOT referenced until now. (marked by 'XXX...') ---
 ##rewind.TSByteArrIO (Eyecatcher)
=====================================================================
  


size

protected final int size()
.
=====================================================================
 Method "size"
 Returns the current size of the valid data within the buffer.
 ##size.TSByteArrIO (Eyecatcher)
=====================================================================
  


skip

protected final long skip(long n)
.
=====================================================================
 Method "skip"
 Skips n bytes of input from this byte-array. Fewer
 bytes might be skipped if the end of the buffer is reached.
 The actual number k
 of bytes to be skipped is equal to the smaller
 of n and  count-pos.
 The value k is returned.
 Attention: This method is copied from (and requested by) source of
            class 'ByteArrayInputStream'/'ByteArrayOutputStream'.
 ##skip.TSByteArrIO (Eyecatcher)
=====================================================================
  


XXXsqueeze

protected final boolean XXXsqueeze(int env)
.
=====================================================================
 Method "squeeze"
 Removes already read elements from the buffer and compacts it.
 Attention: This method must not be called, if this class is used
            as a write-buffer or data may be lost.
 --- Method is NOT referenced until now. (marked by 'XXX...') ---
 ##squeeze.TSByteArrIO (Eyecatcher)
=====================================================================
  


unRead

protected final int unRead(int len)
.
=====================================================================
 Method "unRead"
 Free already read data from the buffer and make them available for
   read again.
 ##unRead.TSByteArrIO (Eyecatcher)
=====================================================================
  


write

public void write(int cByte)
.
=====================================================================
 Method "write"
 Write byte (copy), which is located within an integer, into buffer
   and add it to the already buffered data.
 If needed, the size of the buffer is expanded.
 This method is requested by abstract class 'OutputStream'.
 ##write.TSByteArrIO (Eyecatcher)
=====================================================================
  

Specified by:
write in class java.io.OutputStream

write

public int write(java.lang.String s)
.
=====================================================================
 Method "write"
 Write/Copy data from a string-value into the byte-array-buffer
   and append it.
 If needed, the size of the buffer is expanded.
 ##write.TSByteArrIO (Eyecatcher)
=====================================================================
  


writeTo

public final java.lang.String writeTo(java.io.OutputStream out)
.
=====================================================================
 Method "writeTo"
 Writes the (remaining) contents of this byte-array-buffer to
 the specified output stream argument, as if by calling the output
 stream's write method using
 out.write(buffer,cPos,count-cPos).
 Attention: This method is copied from source of class
            'ByteArrayOutputStream'. However, it is still modified
            and returns an error-message or 'null'. It DO NOT
            throws an error-condition.
 ##writeTo.TSByteArrIO (Eyecatcher)
=====================================================================
  


writeTo

protected final java.lang.String writeTo(java.io.OutputStream out,
                                         int len)
.
=====================================================================
 Method "writeTo"
 Copy part of this byte array buffer to the specified outputstream
   argument, as if by calling the output stream's write method
   using out.write(buffer,cPos,len).
 ##writeTo.TSByteArrIO (Eyecatcher)
=====================================================================
  


XXXwriteTo

protected final java.lang.String XXXwriteTo(java.io.File dat)
.
=====================================================================
 Method "writeTo"
 Read complete buffer and write it to targetfile.
 Returns error-message if request fails ('null' if no error).
 --- Method is NOT referenced until now. (marked by 'XXX...') ---
 ##writeTo.TSByteArrIO (Eyecatcher)
=====================================================================
  


toString

public final java.lang.String toString()
.
=====================================================================
 Method "toString"
 Returns the current value of the IO-buffer.
 ##toString.TSByteArrIO (Eyecatcher)
=====================================================================
  

Overrides:
toString in class java.lang.Object

toStr

protected final java.lang.String toStr()
.
=====================================================================
 Method "toStr"
 Build an String-representation of all values of this class.
 ##toStr.TSByteArrIO (Eyecatcher)
=====================================================================