[lang] Restore clirr report generation
Repository: commons-lang Updated Branches: refs/heads/master 4a300fee2 -> 1674c953f Restore clirr report generation Since commons-parent version 41, generation of the clirr report for the site has to be explicitly enabled by adding a "src\site\resources\profile.clirr" file. Project: http://git-wip-us.apache.org/repos/asf/commons-lang/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-lang/commit/1674c953 Tree: http://git-wip-us.apache.org/repos/asf/commons-lang/tree/1674c953 Diff: http://git-wip-us.apache.org/repos/asf/commons-lang/diff/1674c953 Branch: refs/heads/master Commit: 1674c953fafe6438952d6290f30143aab22f33dd Parents: 4a300fe Author: pascalschumacher Authored: Sun Mar 26 14:06:23 2017 +0200 Committer: pascalschumacher Committed: Sun Mar 26 14:06:23 2017 +0200 -- src/site/resources/profile.clirr | 0 1 file changed, 0 insertions(+), 0 deletions(-) -- http://git-wip-us.apache.org/repos/asf/commons-lang/blob/1674c953/src/site/resources/profile.clirr -- diff --git a/src/site/resources/profile.clirr b/src/site/resources/profile.clirr new file mode 100644 index 000..e69de29
commons-compress git commit: allow LZ77 algorithm to be tuned
Repository: commons-compress Updated Branches: refs/heads/master 5170392a5 -> 043f42b65 allow LZ77 algorithm to be tuned niceLen and maxCandidates are used in the same way as zlib's deflate algorithm. The configured values roughly correspond to zlib's compression levels 5 (tunedForSpeed), 7 (default) and 9 (tunedForCompressionRatio). Project: http://git-wip-us.apache.org/repos/asf/commons-compress/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-compress/commit/043f42b6 Tree: http://git-wip-us.apache.org/repos/asf/commons-compress/tree/043f42b6 Diff: http://git-wip-us.apache.org/repos/asf/commons-compress/diff/043f42b6 Branch: refs/heads/master Commit: 043f42b65d9c67fd064d2ba638b246389ad3a26d Parents: 5170392 Author: Stefan Bodewig Authored: Sun Mar 26 17:57:14 2017 +0200 Committer: Stefan Bodewig Committed: Sun Mar 26 17:57:14 2017 +0200 -- .../compressors/lz77support/LZ77Compressor.java | 6 +- .../compressors/lz77support/Parameters.java | 75 +++- .../lz4/BlockLZ4CompressorRoundtripTest.java| 29 +++- .../lz77support/LZ77CompressorTest.java | 2 +- .../compressors/snappy/SnappyRoundtripTest.java | 20 ++ 5 files changed, 125 insertions(+), 7 deletions(-) -- http://git-wip-us.apache.org/repos/asf/commons-compress/blob/043f42b6/src/main/java/org/apache/commons/compress/compressors/lz77support/LZ77Compressor.java -- diff --git a/src/main/java/org/apache/commons/compress/compressors/lz77support/LZ77Compressor.java b/src/main/java/org/apache/commons/compress/compressors/lz77support/LZ77Compressor.java index 487dee2..c284f4c 100644 --- a/src/main/java/org/apache/commons/compress/compressors/lz77support/LZ77Compressor.java +++ b/src/main/java/org/apache/commons/compress/compressors/lz77support/LZ77Compressor.java @@ -479,7 +479,9 @@ public class LZ77Compressor { int longestMatchLength = minLength - 1; final int maxPossibleLength = Math.min(params.getMaxBackReferenceLength(), lookahead); final int minIndex = Math.max(0, currentPosition - params.getMaxOffset()); -while (matchHead >= minIndex) { +final int niceBackReferenceLength = Math.min(maxPossibleLength, params.getNiceBackReferenceLength()); +final int maxCandidates = params.getMaxCandidates(); +for (int candidates = 0; candidates < maxCandidates && matchHead >= minIndex; candidates++) { int currentLength = 0; for (int i = 0; i < maxPossibleLength; i++) { if (window[matchHead + i] != window[currentPosition + i]) { @@ -490,7 +492,7 @@ public class LZ77Compressor { if (currentLength > longestMatchLength) { longestMatchLength = currentLength; matchStart = matchHead; -if (currentLength == maxPossibleLength) { +if (currentLength >= niceBackReferenceLength) { // no need to search any further break; } http://git-wip-us.apache.org/repos/asf/commons-compress/blob/043f42b6/src/main/java/org/apache/commons/compress/compressors/lz77support/Parameters.java -- diff --git a/src/main/java/org/apache/commons/compress/compressors/lz77support/Parameters.java b/src/main/java/org/apache/commons/compress/compressors/lz77support/Parameters.java index 3842dd9..e4e9e47 100644 --- a/src/main/java/org/apache/commons/compress/compressors/lz77support/Parameters.java +++ b/src/main/java/org/apache/commons/compress/compressors/lz77support/Parameters.java @@ -52,6 +52,7 @@ public final class Parameters { public static class Builder { private final int windowSize; private int minBackReferenceLength, maxBackReferenceLength, maxOffset, maxLiteralLength; +private Integer niceBackReferenceLength, maxCandidates; private Builder(int windowSize) { if (windowSize < 2 || !isPowerOfTwo(windowSize)) { @@ -150,24 +151,78 @@ public final class Parameters { } /** + * Sets the "nice length" of a back-reference. + * + * When a back-references if this size has been found, stop searching for longer back-references. + * + * This settings can be used to tune the tradeoff between compression speed and compression ratio. + */ +public Builder withNiceBackReferenceLength(int niceLen) { +niceBackReferenceLength = niceLen; +return this; +} + +/** + * Sets the maximum number of back-reference candidates that should be consulted. + * + * This settings can be used to tune the tradeoff between compression speed and compression ratio. +
commons-compress git commit: allow LZ77 tuning in framed snappy/lz4 streams as well
Repository: commons-compress Updated Branches: refs/heads/master 043f42b65 -> ad661a8d3 allow LZ77 tuning in framed snappy/lz4 streams as well Project: http://git-wip-us.apache.org/repos/asf/commons-compress/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-compress/commit/ad661a8d Tree: http://git-wip-us.apache.org/repos/asf/commons-compress/tree/ad661a8d Diff: http://git-wip-us.apache.org/repos/asf/commons-compress/diff/ad661a8d Branch: refs/heads/master Commit: ad661a8d347c1c0ff1b9264cf0f8c89de7057a69 Parents: 043f42b Author: Stefan Bodewig Authored: Sun Mar 26 18:55:34 2017 +0200 Committer: Stefan Bodewig Committed: Sun Mar 26 18:55:34 2017 +0200 -- .../lz4/FramedLZ4CompressorOutputStream.java| 36 +++- .../FramedSnappyCompressorOutputStream.java | 16 - .../lz4/FramedLZ4CompressorRoundtripTest.java | 4 +++ 3 files changed, 54 insertions(+), 2 deletions(-) -- http://git-wip-us.apache.org/repos/asf/commons-compress/blob/ad661a8d/src/main/java/org/apache/commons/compress/compressors/lz4/FramedLZ4CompressorOutputStream.java -- diff --git a/src/main/java/org/apache/commons/compress/compressors/lz4/FramedLZ4CompressorOutputStream.java b/src/main/java/org/apache/commons/compress/compressors/lz4/FramedLZ4CompressorOutputStream.java index 3ebcaa0..c08914f 100644 --- a/src/main/java/org/apache/commons/compress/compressors/lz4/FramedLZ4CompressorOutputStream.java +++ b/src/main/java/org/apache/commons/compress/compressors/lz4/FramedLZ4CompressorOutputStream.java @@ -88,6 +88,7 @@ public class FramedLZ4CompressorOutputStream extends CompressorOutputStream { public static class Parameters { private final BlockSize blockSize; private final boolean withContentChecksum, withBlockChecksum, withBlockDependency; +private final org.apache.commons.compress.compressors.lz77support.Parameters lz77params; /** * The default parameters of 4M block size, enabled content @@ -107,6 +108,16 @@ public class FramedLZ4CompressorOutputStream extends CompressorOutputStream { this(blockSize, true, false, false); } /** + * Sets up custom a custom block size for the LZ4 stream but + * otherwise uses the defaults of enabled content checksum, + * disabled block checksums and independent blocks. + * @param blockSize the size of a single block. + */ +public Parameters(BlockSize blockSize, +org.apache.commons.compress.compressors.lz77support.Parameters lz77params) { +this(blockSize, true, false, false, lz77params); +} +/** * Sets up custom parameters for the LZ4 stream. * @param blockSize the size of a single block. * @param withContentChecksum whether to write a content checksum @@ -120,10 +131,33 @@ public class FramedLZ4CompressorOutputStream extends CompressorOutputStream { */ public Parameters(BlockSize blockSize, boolean withContentChecksum, boolean withBlockChecksum, boolean withBlockDependency) { +this(blockSize, withContentChecksum, withBlockChecksum, withBlockDependency, + BlockLZ4CompressorOutputStream.createParameterBuilder().build()); +} + +/** + * Sets up custom parameters for the LZ4 stream. + * @param blockSize the size of a single block. + * @param withContentChecksum whether to write a content checksum + * @param withBlockChecksum whether to write a block checksum. + * Note that block checksums are not supported by the lz4 + * command line utility + * @param withBlockDependency whether a block may depend on + * the content of a previous block. Enabling this may improve + * compression ratio but makes it impossible to decompress the + * output in parallel. + * @param lz77 parameters parameters used to fine-tune + * compression, in particular to balance compression ration vs + * compression speed. + */ +public Parameters(BlockSize blockSize, boolean withContentChecksum, boolean withBlockChecksum, +boolean withBlockDependency, +org.apache.commons.compress.compressors.lz77support.Parameters lz77params) { this.blockSize = blockSize; this.withContentChecksum = withContentChecksum; this.withBlockChecksum = withBlockChecksum; this.withBlockDependency = withBlockDependency; +this.lz77params = lz77params; } @Override @@ -231,7 +265,7 @@ public class FramedLZ4CompressorOutputStream extends CompressorOutputStream { private void flushBlock() throws IOExcep
commons-compress git commit: missing Javadoc param and a typo
Repository: commons-compress Updated Branches: refs/heads/master ad661a8d3 -> d01a053d4 missing Javadoc param and a typo Project: http://git-wip-us.apache.org/repos/asf/commons-compress/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-compress/commit/d01a053d Tree: http://git-wip-us.apache.org/repos/asf/commons-compress/tree/d01a053d Diff: http://git-wip-us.apache.org/repos/asf/commons-compress/diff/d01a053d Branch: refs/heads/master Commit: d01a053d4f3ef9d791be2d5717de305e515be002 Parents: ad661a8 Author: Stefan Bodewig Authored: Sun Mar 26 19:01:31 2017 +0200 Committer: Stefan Bodewig Committed: Sun Mar 26 19:02:33 2017 +0200 -- .../compressors/lz4/FramedLZ4CompressorOutputStream.java| 9 ++--- .../snappy/FramedSnappyCompressorOutputStream.java | 3 +++ 2 files changed, 9 insertions(+), 3 deletions(-) -- http://git-wip-us.apache.org/repos/asf/commons-compress/blob/d01a053d/src/main/java/org/apache/commons/compress/compressors/lz4/FramedLZ4CompressorOutputStream.java -- diff --git a/src/main/java/org/apache/commons/compress/compressors/lz4/FramedLZ4CompressorOutputStream.java b/src/main/java/org/apache/commons/compress/compressors/lz4/FramedLZ4CompressorOutputStream.java index c08914f..75bc5ea 100644 --- a/src/main/java/org/apache/commons/compress/compressors/lz4/FramedLZ4CompressorOutputStream.java +++ b/src/main/java/org/apache/commons/compress/compressors/lz4/FramedLZ4CompressorOutputStream.java @@ -112,6 +112,9 @@ public class FramedLZ4CompressorOutputStream extends CompressorOutputStream { * otherwise uses the defaults of enabled content checksum, * disabled block checksums and independent blocks. * @param blockSize the size of a single block. + * @param lz77params lz77 parameters parameters used to + * fine-tune compression, in particular to balance compression + * ratio vs compression speed. */ public Parameters(BlockSize blockSize, org.apache.commons.compress.compressors.lz77support.Parameters lz77params) { @@ -146,9 +149,9 @@ public class FramedLZ4CompressorOutputStream extends CompressorOutputStream { * the content of a previous block. Enabling this may improve * compression ratio but makes it impossible to decompress the * output in parallel. - * @param lz77 parameters parameters used to fine-tune - * compression, in particular to balance compression ration vs - * compression speed. + * @param lz77params lz77 parameters parameters used to + * fine-tune compression, in particular to balance compression + * ratio vs compression speed. */ public Parameters(BlockSize blockSize, boolean withContentChecksum, boolean withBlockChecksum, boolean withBlockDependency, http://git-wip-us.apache.org/repos/asf/commons-compress/blob/d01a053d/src/main/java/org/apache/commons/compress/compressors/snappy/FramedSnappyCompressorOutputStream.java -- diff --git a/src/main/java/org/apache/commons/compress/compressors/snappy/FramedSnappyCompressorOutputStream.java b/src/main/java/org/apache/commons/compress/compressors/snappy/FramedSnappyCompressorOutputStream.java index fdb5699..8f34655 100644 --- a/src/main/java/org/apache/commons/compress/compressors/snappy/FramedSnappyCompressorOutputStream.java +++ b/src/main/java/org/apache/commons/compress/compressors/snappy/FramedSnappyCompressorOutputStream.java @@ -67,6 +67,9 @@ public class FramedSnappyCompressorOutputStream extends CompressorOutputStream { * Constructs a new output stream that compresses * snappy-framed-compressed data to the specified output stream. * @param out the OutputStream to which to write the compressed data + * @param params lz77 parameters parameters used to fine-tune + * compression, in particular to balance compression ratio vs + * compression speed. * @throws IOException if writing the signature fails */ public FramedSnappyCompressorOutputStream(final OutputStream out, Parameters params) throws IOException {
commons-compress git commit: try to make sense in javadocs
Repository: commons-compress Updated Branches: refs/heads/master d01a053d4 -> 785233a6f try to make sense in javadocs Project: http://git-wip-us.apache.org/repos/asf/commons-compress/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-compress/commit/785233a6 Tree: http://git-wip-us.apache.org/repos/asf/commons-compress/tree/785233a6 Diff: http://git-wip-us.apache.org/repos/asf/commons-compress/diff/785233a6 Branch: refs/heads/master Commit: 785233a6fe47009e8b92db72e778f7932db978cd Parents: d01a053 Author: Stefan Bodewig Authored: Sun Mar 26 19:04:33 2017 +0200 Committer: Stefan Bodewig Committed: Sun Mar 26 19:04:33 2017 +0200 -- .../lz4/FramedLZ4CompressorOutputStream.java| 12 ++-- .../snappy/FramedSnappyCompressorOutputStream.java | 5 ++--- 2 files changed, 8 insertions(+), 9 deletions(-) -- http://git-wip-us.apache.org/repos/asf/commons-compress/blob/785233a6/src/main/java/org/apache/commons/compress/compressors/lz4/FramedLZ4CompressorOutputStream.java -- diff --git a/src/main/java/org/apache/commons/compress/compressors/lz4/FramedLZ4CompressorOutputStream.java b/src/main/java/org/apache/commons/compress/compressors/lz4/FramedLZ4CompressorOutputStream.java index 75bc5ea..51e4a2a 100644 --- a/src/main/java/org/apache/commons/compress/compressors/lz4/FramedLZ4CompressorOutputStream.java +++ b/src/main/java/org/apache/commons/compress/compressors/lz4/FramedLZ4CompressorOutputStream.java @@ -112,9 +112,9 @@ public class FramedLZ4CompressorOutputStream extends CompressorOutputStream { * otherwise uses the defaults of enabled content checksum, * disabled block checksums and independent blocks. * @param blockSize the size of a single block. - * @param lz77params lz77 parameters parameters used to - * fine-tune compression, in particular to balance compression - * ratio vs compression speed. + * @param lz77params parameters used to fine-tune compression, + * in particular to balance compression ratio vs compression + * speed. */ public Parameters(BlockSize blockSize, org.apache.commons.compress.compressors.lz77support.Parameters lz77params) { @@ -149,9 +149,9 @@ public class FramedLZ4CompressorOutputStream extends CompressorOutputStream { * the content of a previous block. Enabling this may improve * compression ratio but makes it impossible to decompress the * output in parallel. - * @param lz77params lz77 parameters parameters used to - * fine-tune compression, in particular to balance compression - * ratio vs compression speed. + * @param lz77params parameters used to fine-tune compression, + * in particular to balance compression ratio vs compression + * speed. */ public Parameters(BlockSize blockSize, boolean withContentChecksum, boolean withBlockChecksum, boolean withBlockDependency, http://git-wip-us.apache.org/repos/asf/commons-compress/blob/785233a6/src/main/java/org/apache/commons/compress/compressors/snappy/FramedSnappyCompressorOutputStream.java -- diff --git a/src/main/java/org/apache/commons/compress/compressors/snappy/FramedSnappyCompressorOutputStream.java b/src/main/java/org/apache/commons/compress/compressors/snappy/FramedSnappyCompressorOutputStream.java index 8f34655..290fc01 100644 --- a/src/main/java/org/apache/commons/compress/compressors/snappy/FramedSnappyCompressorOutputStream.java +++ b/src/main/java/org/apache/commons/compress/compressors/snappy/FramedSnappyCompressorOutputStream.java @@ -67,9 +67,8 @@ public class FramedSnappyCompressorOutputStream extends CompressorOutputStream { * Constructs a new output stream that compresses * snappy-framed-compressed data to the specified output stream. * @param out the OutputStream to which to write the compressed data - * @param params lz77 parameters parameters used to fine-tune - * compression, in particular to balance compression ratio vs - * compression speed. + * @param params parameters used to fine-tune compression, in + * particular to balance compression ratio vs compression speed. * @throws IOException if writing the signature fails */ public FramedSnappyCompressorOutputStream(final OutputStream out, Parameters params) throws IOException {
svn commit: r1788755 - in /commons/proper/codec/trunk/src: changes/changes.xml main/java/org/apache/commons/codec/binary/StringUtils.java test/java/org/apache/commons/codec/binary/StringUtilsTest.java
Author: sebb Date: Sun Mar 26 17:22:08 2017 New Revision: 1788755 URL: http://svn.apache.org/viewvc?rev=1788755&view=rev Log: CODEC-229 StringUtils.newStringxxx(null) should return null, not NPE Modified: commons/proper/codec/trunk/src/changes/changes.xml commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/binary/StringUtils.java commons/proper/codec/trunk/src/test/java/org/apache/commons/codec/binary/StringUtilsTest.java Modified: commons/proper/codec/trunk/src/changes/changes.xml URL: http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/changes/changes.xml?rev=1788755&r1=1788754&r2=1788755&view=diff == --- commons/proper/codec/trunk/src/changes/changes.xml (original) +++ commons/proper/codec/trunk/src/changes/changes.xml Sun Mar 26 17:22:08 2017 @@ -42,9 +42,10 @@ The type attribute can be add,u Apache Commons Developers - + + StringUtils.newStringxxx(null) should return null, not NPE Fluent interface for DigestUtils Fluent interface for HmacUtils Fix minor resource leaks Modified: commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/binary/StringUtils.java URL: http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/binary/StringUtils.java?rev=1788755&r1=1788754&r2=1788755&view=diff == --- commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/binary/StringUtils.java (original) +++ commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/binary/StringUtils.java Sun Mar 26 17:22:08 2017 @@ -336,7 +336,7 @@ public class StringUtils { * @since As of 1.7, throws {@link NullPointerException} instead of UnsupportedEncodingException */ public static String newStringIso8859_1(final byte[] bytes) { -return new String(bytes, Charsets.ISO_8859_1); +return newString(bytes, Charsets.ISO_8859_1); } /** @@ -352,7 +352,7 @@ public class StringUtils { * @since As of 1.7, throws {@link NullPointerException} instead of UnsupportedEncodingException */ public static String newStringUsAscii(final byte[] bytes) { -return new String(bytes, Charsets.US_ASCII); +return newString(bytes, Charsets.US_ASCII); } /** @@ -368,7 +368,7 @@ public class StringUtils { * @since As of 1.7, throws {@link NullPointerException} instead of UnsupportedEncodingException */ public static String newStringUtf16(final byte[] bytes) { -return new String(bytes, Charsets.UTF_16); +return newString(bytes, Charsets.UTF_16); } /** @@ -384,7 +384,7 @@ public class StringUtils { * @since As of 1.7, throws {@link NullPointerException} instead of UnsupportedEncodingException */ public static String newStringUtf16Be(final byte[] bytes) { -return new String(bytes, Charsets.UTF_16BE); +return newString(bytes, Charsets.UTF_16BE); } /** @@ -400,7 +400,7 @@ public class StringUtils { * @since As of 1.7, throws {@link NullPointerException} instead of UnsupportedEncodingException */ public static String newStringUtf16Le(final byte[] bytes) { -return new String(bytes, Charsets.UTF_16LE); +return newString(bytes, Charsets.UTF_16LE); } /** Modified: commons/proper/codec/trunk/src/test/java/org/apache/commons/codec/binary/StringUtilsTest.java URL: http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/test/java/org/apache/commons/codec/binary/StringUtilsTest.java?rev=1788755&r1=1788754&r2=1788755&view=diff == --- commons/proper/codec/trunk/src/test/java/org/apache/commons/codec/binary/StringUtilsTest.java (original) +++ commons/proper/codec/trunk/src/test/java/org/apache/commons/codec/binary/StringUtilsTest.java Sun Mar 26 17:22:08 2017 @@ -146,6 +146,16 @@ public class StringUtilsTest { } @Test +public void testNewStringNullInput_CODEC229() { +Assert.assertNull(StringUtils.newStringUtf8(null)); +Assert.assertNull(StringUtils.newStringIso8859_1(null)); +Assert.assertNull(StringUtils.newStringUsAscii(null)); +Assert.assertNull(StringUtils.newStringUtf16(null)); +Assert.assertNull(StringUtils.newStringUtf16Be(null)); +Assert.assertNull(StringUtils.newStringUtf16Le(null)); +} + +@Test public void testNewStringIso8859_1() throws UnsupportedEncodingException { final String charsetName = "ISO-8859-1"; testNewString(charsetName);
svn commit: r1788757 - /commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/binary/StringUtils.java
Author: sebb Date: Sun Mar 26 17:31:00 2017 New Revision: 1788757 URL: http://svn.apache.org/viewvc?rev=1788757&view=rev Log: Incorrect Javadoc Modified: commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/binary/StringUtils.java Modified: commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/binary/StringUtils.java URL: http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/binary/StringUtils.java?rev=1788757&r1=1788756&r2=1788757&view=diff == --- commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/binary/StringUtils.java (original) +++ commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/binary/StringUtils.java Sun Mar 26 17:31:00 2017 @@ -285,9 +285,6 @@ public class StringUtils { *The {@link Charset} to encode the String * @return A new String decoded from the specified array of bytes using the given charset, * or null if the input byte array was null. - * @throws NullPointerException - * Thrown if {@link Charsets#UTF_8} is not initialized, which should never happen since it is - * required by the Java platform specification. */ private static String newString(final byte[] bytes, final Charset charset) { return bytes == null ? null : new String(bytes, charset);
svn commit: r1788758 - /commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/binary/StringUtils.java
Author: sebb Date: Sun Mar 26 17:38:43 2017 New Revision: 1788758 URL: http://svn.apache.org/viewvc?rev=1788758&view=rev Log: Better Javadoc Modified: commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/binary/StringUtils.java Modified: commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/binary/StringUtils.java URL: http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/binary/StringUtils.java?rev=1788758&r1=1788757&r2=1788758&view=diff == --- commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/binary/StringUtils.java (original) +++ commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/binary/StringUtils.java Sun Mar 26 17:38:43 2017 @@ -282,9 +282,11 @@ public class StringUtils { * @param bytes *The bytes to be decoded into characters * @param charset - *The {@link Charset} to encode the String + *The {@link Charset} to encode the String; not {@code null} * @return A new String decoded from the specified array of bytes using the given charset, * or null if the input byte array was null. + * @throws NullPointerException + * Thrown if charset is {@code null} */ private static String newString(final byte[] bytes, final Charset charset) { return bytes == null ? null : new String(bytes, charset);
svn commit: r1788760 - /commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/net/URLCodec.java
Author: sebb Date: Sun Mar 26 18:26:07 2017 New Revision: 1788760 URL: http://svn.apache.org/viewvc?rev=1788760&view=rev Log: Docn Modified: commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/net/URLCodec.java Modified: commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/net/URLCodec.java URL: http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/net/URLCodec.java?rev=1788760&r1=1788759&r2=1788760&view=diff == --- commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/net/URLCodec.java (original) +++ commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/net/URLCodec.java Sun Mar 26 18:26:07 2017 @@ -55,7 +55,7 @@ public class URLCodec implements BinaryE /** * The default charset used for string decoding and encoding. * - * @deprecated TODO: This field will be changed to a private final Charset in 2.0. + * @deprecated TODO: This field will be changed to a private final Charset in 2.0. (CODEC-126) */ @Deprecated protected String charset;
svn commit: r1788761 - in /commons/proper/codec/trunk/src: changes/changes.xml main/java/org/apache/commons/codec/net/URLCodec.java
Author: sebb Date: Sun Mar 26 18:34:51 2017 New Revision: 1788761 URL: http://svn.apache.org/viewvc?rev=1788761&view=rev Log: CODEC-230 URLCodec.WWW_FORM_URL should be private Modified: commons/proper/codec/trunk/src/changes/changes.xml commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/net/URLCodec.java Modified: commons/proper/codec/trunk/src/changes/changes.xml URL: http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/changes/changes.xml?rev=1788761&r1=1788760&r2=1788761&view=diff == --- commons/proper/codec/trunk/src/changes/changes.xml (original) +++ commons/proper/codec/trunk/src/changes/changes.xml Sun Mar 26 18:34:51 2017 @@ -45,6 +45,7 @@ The type attribute can be add,u + URLCodec.WWW_FORM_URL should be private StringUtils.newStringxxx(null) should return null, not NPE Fluent interface for DigestUtils Fluent interface for HmacUtils Modified: commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/net/URLCodec.java URL: http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/net/URLCodec.java?rev=1788761&r1=1788760&r2=1788761&view=diff == --- commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/net/URLCodec.java (original) +++ commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/net/URLCodec.java Sun Mar 26 18:34:51 2017 @@ -64,31 +64,39 @@ public class URLCodec implements BinaryE * Release 1.5 made this field final. */ protected static final byte ESCAPE_CHAR = '%'; + /** * BitSet of www-form-url safe characters. + * @deprecated Will be removed in 2.0 (CODEC-230) */ -protected static final BitSet WWW_FORM_URL = new BitSet(256); +@Deprecated +protected static final BitSet WWW_FORM_URL; + +private static final BitSet WWW_FORM_URL_SAFE = new BitSet(256); // Static initializer for www_form_url static { // alpha characters for (int i = 'a'; i <= 'z'; i++) { -WWW_FORM_URL.set(i); +WWW_FORM_URL_SAFE.set(i); } for (int i = 'A'; i <= 'Z'; i++) { -WWW_FORM_URL.set(i); +WWW_FORM_URL_SAFE.set(i); } // numeric characters for (int i = '0'; i <= '9'; i++) { -WWW_FORM_URL.set(i); +WWW_FORM_URL_SAFE.set(i); } // special chars -WWW_FORM_URL.set('-'); -WWW_FORM_URL.set('_'); -WWW_FORM_URL.set('.'); -WWW_FORM_URL.set('*'); +WWW_FORM_URL_SAFE.set('-'); +WWW_FORM_URL_SAFE.set('_'); +WWW_FORM_URL_SAFE.set('.'); +WWW_FORM_URL_SAFE.set('*'); // blank to be replaced with + -WWW_FORM_URL.set(' '); +WWW_FORM_URL_SAFE.set(' '); + +// Create a copy in case anyone (ab)uses it +WWW_FORM_URL = (BitSet) WWW_FORM_URL_SAFE.clone(); } @@ -123,7 +131,7 @@ public class URLCodec implements BinaryE return null; } if (urlsafe == null) { -urlsafe = WWW_FORM_URL; +urlsafe = WWW_FORM_URL_SAFE; } final ByteArrayOutputStream buffer = new ByteArrayOutputStream(); @@ -191,7 +199,7 @@ public class URLCodec implements BinaryE */ @Override public byte[] encode(final byte[] bytes) { -return encodeUrl(WWW_FORM_URL, bytes); +return encodeUrl(WWW_FORM_URL_SAFE, bytes); }
svn commit: r1788777 - in /commons/proper/codec/trunk/src: changes/changes.xml main/java/org/apache/commons/codec/binary/StringUtils.java test/java/org/apache/commons/codec/binary/StringUtilsTest.java
Author: sebb Date: Sun Mar 26 21:43:36 2017 New Revision: 1788777 URL: http://svn.apache.org/viewvc?rev=1788777&view=rev Log: CODEC-231 StringUtils.equals(CharSequence cs1, CharSequence cs2) can fail with String Index OBE Modified: commons/proper/codec/trunk/src/changes/changes.xml commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/binary/StringUtils.java commons/proper/codec/trunk/src/test/java/org/apache/commons/codec/binary/StringUtilsTest.java Modified: commons/proper/codec/trunk/src/changes/changes.xml URL: http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/changes/changes.xml?rev=1788777&r1=1788776&r2=1788777&view=diff == --- commons/proper/codec/trunk/src/changes/changes.xml (original) +++ commons/proper/codec/trunk/src/changes/changes.xml Sun Mar 26 21:43:36 2017 @@ -45,6 +45,7 @@ The type attribute can be add,u + StringUtils.equals(CharSequence cs1, CharSequence cs2) can fail with String Index OBE URLCodec.WWW_FORM_URL should be private StringUtils.newStringxxx(null) should return null, not NPE Fluent interface for DigestUtils Modified: commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/binary/StringUtils.java URL: http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/binary/StringUtils.java?rev=1788777&r1=1788776&r2=1788777&view=diff == --- commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/binary/StringUtils.java (original) +++ commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/binary/StringUtils.java Sun Mar 26 21:43:36 2017 @@ -78,7 +78,7 @@ public class StringUtils { if (cs1 instanceof String && cs2 instanceof String) { return cs1.equals(cs2); } -return CharSequenceUtils.regionMatches(cs1, false, 0, cs2, 0, Math.max(cs1.length(), cs2.length())); +return cs1.length() == cs2.length() && CharSequenceUtils.regionMatches(cs1, false, 0, cs2, 0, cs1.length()); } /** Modified: commons/proper/codec/trunk/src/test/java/org/apache/commons/codec/binary/StringUtilsTest.java URL: http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/test/java/org/apache/commons/codec/binary/StringUtilsTest.java?rev=1788777&r1=1788776&r2=1788777&view=diff == --- commons/proper/codec/trunk/src/test/java/org/apache/commons/codec/binary/StringUtilsTest.java (original) +++ commons/proper/codec/trunk/src/test/java/org/apache/commons/codec/binary/StringUtilsTest.java Sun Mar 26 21:43:36 2017 @@ -208,4 +208,33 @@ public class StringUtilsTest { final String actual = StringUtils.newStringUtf8(BYTES_FIXTURE); Assert.assertEquals(expected, actual); } + +@Test +public void testEqualsString() { +Assert.assertTrue(StringUtils.equals(null, null)); +Assert.assertFalse(StringUtils.equals("abc", null)); +Assert.assertFalse(StringUtils.equals(null, "abc")); +Assert.assertTrue(StringUtils.equals("abc", "abc")); +Assert.assertFalse(StringUtils.equals("abc", "abcd")); +Assert.assertFalse(StringUtils.equals("abcd", "abc")); +Assert.assertFalse(StringUtils.equals("abc", "ABC")); +} + +@Test +public void testEqualsCS1() { +Assert.assertFalse(StringUtils.equals(new StringBuilder("abc"), null)); +Assert.assertFalse(StringUtils.equals(null, new StringBuilder("abc"))); +Assert.assertTrue(StringUtils.equals(new StringBuilder("abc"), new StringBuilder("abc"))); +Assert.assertFalse(StringUtils.equals(new StringBuilder("abc"), new StringBuilder("abcd"))); +Assert.assertFalse(StringUtils.equals(new StringBuilder("abcd"), new StringBuilder("abc"))); +Assert.assertFalse(StringUtils.equals(new StringBuilder("abc"), new StringBuilder("ABC"))); +} + +@Test +public void testEqualsCS2() { +Assert.assertTrue(StringUtils.equals("abc", new StringBuilder("abc"))); +Assert.assertFalse(StringUtils.equals(new StringBuilder("abc"), "abcd")); +Assert.assertFalse(StringUtils.equals("abcd", new StringBuilder("abc"))); +Assert.assertFalse(StringUtils.equals(new StringBuilder("abc"), "ABC")); +} }
svn commit: r1788792 - in /commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/net: QuotedPrintableCodec.java URLCodec.java Utils.java
Author: sebb Date: Sun Mar 26 23:57:00 2017 New Revision: 1788792 URL: http://svn.apache.org/viewvc?rev=1788792&view=rev Log: Centralise conversion to hex digit Modified: commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/net/QuotedPrintableCodec.java commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/net/URLCodec.java commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/net/Utils.java Modified: commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/net/QuotedPrintableCodec.java URL: http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/net/QuotedPrintableCodec.java?rev=1788792&r1=1788791&r2=1788792&view=diff == --- commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/net/QuotedPrintableCodec.java (original) +++ commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/net/QuotedPrintableCodec.java Sun Mar 26 23:57:00 2017 @@ -181,8 +181,8 @@ public class QuotedPrintableCodec implem */ private static final int encodeQuotedPrintable(final int b, final ByteArrayOutputStream buffer) { buffer.write(ESCAPE_CHAR); -final char hex1 = Character.toUpperCase(Character.forDigit((b >> 4) & 0xF, 16)); -final char hex2 = Character.toUpperCase(Character.forDigit(b & 0xF, 16)); +final char hex1 = Utils.hexDigit(b >> 4); +final char hex2 = Utils.hexDigit(b); buffer.write(hex1); buffer.write(hex2); return 3; Modified: commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/net/URLCodec.java URL: http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/net/URLCodec.java?rev=1788792&r1=1788791&r2=1788792&view=diff == --- commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/net/URLCodec.java (original) +++ commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/net/URLCodec.java Sun Mar 26 23:57:00 2017 @@ -48,11 +48,6 @@ import org.apache.commons.codec.binary.S public class URLCodec implements BinaryEncoder, BinaryDecoder, StringEncoder, StringDecoder { /** - * Radix used in encoding and decoding. - */ -static final int RADIX = 16; - -/** * The default charset used for string decoding and encoding. * * @deprecated TODO: This field will be changed to a private final Charset in 2.0. (CODEC-126) @@ -147,8 +142,8 @@ public class URLCodec implements BinaryE buffer.write(b); } else { buffer.write(ESCAPE_CHAR); -final char hex1 = Character.toUpperCase(Character.forDigit((b >> 4) & 0xF, RADIX)); -final char hex2 = Character.toUpperCase(Character.forDigit(b & 0xF, RADIX)); +final char hex1 = Utils.hexDigit(b >> 4); +final char hex2 = Utils.hexDigit(b); buffer.write(hex1); buffer.write(hex2); } Modified: commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/net/Utils.java URL: http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/net/Utils.java?rev=1788792&r1=1788791&r2=1788792&view=diff == --- commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/net/Utils.java (original) +++ commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/net/Utils.java Sun Mar 26 23:57:00 2017 @@ -30,6 +30,11 @@ import org.apache.commons.codec.DecoderE class Utils { /** + * Radix used in encoding and decoding. + */ +private static final int RADIX = 16; + +/** * Returns the numeric value of the character b in radix 16. * * @param b @@ -40,11 +45,21 @@ class Utils { * Thrown when the byte is not valid per {@link Character#digit(char,int)} */ static int digit16(final byte b) throws DecoderException { -final int i = Character.digit((char) b, URLCodec.RADIX); +final int i = Character.digit((char) b, RADIX); if (i == -1) { -throw new DecoderException("Invalid URL encoding: not a valid digit (radix " + URLCodec.RADIX + "): " + b); +throw new DecoderException("Invalid URL encoding: not a valid digit (radix " + RADIX + "): " + b); } return i; } +/** + * Returns the upper case hex digit of the lower 4 bits of the int. + * + * @param b the input int + * @return the upper case hex digit of the lower 4 bits of the int. + */ +static char hexDigit(int b) { +return Character.toUpperCase(Character.forDigit(b & 0xF, RADIX)); +} + }