diff options
author | xiaofeng@google.com <xiaofeng@google.com@630680e5-0e50-0410-840e-4b1c322b438d> | 2012-11-30 16:26:07 +0000 |
---|---|---|
committer | xiaofeng@google.com <xiaofeng@google.com@630680e5-0e50-0410-840e-4b1c322b438d> | 2012-11-30 16:26:07 +0000 |
commit | d2d50f9a73184ea77e7b907b7767a6f4c8c8d4bf (patch) | |
tree | 8825961678229563d905869b98c989b417e61d4f /java | |
parent | a4491ea142c6b2b4e898f8110557c83008819476 (diff) |
Fix Java compile issues under JDK 1.5
Diffstat (limited to 'java')
5 files changed, 15 insertions, 17 deletions
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<Byte> { 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<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. 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<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(); } 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<String> } } - @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<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) { 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<String> }; } - @Override public List<?> getUnderlyingElements() { // The returned value is already unmodifiable. return list.getUnderlyingElements(); |