Java バイトストリーム DataInputStream/DataOutputStream

DataInputStream コンストラクタ

コンストラクタ 説明
DataInputStream(InputStream in) inputStream を引数として DataInputStream を生成する。

DataInputStream メソッド

メソッド 説明
boolean readBoolean() throws IOException Stream から読み取った boolean を返す。
byte readByte() throws IOException Stream から読み取った byte を返す。
char readChar() throws IOException Stream から読み取った char を返す。
double readDouble() throws IOException Stream から double を返す。
float readFloat() throws IOException Stream から float を返す。
long readLong() throws IOException Stream から long を返す。
short readShort() throws IOException Stream から short を返す。
int readInt() throws IOException Stream から int を返す。
void readFully(byte[] buf) throws IOException Stream から buf サイズ分のバイトを読み取り、buf[] に保存する。
void readFully(byte[] buf, int off, int len) throws IOException Stream から len の長さ分のバイトを読み取り、buf の off 位置に保存する。
String readUTF() throws IOException UTF エンコード値を取得して文字列として返す。
static String readUTF(DataInput in) throws IOException DataInput の修正 UTF エンコード値を取得して文字列として返す。
int skipBytes(int n) throws IOException n 分のバイトを skip する。

DataOutputStream コンストラクタ

コンストラクタ 説明
DataOutputStream(OutputStream out) outputStream を引数として DataOutputStream を生成する。

DataOutputStream メソッド

メソッド 説明
void flush() throws IOException バッファを出力して空にする。
int size() Stream に出力されたバイトサイズを返す。
void write(int i) throws IOException int 型 i 値が持つ 1 バイトを出力する。
void write(byte buf[], int index, int size) throws IOException byte 配列 buf の index 位置から size 分を出力する。
void writeBoolean(boolean b) throws IOException boolean を 1 バイト値として出力する。
void writeByte(int i) throws IOException int を 4 バイト値として上位バイトから出力する。
void writeBytes(String s) throws IOException 文字列をバイト順に出力する。
void writeChar(int i) throws IOException char を 2 バイト値として上位バイトから出力する。
void writeChars(String s) throws IOException String 文字列を char 型として出力する。
void writeDouble(double d) throws IOException Double クラスの doubleToBits() を使用して long に変換した後、long 値を 8 バイト量として上位バイトから出力する。
void writeFloat(float f) throws IOException Float を floatToBits() で変換した後、int 値を 4 バイト量として上位バイトから出力する。
void writeInt(int i) throws IOException int の上位バイトから出力する。
void writeLong(long l) throws IOException long 型の引数値を出力する。
void writeShort(short s) throws IOException short 型の引数値を出力する。
void writeUTF(String s) throws IOException UTF-8 エンコードを使用して文字列を出力する。