/**
* OutputStreamの現在位置にint値(4バイト)を書き込む。
* @param out
* @param i
* @throws IOException
*/
protected static void writeInt(OutputStream out, int i) throws IOException {
byte[] bytes = {
(byte) (i >> 24)
, (byte) (i >> 16)
, (byte) (i >> 8)
, (byte) i
};
out.write(bytes);
}
/**
* InputStreamからint値(4バイト)を読み込む
* @param in
* @return
* @throws IOException
*/
protected static int readInt(InputStream in) throws IOException {
byte[] bytes = new byte[4];
in.read(bytes);
return (0xff & bytes[0]) << 24
| (0xff & bytes[1]) << 16
| (0xff & bytes[2]) << 8
| (0xff & bytes[3]);
}
More than 5 years have passed since last update.
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme