-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AVRO-4068: Java Code Cleanup #3192
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -150,9 +150,9 @@ private Null() { | |
// Also, we only ever ADD to the collection, never changing a value, so | ||
// putWithAbsent is the | ||
// only modifier | ||
private ConcurrentMap<String, JsonNode> props = new ConcurrentHashMap<String, JsonNode>() { | ||
private final ConcurrentMap<String, JsonNode> props = new ConcurrentHashMap<>() { | ||
private static final long serialVersionUID = 1L; | ||
private Queue<MapEntry<String, JsonNode>> propOrder = new ConcurrentLinkedQueue<>(); | ||
private final Queue<MapEntry<String, JsonNode>> propOrder = new ConcurrentLinkedQueue<>(); | ||
|
||
@Override | ||
public JsonNode putIfAbsent(String key, JsonNode value) { | ||
|
@@ -170,10 +170,10 @@ public JsonNode put(String key, JsonNode value) { | |
|
||
@Override | ||
public Set<Map.Entry<String, JsonNode>> entrySet() { | ||
return new AbstractSet<Map.Entry<String, JsonNode>>() { | ||
return new AbstractSet<>() { | ||
@Override | ||
public Iterator<Map.Entry<String, JsonNode>> iterator() { | ||
return new Iterator<Map.Entry<String, JsonNode>>() { | ||
return new Iterator<>() { | ||
Iterator<MapEntry<String, JsonNode>> it = propOrder.iterator(); | ||
|
||
@Override | ||
|
@@ -196,7 +196,7 @@ public int size() { | |
} | ||
}; | ||
|
||
private Set<String> reserved; | ||
private final Set<String> reserved; | ||
|
||
JsonProperties(Set<String> reserved) { | ||
this.reserved = reserved; | ||
|
@@ -206,7 +206,7 @@ public int size() { | |
this.reserved = reserved; | ||
for (Entry<String, ?> a : propMap.entrySet()) { | ||
Object v = a.getValue(); | ||
JsonNode json = null; | ||
JsonNode json; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This always gets overwritten |
||
if (v instanceof String) { | ||
json = TextNode.valueOf((String) v); | ||
} else if (v instanceof JsonNode) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,7 +25,6 @@ | |
import java.nio.charset.StandardCharsets; | ||
import java.security.MessageDigest; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.HashSet; | ||
|
@@ -71,11 +70,9 @@ public class Protocol extends JsonProperties { | |
public static final long VERSION = 1; | ||
|
||
// Support properties for both Protocol and Message objects | ||
private static final Set<String> MESSAGE_RESERVED = Collections | ||
.unmodifiableSet(new HashSet<>(Arrays.asList("doc", "response", "request", "errors", "one-way"))); | ||
private static final Set<String> MESSAGE_RESERVED = Set.of("doc", "response", "request", "errors", "one-way"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use new |
||
|
||
private static final Set<String> FIELD_RESERVED = Collections | ||
.unmodifiableSet(new HashSet<>(Arrays.asList("name", "type", "doc", "default", "aliases"))); | ||
private static final Set<String> FIELD_RESERVED = Set.of("name", "type", "doc", "default", "aliases"); | ||
|
||
/** A protocol message. */ | ||
public class Message extends JsonProperties { | ||
|
@@ -255,8 +252,8 @@ void toJson1(Set<String> knownNames, JsonGenerator gen) throws IOException { | |
/** Union type for generating system errors. */ | ||
public static final Schema SYSTEM_ERRORS = Schema.createUnion(Collections.singletonList(SYSTEM_ERROR)); | ||
|
||
private static final Set<String> PROTOCOL_RESERVED = Collections | ||
.unmodifiableSet(new HashSet<>(Arrays.asList("namespace", "protocol", "doc", "messages", "types", "errors"))); | ||
private static final Set<String> PROTOCOL_RESERVED = Set.of("namespace", "protocol", "doc", "messages", "types", | ||
"errors"); | ||
|
||
private Protocol() { | ||
super(PROTOCOL_RESERVED); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,7 +27,6 @@ private DataFileConstants() { | |
|
||
public static final byte VERSION = 1; | ||
public static final byte[] MAGIC = new byte[] { (byte) 'O', (byte) 'b', (byte) 'j', VERSION }; | ||
public static final long FOOTER_BLOCK = -1; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Never used |
||
public static final int SYNC_SIZE = 16; | ||
public static final int DEFAULT_SYNC_INTERVAL = 4000 * SYNC_SIZE; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,7 +63,7 @@ private Header() { | |
} | ||
} | ||
|
||
private DatumReader<D> reader; | ||
private final DatumReader<D> reader; | ||
private long blockSize; | ||
private boolean availableBlock = false; | ||
private Header header; | ||
|
@@ -94,7 +94,7 @@ public DataFileStream(InputStream in, DatumReader<D> reader) throws IOException | |
/** | ||
* create an uninitialized DataFileStream | ||
*/ | ||
protected DataFileStream(DatumReader<D> reader) throws IOException { | ||
protected DataFileStream(DatumReader<D> reader) { | ||
this.reader = reader; | ||
} | ||
|
||
|
@@ -147,7 +147,7 @@ void initialize(InputStream in, byte[] magic) throws IOException { | |
} | ||
|
||
/** Initialize the stream without reading from it. */ | ||
void initialize(Header header) throws IOException { | ||
void initialize(Header header) { | ||
this.header = header; | ||
this.codec = resolveCodec(); | ||
reader.setSchema(header.schema); | ||
|
@@ -303,7 +303,7 @@ boolean hasNextBlock() { | |
blockRemaining = vin.readLong(); // read block count | ||
blockSize = vin.readLong(); // read block size | ||
if (blockSize > Integer.MAX_VALUE || blockSize < 0) { | ||
throw new IOException("Block size invalid or too large for this " + "implementation: " + blockSize); | ||
throw new IOException("Block size invalid or too large for this implementation: " + blockSize); | ||
} | ||
blockCount = blockRemaining; | ||
availableBlock = true; | ||
|
@@ -366,22 +366,6 @@ private DataBlock(long numEntries, int blockSize) { | |
this.numEntries = numEntries; | ||
} | ||
|
||
byte[] getData() { | ||
return data; | ||
} | ||
|
||
long getNumEntries() { | ||
return numEntries; | ||
} | ||
|
||
int getBlockSize() { | ||
return blockSize; | ||
} | ||
|
||
boolean isFlushOnWrite() { | ||
return flushOnWrite; | ||
} | ||
|
||
Comment on lines
-369
to
-384
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Never used |
||
void setFlushOnWrite(boolean flushOnWrite) { | ||
this.flushOnWrite = flushOnWrite; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,15 +26,14 @@ | |
import org.apache.avro.util.NonCopyingByteArrayOutputStream; | ||
import org.apache.commons.compress.compressors.xz.XZCompressorInputStream; | ||
import org.apache.commons.compress.compressors.xz.XZCompressorOutputStream; | ||
import org.apache.commons.compress.utils.IOUtils; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Deprecated |
||
|
||
/** * Implements xz compression and decompression. */ | ||
public class XZCodec extends Codec { | ||
public final static int DEFAULT_COMPRESSION = 6; | ||
private static final int DEFAULT_BUFFER_SIZE = 8192; | ||
|
||
static class Option extends CodecFactory { | ||
private int compressionLevel; | ||
private final int compressionLevel; | ||
|
||
Option(int compressionLevel) { | ||
this.compressionLevel = compressionLevel; | ||
|
@@ -46,7 +45,7 @@ protected Codec createInstance() { | |
} | ||
} | ||
|
||
private int compressionLevel; | ||
private final int compressionLevel; | ||
|
||
public XZCodec(int compressionLevel) { | ||
this.compressionLevel = compressionLevel; | ||
|
@@ -72,7 +71,7 @@ public ByteBuffer decompress(ByteBuffer data) throws IOException { | |
InputStream bytesIn = new ByteArrayInputStream(data.array(), computeOffset(data), data.remaining()); | ||
|
||
try (InputStream ios = new XZCompressorInputStream(bytesIn)) { | ||
IOUtils.copy(ios, baos); | ||
ios.transferTo(baos); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. new JDK9+ syntax |
||
} | ||
return baos.asByteBuffer(); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This cannot be null