Skip to content

Commit

Permalink
Add GzipParameters.setFileName(String) and deprecate setFilename(String)
Browse files Browse the repository at this point in the history
  • Loading branch information
garydgregory committed Oct 19, 2023
1 parent 030034f commit 1cca111
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/changes/changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ The <action> type attribute can be add,update,fix,remove.
<body>
<release version="1.25.0" date="202Y-MM-DD" description="Minor feature and maintenance release.">
<!-- ADD -->
<action type="add" dev="ggregory" due-to="Gary Gregory">Add GzipParameters.getFileName() and deprecated getFilename().</action>
<action type="add" dev="ggregory" due-to="Gary Gregory">Add GzipParameters.getFileName() and deprecate getFilename().</action>
<action type="add" dev="ggregory" due-to="Gary Gregory">Add GzipParameters.setFileName(String) and deprecate setFilename(String).</action>
<!-- FIX -->
<!-- UPDATE -->
<action type="update" dev="ggregory" due-to="Dependabot">Bump org.slf4j:slf4j-api from 2.0.8 to 2.0.9 #413.</action>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ private boolean init(final boolean isFirstMember) throws IOException {

// Original file name
if ((flg & FNAME) != 0) {
parameters.setFilename(new String(readToNull(inData), GzipUtils.GZIP_ENCODING));
parameters.setFileName(new String(readToNull(inData), GzipUtils.GZIP_ENCODING));
}

// Comment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,22 @@ public void setDeflateStrategy(final int deflateStrategy) {
* Sets the name of the compressed file.
*
* @param fileName the name of the file without the directory path
* @deprecated Use {@link #setFileName(String)}.
*/
@Deprecated
public void setFilename(final String fileName) {
this.fileName = fileName;
}

/**
* Sets the name of the compressed file.
*
* @param fileName the name of the file without the directory path
*/
public void setFileName(final String fileName) {
this.fileName = fileName;
}

/**
* Sets the modification time of the compressed file.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,9 @@ public void testInteroperabilityWithGzipCompressorInputStream() throws Exception
parameters.setCompressionLevel(Deflater.BEST_COMPRESSION);
parameters.setOperatingSystem(3);
parameters.setFilename("test3.xml");
assertEquals(parameters.getFilename(), parameters.getFileName());
parameters.setFileName("test3.xml");
assertEquals(parameters.getFilename(), parameters.getFileName());
parameters.setComment("Test file");
parameters.setModificationTime(System.currentTimeMillis());
try (GzipCompressorOutputStream out = new GzipCompressorOutputStream(bout, parameters)) {
Expand All @@ -196,6 +199,9 @@ public void testInteroperabilityWithGZIPInputStream() throws Exception {
parameters.setCompressionLevel(Deflater.BEST_COMPRESSION);
parameters.setOperatingSystem(3);
parameters.setFilename("test3.xml");
assertEquals(parameters.getFilename(), parameters.getFileName());
parameters.setFileName("test3.xml");
assertEquals(parameters.getFilename(), parameters.getFileName());
parameters.setComment("Test file");
parameters.setModificationTime(System.currentTimeMillis());
try (GzipCompressorOutputStream out = new GzipCompressorOutputStream(bout, parameters)) {
Expand Down Expand Up @@ -234,6 +240,9 @@ public void testMetadataRoundTrip() throws Exception {
parameters.setModificationTime(123456000);
parameters.setOperatingSystem(13);
parameters.setFilename("test3.xml");
assertEquals(parameters.getFilename(), parameters.getFileName());
parameters.setFileName("test3.xml");
assertEquals(parameters.getFilename(), parameters.getFileName());
parameters.setComment("Umlaute möglich?");
try (GzipCompressorOutputStream out = new GzipCompressorOutputStream(bout, parameters)) {
Files.copy(getFile("test3" + ".xml").toPath(), out);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ private void testFileName(final String expected, final String sourceFile) throws
final Path targetFile = Files.createTempFile("test", ".gz");
final GzipParameters parameters = new GzipParameters();
parameters.setFilename(sourceFile);
assertEquals(parameters.getFilename(), parameters.getFileName());
parameters.setFileName(sourceFile);
assertEquals(parameters.getFilename(), parameters.getFileName());
try (OutputStream fos = Files.newOutputStream(targetFile); GzipCompressorOutputStream gos = new GzipCompressorOutputStream(fos, parameters)) {
Files.copy(tempSourceFile, gos);
}
Expand Down

0 comments on commit 1cca111

Please sign in to comment.