mirror of
https://github.com/corda/corda.git
synced 2025-01-22 12:28:11 +00:00
Merge branch 'master' of dice:git/vm
This commit is contained in:
commit
fc6beb852b
@ -2,13 +2,15 @@ package java.io;
|
||||
|
||||
public class PushbackReader extends Reader {
|
||||
private final Reader in;
|
||||
private final char[] buffer;
|
||||
private int position;
|
||||
private int limit;
|
||||
private char savedChar;
|
||||
private boolean hasSavedChar;
|
||||
|
||||
public PushbackReader(Reader in, int bufferSize) {
|
||||
if (bufferSize > 1) {
|
||||
throw new IllegalArgumentException(bufferSize + " > 1");
|
||||
}
|
||||
this.in = in;
|
||||
this.buffer = new char[bufferSize];
|
||||
this.hasSavedChar = false;
|
||||
}
|
||||
|
||||
public PushbackReader(Reader in) {
|
||||
@ -17,21 +19,12 @@ public class PushbackReader extends Reader {
|
||||
|
||||
public int read(char[] b, int offset, int length) throws IOException {
|
||||
int count = 0;
|
||||
|
||||
if (position < limit) {
|
||||
int remaining = limit - position;
|
||||
if (remaining > length) {
|
||||
remaining = length;
|
||||
if (hasSavedChar && length > 0) {
|
||||
length--;
|
||||
b[offset++] = savedChar;
|
||||
hasSavedChar = false;
|
||||
count = 1;
|
||||
}
|
||||
|
||||
System.arraycopy(buffer, position, b, offset, remaining);
|
||||
|
||||
count += remaining;
|
||||
position += remaining;
|
||||
offset += remaining;
|
||||
length -= remaining;
|
||||
}
|
||||
|
||||
if (length > 0) {
|
||||
int c = in.read(b, offset, length);
|
||||
if (c == -1) {
|
||||
@ -47,11 +40,13 @@ public class PushbackReader extends Reader {
|
||||
}
|
||||
|
||||
public void unread(char[] b, int offset, int length) throws IOException {
|
||||
if (position < length) {
|
||||
throw new IOException(length + " not in [0," + position + "]");
|
||||
if (length != 1) {
|
||||
throw new IOException("Can only push back 1 char, not " + length);
|
||||
} else if (hasSavedChar) {
|
||||
throw new IOException("Already have a saved char");
|
||||
} else {
|
||||
System.arraycopy(buffer, position - length, b, offset, length);
|
||||
position -= length;
|
||||
hasSavedChar = true;
|
||||
savedChar = b[offset];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,7 @@ public class StringReader extends Reader {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
in.getChars(position, length, b, offset);
|
||||
in.getChars(position, position+length, b, offset);
|
||||
position += length;
|
||||
return length;
|
||||
}
|
||||
|
@ -11,6 +11,13 @@ public class Hashtable<K, V> implements Map<K, V> {
|
||||
this(0);
|
||||
}
|
||||
|
||||
public Hashtable(Map<? extends K,? extends V> m) {
|
||||
this(m.size());
|
||||
for (Entry<? extends K, ? extends V> entry : m.entrySet()) {
|
||||
put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return map.toString();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user