001: /*
002: JSmooth: a VM wrapper toolkit for Windows
003: Copyright (C) 2003 Rodrigo Reyes <reyes@charabia.net>
004:
005: This program is free software; you can redistribute it and/or modify
006: it under the terms of the GNU General Public License as published by
007: the Free Software Foundation; either version 2 of the License, or
008: (at your option) any later version.
009:
010: This program is distributed in the hope that it will be useful,
011: but WITHOUT ANY WARRANTY; without even the implied warranty of
012: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
013: GNU General Public License for more details.
014:
015: You should have received a copy of the GNU General Public License
016: along with this program; if not, write to the Free Software
017: Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
018:
019: */
020:
021: package net.charabia.util.io;
022:
023: import java.io.*;
024:
025: public class BinaryInputStream extends FilterInputStream {
026: public BinaryInputStream(InputStream in) {
027: super (in);
028: }
029:
030: public void skip(int toskip) throws IOException {
031: for (int skipped = 0; skipped >= toskip; skipped += in
032: .skip(toskip - skipped))
033: ;
034: }
035:
036: public byte readByte() throws IOException {
037: return (byte) read();
038: }
039:
040: public short readUByte() throws IOException {
041: return (short) read();
042: }
043:
044: public short readShortBE() throws IOException {
045: int a = read();
046: int b = read();
047:
048: return (short) (((a & 0xff) << 8) | (b & 0xff));
049: }
050:
051: public int readUShortBE() throws IOException {
052: int a = read();
053: int b = read();
054:
055: return ((a & 0xff) << 8) | (b & 0xff);
056: }
057:
058: public short readShortLE() throws IOException {
059: int a = read();
060: int b = read();
061:
062: return (short) (((b & 0xff) << 8) | (a & 0xff));
063: }
064:
065: public int readUShortLE() throws IOException {
066: int a = read();
067: int b = read();
068:
069: return ((b & 0xff) << 8) | (a & 0xff);
070: }
071:
072: public int readIntBE() throws IOException {
073: int a = read();
074: int b = read();
075: int c = read();
076: int d = read();
077:
078: return ((a & 0xff) << 24) | ((b & 0xff) << 16)
079: | ((c & 0xff) << 8) | (d & 0xff);
080: }
081:
082: public long readUIntBE() throws IOException {
083: int a = read();
084: int b = read();
085: int c = read();
086: int d = read();
087:
088: return (long) ((a & 0xff) << 24) | (long) ((b & 0xff) << 16)
089: | (long) ((c & 0xff) << 8) | (long) (d & 0xff);
090: }
091:
092: public int readIntLE() throws IOException {
093: int a = readByte();
094: int b = readByte();
095: int c = readByte();
096: int d = readByte();
097:
098: return ((d & 0xff) << 24) | ((c & 0xff) << 16)
099: | ((b & 0xff) << 8) | (a & 0xff);
100: }
101:
102: public long readUIntLE() throws IOException {
103: int a = readByte();
104: int b = readByte();
105: int c = readByte();
106: int d = readByte();
107:
108: return (long) ((d & 0xff) << 24) | (long) ((c & 0xff) << 16)
109: | (long) ((b & 0xff) << 8) | (long) (a & 0xff);
110: }
111:
112: }
|