net.argius.stu.io
クラス BinaryStream

java.lang.Object
  拡張net.argius.stu.io.BinaryStream

public final class BinaryStream
extends Object

バイナリストリームを表現するクラスです。

機能的には、java.io.InputStreamjava.io.OutputStreamの 両方を実装しており、両方のストリームが同じバイト配列バッファを共有する構造を提供しています。 また、カーソルによるランダムアクセスも可能となっています。


コンストラクタの概要
BinaryStream()
          バイナリストリームを生成します。
BinaryStream(int size)
          バイナリストリームを生成します。
 
メソッドの概要
 InputStream getInputStream()
          入力ストリームを取得します。
 OutputStream getOutputStream()
          出力ストリームを取得します。
 int getPosition()
          現在のカーソル位置を返します。
 int length()
          ストリームのデータサイズを返します。
 byte read()
          ストリームから現在カーソル位置のデータを読み込みます。
 byte read(long index)
          ストリームから指定した位置のデータを読み込みます。
 void setAbsolutePosition(long absolutePosition)
          カーソル位置を指定した位置に移動します。
 void setRelativePosition(int relativePosition)
          カーソル位置を現在の相対位置に移動します。
 String toString()
          ストリームの文字列表現を返します。
 void trancate(long length)
          このストリームのサイズを指定した長さに切り詰めます。
 void write(byte b)
          ストリームにデータを書き込みます。
 
クラス java.lang.Object から継承したメソッド
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

コンストラクタの詳細

BinaryStream

public BinaryStream()
バイナリストリームを生成します。


BinaryStream

public BinaryStream(int size)
バイナリストリームを生成します。

パラメータ:
size - バッファサイズ
メソッドの詳細

length

public int length()
ストリームのデータサイズを返します。

戻り値:
データサイズ(バイト数)

read

public byte read(long index)
          throws ArrayIndexOutOfBoundsException
ストリームから指定した位置のデータを読み込みます。

パラメータ:
index - 指定位置
戻り値:
指定位置の1バイト
例外:
ArrayIndexOutOfBoundsException - 指定位置がバッファの外を指している場合

read

public byte read()
          throws ArrayIndexOutOfBoundsException
ストリームから現在カーソル位置のデータを読み込みます。

戻り値:
指定位置の1バイト
例外:
ArrayIndexOutOfBoundsException - 指定位置がバッファの外を指している場合

write

public void write(byte b)
ストリームにデータを書き込みます。

パラメータ:
b - データ

trancate

public void trancate(long length)
このストリームのサイズを指定した長さに切り詰めます。

パラメータ:
length - 切り詰める長さ

getPosition

public int getPosition()
現在のカーソル位置を返します。

戻り値:
カーソル位置

setAbsolutePosition

public void setAbsolutePosition(long absolutePosition)
カーソル位置を指定した位置に移動します。

パラメータ:
absolutePosition - 絶対位置
例外:
ArrayIndexOutOfBoundsException - 指定位置がバッファの外を指している場合

setRelativePosition

public void setRelativePosition(int relativePosition)
カーソル位置を現在の相対位置に移動します。

パラメータ:
relativePosition - 相対位置
例外:
ArrayIndexOutOfBoundsException - 指定位置がバッファの外を指している場合

getInputStream

public InputStream getInputStream()
入力ストリームを取得します。

戻り値:
入力ストリーム

getOutputStream

public OutputStream getOutputStream()
出力ストリームを取得します。

戻り値:
出力ストリーム

toString

public String toString()
ストリームの文字列表現を返します。

戻り値:
文字列表現