From d2d50f9a73184ea77e7b907b7767a6f4c8c8d4bf Mon Sep 17 00:00:00 2001 From: "xiaofeng@google.com" Date: Fri, 30 Nov 2012 16:26:07 +0000 Subject: Fix Java compile issues under JDK 1.5 --- java/src/main/java/com/google/protobuf/ByteString.java | 14 +++++++++++--- java/src/main/java/com/google/protobuf/LazyField.java | 6 ------ .../main/java/com/google/protobuf/LazyStringArrayList.java | 1 - java/src/main/java/com/google/protobuf/RopeByteString.java | 10 ++++------ .../com/google/protobuf/UnmodifiableLazyStringList.java | 1 - 5 files changed, 15 insertions(+), 17 deletions(-) (limited to 'java/src') diff --git a/java/src/main/java/com/google/protobuf/ByteString.java b/java/src/main/java/com/google/protobuf/ByteString.java index 1b18169e..73d831f6 100644 --- a/java/src/main/java/com/google/protobuf/ByteString.java +++ b/java/src/main/java/com/google/protobuf/ByteString.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; @@ -776,6 +775,15 @@ public abstract class ByteString implements Iterable { flushLastBuffer(); 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 @@ -800,7 +808,7 @@ public abstract class ByteString implements Iterable { byteString.writeTo(out); } - out.write(Arrays.copyOf(cachedBuffer, cachedBufferPos)); + out.write(copyArray(cachedBuffer, cachedBufferPos)); } /** @@ -853,7 +861,7 @@ public abstract class ByteString implements Iterable { 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. diff --git a/java/src/main/java/com/google/protobuf/LazyField.java b/java/src/main/java/com/google/protobuf/LazyField.java index df9425eb..c4f9201c 100644 --- a/java/src/main/java/com/google/protobuf/LazyField.java +++ b/java/src/main/java/com/google/protobuf/LazyField.java @@ -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 next() { Entry entry = iterator.next(); if (entry.getValue() instanceof LazyField) { @@ -208,7 +203,6 @@ class LazyField { return (Entry) entry; } - @Override public void remove() { iterator.remove(); } diff --git a/java/src/main/java/com/google/protobuf/LazyStringArrayList.java b/java/src/main/java/com/google/protobuf/LazyStringArrayList.java index 75c6a4b7..a5f0bd90 100644 --- a/java/src/main/java/com/google/protobuf/LazyStringArrayList.java +++ b/java/src/main/java/com/google/protobuf/LazyStringArrayList.java @@ -172,7 +172,6 @@ public class LazyStringArrayList extends AbstractList } } - @Override public List getUnderlyingElements() { return Collections.unmodifiableList(list); } diff --git a/java/src/main/java/com/google/protobuf/RopeByteString.java b/java/src/main/java/com/google/protobuf/RopeByteString.java index 8d44d117..46997823 100644 --- a/java/src/main/java/com/google/protobuf/RopeByteString.java +++ b/java/src/main/java/com/google/protobuf/RopeByteString.java @@ -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 prefixesStack = - new ArrayDeque(minLengthByDepth.length); + private final Stack prefixesStack = new Stack(); private ByteString balance(ByteString left, ByteString right) { doBalance(left); @@ -703,8 +701,8 @@ class RopeByteString extends ByteString { */ private static class PieceIterator implements Iterator { - private final Deque breadCrumbs = - new ArrayDeque(minLengthByDepth.length); + private final Stack breadCrumbs = + new Stack(); private LiteralByteString next; private PieceIterator(ByteString root) { diff --git a/java/src/main/java/com/google/protobuf/UnmodifiableLazyStringList.java b/java/src/main/java/com/google/protobuf/UnmodifiableLazyStringList.java index f80f0968..591bca54 100644 --- a/java/src/main/java/com/google/protobuf/UnmodifiableLazyStringList.java +++ b/java/src/main/java/com/google/protobuf/UnmodifiableLazyStringList.java @@ -145,7 +145,6 @@ public class UnmodifiableLazyStringList extends AbstractList }; } - @Override public List getUnderlyingElements() { // The returned value is already unmodifiable. return list.getUnderlyingElements(); -- cgit v1.2.3