Hallo Leute,
ich habe da ein kleines Problem:
Ich möchte Werte einlesen mit einem DataInputStream. Wenn ich byte-werte einlese, stimmen sie, aber sobald der Datentyp grösser als 1 byte ist, gibt es ein Fehler:
Was mache ich falsch bzw. was mache ich nicht?
ich habe da ein kleines Problem:
Ich möchte Werte einlesen mit einem DataInputStream. Wenn ich byte-werte einlese, stimmen sie, aber sobald der Datentyp grösser als 1 byte ist, gibt es ein Fehler:
Java:
@Override
public void init() throws Exception {
DataInputStream in = new DataInputStream(getDataSource().createInputStream());
System.out.println("available: " + in.available());
short reserved = in.readShort();
short type = (short) (in.readShort());// Wert: 256 sollte aber 1 sein -> 256 / 256 = 1
short count = (short) (in.readShort());// Wert: 512 sollte aber 2 sein -> 512 / 256 = 2
System.out.println(reserved);
System.out.println(type);
System.out.println(count);
IcoEntry[] entries = new IcoEntry[count];
for (int i = 0; i < count; i++) {
entries[i] = new IcoEntry();
entries[i].read(in);
entries[i].print();
}
}
private static class IcoEntry {
byte width;
byte height;
byte colorCount;
byte reserved;
short planes;
short bitCount;
int bytesInResource;
int offset;
void read(DataInputStream in) throws Exception {
width = in.readByte();
height = in.readByte();
colorCount = in.readByte();
reserved = in.readByte();
planes = in.readShort();
bitCount = in.readShort();
bytesInResource = in.readInt();
offset = in.readInt();
}
void print() {
System.out.println("--------");
System.out.println("width: " + width);
System.out.println("height: " + height);
System.out.println("colorCount: " + colorCount);
System.out.println("reserved: " + reserved);
System.out.println("colorPlanes: " + planes);
System.out.println("bitCount: " + bitCount);
System.out.println("bytesInResource: " + bytesInResource);
System.out.println("offset: " + offset);
}
}
}
Was mache ich falsch bzw. was mache ich nicht?