You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2020/11/01 15:01:05 UTC

[commons-compress] branch master updated (ea1cba2 -> 99cc3fb)

This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/commons-compress.git.


    from ea1cba2  Access static methods directly.
     new 82f7401  Use final.
     new 3c05472  Remove unused import.
     new cbdb1e2  No need to nest else clause.
     new d68da9b  No need to throw UnsupportedEncodingException from this private method.
     new e61abc3  No need to throw IOException from this private method.
     new e0b11ec  Use try-with-resources.
     new e21f1ac  Fix Javadoc link.
     new 99cc3fb  Use Objects.equals().

The 8 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../compress/archivers/examples/Archiver.java      |  1 -
 .../compress/archivers/sevenz/SevenZFile.java      |  5 ++-
 .../archivers/tar/TarArchiveInputStream.java       |  5 ++-
 .../archivers/tar/TarArchiveOutputStream.java      |  5 ++-
 .../compress/archivers/zip/NioZipEncoding.java     | 16 +++++-----
 .../compress/archivers/zip/ZipArchiveEntry.java    |  7 ++---
 .../archivers/zip/ZipArchiveOutputStream.java      |  4 +--
 .../archivers/zip/Maven221MultiVolumeTest.java     | 25 ++++++---------
 .../archivers/zip/X5455_ExtendedTimestampTest.java | 36 +++++++---------------
 .../compress/archivers/zip/X7875_NewUnixTest.java  |  8 +----
 .../compress/archivers/zip/ZipFileTest.java        |  4 +--
 11 files changed, 41 insertions(+), 75 deletions(-)


[commons-compress] 08/08: Use Objects.equals().

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-compress.git

commit 99cc3fb7eeaed3eb7467c8771ab752f9999dd1ce
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun Nov 1 09:52:19 2020 -0500

    Use Objects.equals().
---
 .../org/apache/commons/compress/archivers/zip/ZipArchiveEntry.java | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntry.java b/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntry.java
index b611bda..e397fff 100644
--- a/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntry.java
+++ b/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntry.java
@@ -27,6 +27,7 @@ import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Date;
 import java.util.List;
+import java.util.Objects;
 import java.util.zip.ZipException;
 
 import org.apache.commons.compress.archivers.ArchiveEntry;
@@ -995,11 +996,7 @@ public class ZipArchiveEntry extends java.util.zip.ZipEntry
         final ZipArchiveEntry other = (ZipArchiveEntry) obj;
         final String myName = getName();
         final String otherName = other.getName();
-        if (myName == null) {
-            if (otherName != null) {
-                return false;
-            }
-        } else if (!myName.equals(otherName)) {
+        if (!Objects.equals(myName, otherName)) {
             return false;
         }
         String myComment = getComment();


[commons-compress] 03/08: No need to nest else clause.

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-compress.git

commit cbdb1e270d525557cca23d76cfc8b4822804b34f
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun Nov 1 08:53:11 2020 -0500

    No need to nest else clause.
---
 .../commons/compress/archivers/sevenz/SevenZFile.java    |  5 ++---
 .../commons/compress/archivers/zip/NioZipEncoding.java   | 16 +++++++---------
 2 files changed, 9 insertions(+), 12 deletions(-)

diff --git a/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZFile.java b/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZFile.java
index 9b68457..5624b4c 100644
--- a/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZFile.java
+++ b/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZFile.java
@@ -468,10 +468,9 @@ public class SevenZFile implements Closeable {
         if (headerLooksValid) {
             final StartHeader startHeader = readStartHeader(startHeaderCrc);
             return initializeArchive(startHeader, password, true);
-        } else {
-            // No valid header found - probably first file of multipart archive was removed too early. Scan for end header.
-            return tryToLocateEndHeader(password);
         }
+        // No valid header found - probably first file of multipart archive was removed too early. Scan for end header.
+        return tryToLocateEndHeader(password);
     }
 
     private Archive tryToLocateEndHeader(final byte[] password) throws IOException {
diff --git a/src/main/java/org/apache/commons/compress/archivers/zip/NioZipEncoding.java b/src/main/java/org/apache/commons/compress/archivers/zip/NioZipEncoding.java
index 4757074..ce9d124 100644
--- a/src/main/java/org/apache/commons/compress/archivers/zip/NioZipEncoding.java
+++ b/src/main/java/org/apache/commons/compress/archivers/zip/NioZipEncoding.java
@@ -167,11 +167,10 @@ class NioZipEncoding implements ZipEncoding, CharsetAccessor {
                 .onMalformedInput(CodingErrorAction.REPLACE)
                 .onUnmappableCharacter(CodingErrorAction.REPLACE)
                 .replaceWith(REPLACEMENT_BYTES);
-        } else {
-            return charset.newEncoder()
-                .onMalformedInput(CodingErrorAction.REPORT)
-                .onUnmappableCharacter(CodingErrorAction.REPORT);
         }
+        return charset.newEncoder()
+            .onMalformedInput(CodingErrorAction.REPORT)
+            .onUnmappableCharacter(CodingErrorAction.REPORT);
     }
 
     private CharsetDecoder newDecoder() {
@@ -179,12 +178,11 @@ class NioZipEncoding implements ZipEncoding, CharsetAccessor {
             return this.charset.newDecoder()
                 .onMalformedInput(CodingErrorAction.REPORT)
                 .onUnmappableCharacter(CodingErrorAction.REPORT);
-        } else {
-            return  charset.newDecoder()
-                .onMalformedInput(CodingErrorAction.REPLACE)
-                .onUnmappableCharacter(CodingErrorAction.REPLACE)
-                .replaceWith(REPLACEMENT_STRING);
         }
+        return  charset.newDecoder()
+            .onMalformedInput(CodingErrorAction.REPLACE)
+            .onUnmappableCharacter(CodingErrorAction.REPLACE)
+            .replaceWith(REPLACEMENT_STRING);
     }
 
     /**


[commons-compress] 02/08: Remove unused import.

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-compress.git

commit 3c054726596c81459acf4c4c6be057f81d7924b1
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun Nov 1 08:46:29 2020 -0500

    Remove unused import.
---
 .../java/org/apache/commons/compress/archivers/examples/Archiver.java    | 1 -
 1 file changed, 1 deletion(-)

diff --git a/src/main/java/org/apache/commons/compress/archivers/examples/Archiver.java b/src/main/java/org/apache/commons/compress/archivers/examples/Archiver.java
index d87fa2d..8358753 100644
--- a/src/main/java/org/apache/commons/compress/archivers/examples/Archiver.java
+++ b/src/main/java/org/apache/commons/compress/archivers/examples/Archiver.java
@@ -34,7 +34,6 @@ import java.nio.file.StandardOpenOption;
 import java.nio.file.attribute.BasicFileAttributes;
 import java.util.EnumSet;
 import java.util.Objects;
-import java.util.function.BiConsumer;
 
 import org.apache.commons.compress.archivers.ArchiveEntry;
 import org.apache.commons.compress.archivers.ArchiveException;


[commons-compress] 06/08: Use try-with-resources.

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-compress.git

commit e0b11ec71dd1e9ae152b02015415c22608dc4a59
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun Nov 1 09:09:52 2020 -0500

    Use try-with-resources.
---
 .../archivers/zip/Maven221MultiVolumeTest.java     | 25 ++++++---------
 .../archivers/zip/X5455_ExtendedTimestampTest.java | 36 +++++++---------------
 .../compress/archivers/zip/X7875_NewUnixTest.java  |  8 +----
 3 files changed, 22 insertions(+), 47 deletions(-)

diff --git a/src/test/java/org/apache/commons/compress/archivers/zip/Maven221MultiVolumeTest.java b/src/test/java/org/apache/commons/compress/archivers/zip/Maven221MultiVolumeTest.java
index e8d8a62..a4a7be9 100644
--- a/src/test/java/org/apache/commons/compress/archivers/zip/Maven221MultiVolumeTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/zip/Maven221MultiVolumeTest.java
@@ -68,11 +68,8 @@ public class Maven221MultiVolumeTest {
     @Test
     public void testRead7ZipMultiVolumeArchiveForStream() throws IOException {
 
-        final FileInputStream archive =
-            new FileInputStream(getFile("apache-maven-2.2.1.zip.001"));
-        ZipArchiveInputStream zi = null;
-        try {
-            zi = new ZipArchiveInputStream(archive,null,false);
+        try (final FileInputStream archive = new FileInputStream(getFile("apache-maven-2.2.1.zip.001"));
+            ZipArchiveInputStream zi = new ZipArchiveInputStream(archive, null, false)) {
 
             // these are the entries that are supposed to be processed
             // correctly without any problems
@@ -83,14 +80,16 @@ public class Maven221MultiVolumeTest {
             // this is the last entry that is truncated
             final ArchiveEntry lastEntry = zi.getNextEntry();
             assertEquals(LAST_ENTRY_NAME, lastEntry.getName());
-            final byte [] buffer = new byte [4096];
+            final byte[] buffer = new byte[4096];
 
             // before the fix, we'd get 0 bytes on this read and all
             // subsequent reads thus a client application might enter
             // an infinite loop after the fix, we should get an
             // exception
             try {
-                while (zi.read(buffer) > 0) { }
+                while (zi.read(buffer) > 0) {
+                    // empty
+                }
                 fail("shouldn't be able to read from truncated entry");
             } catch (final IOException e) {
                 assertEquals("Truncated ZIP file", e.getMessage());
@@ -107,22 +106,18 @@ public class Maven221MultiVolumeTest {
             // an exception
             try {
                 zi.getNextEntry();
-                fail("shouldn't be able to read another entry from truncated"
-                     + " file");
+                fail("shouldn't be able to read another entry from truncated" + " file");
             } catch (final IOException e) {
                 // this is to be expected
             }
-        } finally {
-            if (zi != null) {
-                zi.close();
-            }
         }
     }
 
     @Test(expected=IOException.class)
     public void testRead7ZipMultiVolumeArchiveForFile() throws IOException {
         final File file = getFile("apache-maven-2.2.1.zip.001");
-        final ZipFile zf = new ZipFile(file);
-        zf.close();
+        try (final ZipFile zf = new ZipFile(file)) {
+            // empty
+        }
     }
 }
diff --git a/src/test/java/org/apache/commons/compress/archivers/zip/X5455_ExtendedTimestampTest.java b/src/test/java/org/apache/commons/compress/archivers/zip/X5455_ExtendedTimestampTest.java
index c89ec0a..5fa86c7 100644
--- a/src/test/java/org/apache/commons/compress/archivers/zip/X5455_ExtendedTimestampTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/zip/X5455_ExtendedTimestampTest.java
@@ -115,10 +115,8 @@ public class X5455_ExtendedTimestampTest {
          */
 
         final File archive = getFile("COMPRESS-210_unix_time_zip_test.zip");
-        ZipFile zf = null;
 
-        try {
-            zf = new ZipFile(archive);
+        try (ZipFile zf = new ZipFile(archive)) {
             final Enumeration<ZipArchiveEntry> en = zf.getEntries();
 
             // We expect EVERY entry of this zip file
@@ -189,10 +187,6 @@ public class X5455_ExtendedTimestampTest {
                     break;
                 }
             }
-        } finally {
-            if (zf != null) {
-                zf.close();
-            }
         }
     }
 
@@ -423,32 +417,24 @@ public class X5455_ExtendedTimestampTest {
     public void testWriteReadRoundtrip() throws IOException {
         tmpDir = mkdir("X5455");
         final File output = new File(tmpDir, "write_rewrite.zip");
-        final OutputStream out = new FileOutputStream(output);
         final Date d = new Date(97, 8, 24, 15, 10, 2);
-        ZipArchiveOutputStream os = null;
-        try {
-            os = new ZipArchiveOutputStream(out);
+        try (final OutputStream out = new FileOutputStream(output);
+            ZipArchiveOutputStream os = new ZipArchiveOutputStream(out)) {
             final ZipArchiveEntry ze = new ZipArchiveEntry("foo");
             xf.setModifyJavaTime(d);
             xf.setFlags((byte) 1);
             ze.addExtraField(xf);
             os.putArchiveEntry(ze);
             os.closeArchiveEntry();
-        } finally {
-            if (os != null) {
-                os.close();
-            }
         }
-        out.close();
-
-        final ZipFile zf = new ZipFile(output);
-        final ZipArchiveEntry ze = zf.getEntry("foo");
-        final X5455_ExtendedTimestamp ext =
-            (X5455_ExtendedTimestamp) ze.getExtraField(X5455);
-        assertNotNull(ext);
-        assertTrue(ext.isBit0_modifyTimePresent());
-        assertEquals(d, ext.getModifyJavaTime());
-        zf.close();
+
+        try (final ZipFile zf = new ZipFile(output)) {
+            final ZipArchiveEntry ze = zf.getEntry("foo");
+            final X5455_ExtendedTimestamp ext = (X5455_ExtendedTimestamp) ze.getExtraField(X5455);
+            assertNotNull(ext);
+            assertTrue(ext.isBit0_modifyTimePresent());
+            assertEquals(d, ext.getModifyJavaTime());
+        }
     }
 
     @Test
diff --git a/src/test/java/org/apache/commons/compress/archivers/zip/X7875_NewUnixTest.java b/src/test/java/org/apache/commons/compress/archivers/zip/X7875_NewUnixTest.java
index b148809..f18ec57 100644
--- a/src/test/java/org/apache/commons/compress/archivers/zip/X7875_NewUnixTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/zip/X7875_NewUnixTest.java
@@ -47,10 +47,8 @@ public class X7875_NewUnixTest {
     @Test
     public void testSampleFile() throws Exception {
         final File archive = getFile("COMPRESS-211_uid_gid_zip_test.zip");
-        ZipFile zf = null;
 
-        try {
-            zf = new ZipFile(archive);
+        try (ZipFile zf = new ZipFile(archive)) {
             final Enumeration<ZipArchiveEntry> en = zf.getEntries();
 
             // We expect EVERY entry of this zip file (dir & file) to
@@ -81,10 +79,6 @@ public class X7875_NewUnixTest {
                 assertEquals(expected, xf.getUID());
                 assertEquals(expected, xf.getGID());
             }
-        } finally {
-            if (zf != null) {
-                zf.close();
-            }
         }
     }
 


[commons-compress] 01/08: Use final.

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-compress.git

commit 82f740156c8f8c1f7d713ea33b5e9ab08b3ab3dc
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun Nov 1 08:45:51 2020 -0500

    Use final.
---
 .../java/org/apache/commons/compress/archivers/zip/ZipFileTest.java   | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/test/java/org/apache/commons/compress/archivers/zip/ZipFileTest.java b/src/test/java/org/apache/commons/compress/archivers/zip/ZipFileTest.java
index 6b6feee..955e15a 100644
--- a/src/test/java/org/apache/commons/compress/archivers/zip/ZipFileTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/zip/ZipFileTest.java
@@ -781,7 +781,7 @@ public class ZipFileTest {
         OutputStream outputStream = null;
         InputStream inputStream = null;
         final byte[] testData = new byte[]{1, 2, 3, 4};
-        byte[] buffer = new byte[512];
+        final byte[] buffer = new byte[512];
         int bytesRead;
         try (InputStream unzipsfxInputStream = new FileInputStream(unzipsfx)) {
             outputStream = new FileOutputStream(testZip);
@@ -791,7 +791,7 @@ public class ZipFileTest {
                 zo.writePreamble(buffer, 0, bytesRead);
             }
 
-            ZipArchiveEntry ze = new ZipArchiveEntry(testEntryName);
+            final ZipArchiveEntry ze = new ZipArchiveEntry(testEntryName);
             ze.setMethod(ZipEntry.STORED);
             ze.setSize(4);
             ze.setCrc(0xb63cfbcdL);


[commons-compress] 07/08: Fix Javadoc link.

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-compress.git

commit e21f1acc9660fb67d5992b254ff394d2f3959187
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun Nov 1 09:10:03 2020 -0500

    Fix Javadoc link.
---
 .../apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java b/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java
index 3d63bf2..02f0cf1 100644
--- a/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java
+++ b/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java
@@ -1324,7 +1324,7 @@ public class ZipArchiveOutputStream extends ArchiveOutputStream {
      * @param ze the entry to write
      * @throws IOException on error
      * @throws Zip64RequiredException if the archive's size exceeds 4
-     * GByte and {@link Zip64Mode #setUseZip64} is {@link
+     * GByte and {@link #setUseZip64(Zip64Mode)} is {@link
      * Zip64Mode#Never}.
      */
     protected void writeCentralFileHeader(final ZipArchiveEntry ze) throws IOException {
@@ -1503,7 +1503,7 @@ public class ZipArchiveOutputStream extends ArchiveOutputStream {
      * @throws IOException on error
      * @throws Zip64RequiredException if the archive's size exceeds 4
      * GByte or there are more than 65535 entries inside the archive
-     * and {@link Zip64Mode #setUseZip64} is {@link Zip64Mode#Never}.
+     * and {@link #setUseZip64(Zip64Mode)} is {@link Zip64Mode#Never}.
      */
     protected void writeCentralDirectoryEnd() throws IOException {
         if(!hasUsedZip64 && isSplitZip) {


[commons-compress] 05/08: No need to throw IOException from this private method.

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-compress.git

commit e61abc3e03482e3e08c5aaaa1c4ad57ddf6be383
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun Nov 1 08:58:46 2020 -0500

    No need to throw IOException from this private method.
---
 .../apache/commons/compress/archivers/tar/TarArchiveInputStream.java | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java b/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java
index cecef21..1f532b7 100644
--- a/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java
+++ b/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java
@@ -604,7 +604,7 @@ public class TarArchiveInputStream extends ArchiveInputStream {
      * giving the offset and size of the data block it describes.
      * @throws IOException
      */
-    private void paxHeaders() throws IOException{
+    private void paxHeaders() throws IOException {
         List<TarArchiveStructSparse> sparseHeaders = new ArrayList<>();
         final Map<String, String> headers = parsePaxHeaders(this, sparseHeaders);
 
@@ -636,9 +636,8 @@ public class TarArchiveInputStream extends ArchiveInputStream {
      *
      * @param sparseMap the sparse map string consisting of comma-separated values "offset,size[,offset-1,size-1...]"
      * @return sparse headers parsed from sparse map
-     * @throws IOException
      */
-    private List<TarArchiveStructSparse> parsePAX01SparseHeaders(final String sparseMap) throws IOException {
+    private List<TarArchiveStructSparse> parsePAX01SparseHeaders(final String sparseMap) {
         final List<TarArchiveStructSparse> sparseHeaders = new ArrayList<>();
         final String[] sparseHeaderStrings = sparseMap.split(",");
 


[commons-compress] 04/08: No need to throw UnsupportedEncodingException from this private method.

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-compress.git

commit d68da9b3193e5aaff195ba64eebe0d82a54a2745
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun Nov 1 08:54:18 2020 -0500

    No need to throw UnsupportedEncodingException from this private method.
---
 .../commons/compress/archivers/tar/TarArchiveOutputStream.java       | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStream.java b/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStream.java
index 68e8f51..bcf59b9 100644
--- a/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStream.java
+++ b/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStream.java
@@ -22,7 +22,6 @@ import java.io.File;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.io.StringWriter;
-import java.io.UnsupportedEncodingException;
 import java.nio.ByteBuffer;
 import java.nio.charset.StandardCharsets;
 import java.nio.file.LinkOption;
@@ -31,6 +30,7 @@ import java.util.Arrays;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.Map;
+
 import org.apache.commons.compress.archivers.ArchiveEntry;
 import org.apache.commons.compress.archivers.ArchiveOutputStream;
 import org.apache.commons.compress.archivers.zip.ZipEncoding;
@@ -486,8 +486,7 @@ public class TarArchiveOutputStream extends ArchiveOutputStream {
         closeArchiveEntry();
     }
 
-    private byte[] encodeExtendedPaxHeadersContents(final Map<String, String> headers)
-        throws UnsupportedEncodingException {
+    private byte[] encodeExtendedPaxHeadersContents(final Map<String, String> headers) {
         final StringWriter w = new StringWriter();
         for (final Map.Entry<String, String> h : headers.entrySet()) {
             final String key = h.getKey();