Fix Java compile issues under JDK 1.5

pull/3335/head
xiaofeng@google.com 12 years ago
parent a4491ea142
commit d2d50f9a73
  1. 14
      java/src/main/java/com/google/protobuf/ByteString.java
  2. 6
      java/src/main/java/com/google/protobuf/LazyField.java
  3. 1
      java/src/main/java/com/google/protobuf/LazyStringArrayList.java
  4. 10
      java/src/main/java/com/google/protobuf/RopeByteString.java
  5. 1
      java/src/main/java/com/google/protobuf/UnmodifiableLazyStringList.java

@ -37,7 +37,6 @@ import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
@ -777,6 +776,15 @@ public abstract class ByteString implements Iterable<Byte> {
return ByteString.copyFrom(flushedBuffers);
}
/**
* Implement java.util.Arrays.copyOf() for jdk 1.5.
*/
private byte[] copyArray(byte[] buffer, int length) {
byte[] result = new byte[length];
System.arraycopy(buffer, 0, result, 0, Math.min(buffer.length, length));
return result;
}
/**
* Writes the complete contents of this byte array output stream to
* the specified output stream argument.
@ -800,7 +808,7 @@ public abstract class ByteString implements Iterable<Byte> {
byteString.writeTo(out);
}
out.write(Arrays.copyOf(cachedBuffer, cachedBufferPos));
out.write(copyArray(cachedBuffer, cachedBufferPos));
}
/**
@ -853,7 +861,7 @@ public abstract class ByteString implements Iterable<Byte> {
private void flushLastBuffer() {
if (bufferPos < buffer.length) {
if (bufferPos > 0) {
byte[] bufferCopy = Arrays.copyOf(buffer, bufferPos);
byte[] bufferCopy = copyArray(buffer, bufferPos);
flushedBuffers.add(new LiteralByteString(bufferCopy));
}
// We reuse this buffer for further writes.

@ -157,12 +157,10 @@ class LazyField {
this.entry = entry;
}
@Override
public K getKey() {
return entry.getKey();
}
@Override
public Object getValue() {
LazyField field = entry.getValue();
if (field == null) {
@ -175,7 +173,6 @@ class LazyField {
return entry.getValue();
}
@Override
public Object setValue(Object value) {
if (!(value instanceof MessageLite)) {
throw new IllegalArgumentException(
@ -193,13 +190,11 @@ class LazyField {
this.iterator = iterator;
}
@Override
public boolean hasNext() {
return iterator.hasNext();
}
@SuppressWarnings("unchecked")
@Override
public Entry<K, Object> next() {
Entry<K, ?> entry = iterator.next();
if (entry.getValue() instanceof LazyField) {
@ -208,7 +203,6 @@ class LazyField {
return (Entry<K, Object>) entry;
}
@Override
public void remove() {
iterator.remove();
}

@ -172,7 +172,6 @@ public class LazyStringArrayList extends AbstractList<String>
}
}
@Override
public List<?> getUnderlyingElements() {
return Collections.unmodifiableList(list);
}

@ -36,13 +36,12 @@ import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.io.ByteArrayInputStream;
import java.nio.ByteBuffer;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Deque;
import java.util.Iterator;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.Stack;
/**
* Class to represent {@code ByteStrings} formed by concatenation of other
@ -590,8 +589,7 @@ class RopeByteString extends ByteString {
// Stack containing the part of the string, starting from the left, that
// we've already traversed. The final string should be the equivalent of
// concatenating the strings on the stack from bottom to top.
private final Deque<ByteString> prefixesStack =
new ArrayDeque<ByteString>(minLengthByDepth.length);
private final Stack<ByteString> prefixesStack = new Stack<ByteString>();
private ByteString balance(ByteString left, ByteString right) {
doBalance(left);
@ -703,8 +701,8 @@ class RopeByteString extends ByteString {
*/
private static class PieceIterator implements Iterator<LiteralByteString> {
private final Deque<RopeByteString> breadCrumbs =
new ArrayDeque<RopeByteString>(minLengthByDepth.length);
private final Stack<RopeByteString> breadCrumbs =
new Stack<RopeByteString>();
private LiteralByteString next;
private PieceIterator(ByteString root) {

@ -145,7 +145,6 @@ public class UnmodifiableLazyStringList extends AbstractList<String>
};
}
@Override
public List<?> getUnderlyingElements() {
// The returned value is already unmodifiable.
return list.getUnderlyingElements();

Loading…
Cancel
Save