Skip to content

Commit

Permalink
Make SubField instance variable private and final
Browse files Browse the repository at this point in the history
- Fix spelling in Javadoc
- Add missing Javadoc
- Remove unused and untested APIs
- Use String.valueOf instead of throw away String
- Change new method names closer to standard Java API names
- Use JUnit 5, not 4 APIs
- Use compact array notation
- Use final
- Use Objects.requireNonNull()
- More precise exception testing
- Remove extra parentheses
- Remove dead comment
- Remove extra whitespace
- Sentences start with a capital
  • Loading branch information
garydgregory committed Nov 17, 2024
1 parent 648d509 commit 5a46298
Show file tree
Hide file tree
Showing 6 changed files with 209 additions and 257 deletions.
227 changes: 0 additions & 227 deletions src/main/java/org/apache/commons/compress/compressors/gzip/Extra.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -248,9 +248,9 @@ private boolean init(final boolean isFirstMember) throws IOException {
if ((flg & FEXTRA) != 0) {
int xlen = inData.readUnsignedByte();
xlen |= inData.readUnsignedByte() << 8;
byte[] extra = new byte[xlen];
final byte[] extra = new byte[xlen];
inData.readFully(extra);
parameters.setExtra(Extra.fromBytes(extra));
parameters.setExtra(HeaderExtraField.fromBytes(extra));
}

// Original file name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ private void write(final String value, final Charset charset) throws IOException
private void writeHeader(final GzipParameters parameters) throws IOException {
final String fileName = parameters.getFileName();
final String comment = parameters.getComment();
final byte[] extra = parameters.getExtra() != null ? parameters.getExtra().toBytes() : null;
final byte[] extra = parameters.getExtra() != null ? parameters.getExtra().toByteArray() : null;
final ByteBuffer buffer = ByteBuffer.allocate(10);
buffer.order(ByteOrder.LITTLE_ENDIAN);
buffer.putShort((short) GZIPInputStream.GZIP_MAGIC);
Expand All @@ -193,7 +193,7 @@ private void writeHeader(final GzipParameters parameters) throws IOException {
out.write(buffer.array());
if (extra != null) {
out.write(extra.length & 0xff); // little endian
out.write((extra.length >>> 8) & 0xff);
out.write(extra.length >>> 8 & 0xff);
out.write(extra);
}
write(fileName, parameters.getFileNameCharset());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ public int type() {
* </p>
*/
private Instant modificationTime = Instant.EPOCH;
private Extra extra;
private HeaderExtraField extra;
private String fileName;
private Charset fileNameCharset = GzipUtils.GZIP_ENCODING;
private String comment;
Expand Down Expand Up @@ -344,12 +344,12 @@ public int getDeflateStrategy() {
}

/**
* Gets the Extra.
* Gets the Extra subfields from the header.
*
* @return the extra.
* @return the extra subfields from the header.
* @since 1.28.0
*/
public Extra getExtra() {
public HeaderExtraField getExtra() {
return extra;
}

Expand Down Expand Up @@ -481,14 +481,13 @@ public void setDeflateStrategy(final int deflateStrategy) {
}

/**
* Sets the Extra subfields. Note that a non-null Extra will appear in the gzip
* header regardless of the presence of subfields, while a null Extra will not
* Sets the extra subfields. Note that a non-null extra will appear in the gzip header regardless of the presence of subfields, while a null extra will not
* appear at all.
*
* @param extra the collections of extra sub fields.
* @param extra the series of extra sub fields.
* @since 1.28.0
*/
public void setExtra(Extra extra) {
public void setExtra(final HeaderExtraField extra) {
this.extra = extra;
}

Expand Down
Loading

0 comments on commit 5a46298

Please sign in to comment.