|
|
@ -4,7 +4,10 @@
|
|
|
|
// (C) by Michael Peter Christen; mc@anomic.de
|
|
|
|
// (C) by Michael Peter Christen; mc@anomic.de
|
|
|
|
// first published on http://www.anomic.de
|
|
|
|
// first published on http://www.anomic.de
|
|
|
|
// Frankfurt, Germany, 2004
|
|
|
|
// Frankfurt, Germany, 2004
|
|
|
|
// last major change: 09.02.2004
|
|
|
|
//
|
|
|
|
|
|
|
|
// $LastChangedDate$
|
|
|
|
|
|
|
|
// $LastChangedRevision$
|
|
|
|
|
|
|
|
// $LastChangedBy$
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or modify
|
|
|
|
// This program is free software; you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
@ -68,42 +71,42 @@ abstract class kelondroAbstractRA implements kelondroRA {
|
|
|
|
|
|
|
|
|
|
|
|
// derived methods:
|
|
|
|
// derived methods:
|
|
|
|
public void readFully(byte[] b, int off, int len) throws IOException {
|
|
|
|
public void readFully(byte[] b, int off, int len) throws IOException {
|
|
|
|
int r = read(b, off, len);
|
|
|
|
final int r = read(b, off, len);
|
|
|
|
if (r < 0) return; // read exceeded EOF
|
|
|
|
if (r < 0) return; // read exceeded EOF
|
|
|
|
if (r < len) readFully(b, off + r, len - r);
|
|
|
|
if (r < len) { readFully(b, off + r, len - r); }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public byte readByte() throws IOException {
|
|
|
|
public byte readByte() throws IOException {
|
|
|
|
int ch = this.read();
|
|
|
|
final int ch = this.read();
|
|
|
|
if (ch < 0) throw new IOException();
|
|
|
|
if (ch < 0) throw new IOException();
|
|
|
|
return (byte)(ch);
|
|
|
|
return (byte)(ch);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void writeByte(int v) throws IOException {
|
|
|
|
public void writeByte(final int v) throws IOException {
|
|
|
|
this.write(v);
|
|
|
|
this.write(v);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public short readShort() throws IOException {
|
|
|
|
public short readShort() throws IOException {
|
|
|
|
int ch1 = this.read();
|
|
|
|
final int ch1 = this.read();
|
|
|
|
int ch2 = this.read();
|
|
|
|
final int ch2 = this.read();
|
|
|
|
if ((ch1 | ch2) < 0) throw new IOException();
|
|
|
|
if ((ch1 | ch2) < 0) throw new IOException();
|
|
|
|
return (short) ((ch1 << 8) + (ch2 << 0));
|
|
|
|
return (short) ((ch1 << 8) + (ch2 << 0));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void writeShort(int v) throws IOException {
|
|
|
|
public void writeShort(final int v) throws IOException {
|
|
|
|
this.write((v >>> 8) & 0xFF); this.write((v >>> 0) & 0xFF);
|
|
|
|
this.write((v >>> 8) & 0xFF); this.write((v >>> 0) & 0xFF);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public int readInt() throws IOException {
|
|
|
|
public int readInt() throws IOException {
|
|
|
|
int ch1 = this.read();
|
|
|
|
final int ch1 = this.read();
|
|
|
|
int ch2 = this.read();
|
|
|
|
final int ch2 = this.read();
|
|
|
|
int ch3 = this.read();
|
|
|
|
final int ch3 = this.read();
|
|
|
|
int ch4 = this.read();
|
|
|
|
final int ch4 = this.read();
|
|
|
|
if ((ch1 | ch2 | ch3 | ch4) < 0) throw new IOException("kelondroAbstractRA.readInt: wrong values; ch1=" + ch1 + ", ch2=" + ch2 + ", ch3=" + ch3 + ", ch4=" + ch4);
|
|
|
|
if ((ch1 | ch2 | ch3 | ch4) < 0) throw new IOException("kelondroAbstractRA.readInt: wrong values; ch1=" + ch1 + ", ch2=" + ch2 + ", ch3=" + ch3 + ", ch4=" + ch4);
|
|
|
|
return ((ch1 << 24) | (ch2 << 16) | (ch3 << 8) | ch4);
|
|
|
|
return ((ch1 << 24) | (ch2 << 16) | (ch3 << 8) | ch4);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void writeInt(int v) throws IOException {
|
|
|
|
public void writeInt(final int v) throws IOException {
|
|
|
|
this.write((v >>> 24) & 0xFF); this.write((v >>> 16) & 0xFF);
|
|
|
|
this.write((v >>> 24) & 0xFF); this.write((v >>> 16) & 0xFF);
|
|
|
|
this.write((v >>> 8) & 0xFF); this.write((v >>> 0) & 0xFF);
|
|
|
|
this.write((v >>> 8) & 0xFF); this.write((v >>> 0) & 0xFF);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -112,14 +115,14 @@ abstract class kelondroAbstractRA implements kelondroRA {
|
|
|
|
return ((long) (readInt()) << 32) + (readInt() & 0xFFFFFFFFL);
|
|
|
|
return ((long) (readInt()) << 32) + (readInt() & 0xFFFFFFFFL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void writeLong(long v) throws IOException {
|
|
|
|
public void writeLong(final long v) throws IOException {
|
|
|
|
this.write((int) (v >>> 56) & 0xFF); this.write((int) (v >>> 48) & 0xFF);
|
|
|
|
this.write((int) (v >>> 56) & 0xFF); this.write((int) (v >>> 48) & 0xFF);
|
|
|
|
this.write((int) (v >>> 40) & 0xFF); this.write((int) (v >>> 32) & 0xFF);
|
|
|
|
this.write((int) (v >>> 40) & 0xFF); this.write((int) (v >>> 32) & 0xFF);
|
|
|
|
this.write((int) (v >>> 24) & 0xFF); this.write((int) (v >>> 16) & 0xFF);
|
|
|
|
this.write((int) (v >>> 24) & 0xFF); this.write((int) (v >>> 16) & 0xFF);
|
|
|
|
this.write((int) (v >>> 8) & 0xFF); this.write((int) (v >>> 0) & 0xFF);
|
|
|
|
this.write((int) (v >>> 8) & 0xFF); this.write((int) (v >>> 0) & 0xFF);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void write(byte[] b) throws IOException {
|
|
|
|
public void write(final byte[] b) throws IOException {
|
|
|
|
this.write(b, 0, b.length);
|
|
|
|
this.write(b, 0, b.length);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -127,7 +130,7 @@ abstract class kelondroAbstractRA implements kelondroRA {
|
|
|
|
private static final byte lf = 10;
|
|
|
|
private static final byte lf = 10;
|
|
|
|
private static final String crlf = new String(new byte[] {cr, lf});
|
|
|
|
private static final String crlf = new String(new byte[] {cr, lf});
|
|
|
|
|
|
|
|
|
|
|
|
public void writeLine(String line) throws IOException {
|
|
|
|
public void writeLine(final String line) throws IOException {
|
|
|
|
this.write(line.getBytes());
|
|
|
|
this.write(line.getBytes());
|
|
|
|
this.write(cr);
|
|
|
|
this.write(cr);
|
|
|
|
this.write(lf);
|
|
|
|
this.write(lf);
|
|
|
@ -158,10 +161,10 @@ abstract class kelondroAbstractRA implements kelondroRA {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void writeProperties(Properties props, String comment) throws IOException {
|
|
|
|
public void writeProperties(final Properties props, final String comment) throws IOException {
|
|
|
|
this.seek(0);
|
|
|
|
this.seek(0);
|
|
|
|
writeLine("# " + comment);
|
|
|
|
writeLine("# " + comment);
|
|
|
|
Enumeration e = props.propertyNames();
|
|
|
|
final Enumeration e = props.propertyNames();
|
|
|
|
String key, value;
|
|
|
|
String key, value;
|
|
|
|
while (e.hasMoreElements()) {
|
|
|
|
while (e.hasMoreElements()) {
|
|
|
|
key = (String) e.nextElement();
|
|
|
|
key = (String) e.nextElement();
|
|
|
@ -175,7 +178,7 @@ abstract class kelondroAbstractRA implements kelondroRA {
|
|
|
|
|
|
|
|
|
|
|
|
public Properties readProperties() throws IOException {
|
|
|
|
public Properties readProperties() throws IOException {
|
|
|
|
this.seek(0);
|
|
|
|
this.seek(0);
|
|
|
|
Properties props = new Properties();
|
|
|
|
final Properties props = new Properties();
|
|
|
|
String line;
|
|
|
|
String line;
|
|
|
|
int pos;
|
|
|
|
int pos;
|
|
|
|
while ((line = readLine()) != null) {
|
|
|
|
while ((line = readLine()) != null) {
|
|
|
@ -189,13 +192,13 @@ abstract class kelondroAbstractRA implements kelondroRA {
|
|
|
|
return props;
|
|
|
|
return props;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void writeMap(Map map, String comment) throws IOException {
|
|
|
|
public void writeMap(final Map map, final String comment) throws IOException {
|
|
|
|
this.seek(0);
|
|
|
|
this.seek(0);
|
|
|
|
writeLine("# " + comment);
|
|
|
|
writeLine("# " + comment);
|
|
|
|
Iterator i = map.entrySet().iterator();
|
|
|
|
final Iterator iter = map.entrySet().iterator();
|
|
|
|
Map.Entry entry;
|
|
|
|
Map.Entry entry;
|
|
|
|
while (i.hasNext()) {
|
|
|
|
while (iter.hasNext()) {
|
|
|
|
entry = (Map.Entry) i.next();
|
|
|
|
entry = (Map.Entry) iter.next();
|
|
|
|
write(((String) entry.getKey()).getBytes());
|
|
|
|
write(((String) entry.getKey()).getBytes());
|
|
|
|
write((byte) '=');
|
|
|
|
write((byte) '=');
|
|
|
|
writeLine((String) entry.getValue());
|
|
|
|
writeLine((String) entry.getValue());
|
|
|
@ -205,7 +208,7 @@ abstract class kelondroAbstractRA implements kelondroRA {
|
|
|
|
|
|
|
|
|
|
|
|
public Map readMap() throws IOException {
|
|
|
|
public Map readMap() throws IOException {
|
|
|
|
this.seek(0);
|
|
|
|
this.seek(0);
|
|
|
|
TreeMap map = new TreeMap();
|
|
|
|
final TreeMap map = new TreeMap();
|
|
|
|
String line;
|
|
|
|
String line;
|
|
|
|
int pos;
|
|
|
|
int pos;
|
|
|
|
while ((line = readLine()) != null) { // very slow readLine????
|
|
|
|
while ((line = readLine()) != null) { // very slow readLine????
|
|
|
@ -219,10 +222,12 @@ abstract class kelondroAbstractRA implements kelondroRA {
|
|
|
|
return map;
|
|
|
|
return map;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void writeArray(byte[] b) throws IOException {
|
|
|
|
/**
|
|
|
|
// this does not write the content to the see position
|
|
|
|
* this does not write the content to the see position
|
|
|
|
// but to the very beginning of the record
|
|
|
|
* but to the very beginning of the record
|
|
|
|
// some additional bytes will ensure that we know the correct content size later on
|
|
|
|
* some additional bytes will ensure that we know the correct content size later on
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public void writeArray(final byte[] b) throws IOException {
|
|
|
|
seek(0);
|
|
|
|
seek(0);
|
|
|
|
writeInt(b.length);
|
|
|
|
writeInt(b.length);
|
|
|
|
write(b);
|
|
|
|
write(b);
|
|
|
@ -230,8 +235,8 @@ abstract class kelondroAbstractRA implements kelondroRA {
|
|
|
|
|
|
|
|
|
|
|
|
public byte[] readArray() throws IOException {
|
|
|
|
public byte[] readArray() throws IOException {
|
|
|
|
seek(0);
|
|
|
|
seek(0);
|
|
|
|
int l = readInt();
|
|
|
|
final int l = readInt();
|
|
|
|
byte[] b = new byte[l];
|
|
|
|
final byte[] b = new byte[l];
|
|
|
|
read(b, 0, l);
|
|
|
|
read(b, 0, l);
|
|
|
|
return b;
|
|
|
|
return b;
|
|
|
|
}
|
|
|
|
}
|
|
|
|