You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by se...@apache.org on 2013/04/17 15:03:13 UTC
svn commit: r1468885 - in
/commons/proper/io/trunk/src/main/java/org/apache/commons/io:
filefilter/MagicNumberFileFilter.java output/ByteArrayOutputStream.java
Author: sebb
Date: Wed Apr 17 13:03:12 2013
New Revision: 1468885
URL: http://svn.apache.org/r1468885
Log:
Make explicit where the default platform encoding is being used
Modified:
commons/proper/io/trunk/src/main/java/org/apache/commons/io/filefilter/MagicNumberFileFilter.java
commons/proper/io/trunk/src/main/java/org/apache/commons/io/output/ByteArrayOutputStream.java
Modified: commons/proper/io/trunk/src/main/java/org/apache/commons/io/filefilter/MagicNumberFileFilter.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/main/java/org/apache/commons/io/filefilter/MagicNumberFileFilter.java?rev=1468885&r1=1468884&r2=1468885&view=diff
==============================================================================
--- commons/proper/io/trunk/src/main/java/org/apache/commons/io/filefilter/MagicNumberFileFilter.java (original)
+++ commons/proper/io/trunk/src/main/java/org/apache/commons/io/filefilter/MagicNumberFileFilter.java Wed Apr 17 13:03:12 2013
@@ -20,6 +20,7 @@ import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.io.Serializable;
+import java.nio.charset.Charset;
import java.util.Arrays;
import org.apache.commons.io.IOUtils;
@@ -168,7 +169,7 @@ public class MagicNumberFileFilter exten
throw new IllegalArgumentException("The offset cannot be negative");
}
- this.magicNumbers = magicNumber.getBytes(); // uses the platform default charset
+ this.magicNumbers = magicNumber.getBytes(Charset.defaultCharset()); // explicitly uses the platform default charset
this.byteOffset = offset;
}
@@ -267,7 +268,7 @@ public class MagicNumberFileFilter exten
public String toString() {
final StringBuilder builder = new StringBuilder(super.toString());
builder.append("(");
- builder.append(new String(magicNumbers));// TODO perhaps use hex if value is not printable
+ builder.append(new String(magicNumbers, Charset.defaultCharset()));// TODO perhaps use hex if value is not printable
builder.append(",");
builder.append(this.byteOffset);
builder.append(")");
Modified: commons/proper/io/trunk/src/main/java/org/apache/commons/io/output/ByteArrayOutputStream.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/main/java/org/apache/commons/io/output/ByteArrayOutputStream.java?rev=1468885&r1=1468884&r2=1468885&view=diff
==============================================================================
--- commons/proper/io/trunk/src/main/java/org/apache/commons/io/output/ByteArrayOutputStream.java (original)
+++ commons/proper/io/trunk/src/main/java/org/apache/commons/io/output/ByteArrayOutputStream.java Wed Apr 17 13:03:12 2013
@@ -22,6 +22,7 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.io.SequenceInputStream;
import java.io.UnsupportedEncodingException;
+import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -336,13 +337,15 @@ public class ByteArrayOutputStream exten
}
/**
- * Gets the curent contents of this byte stream as a string.
+ * Gets the curent contents of this byte stream as a string
+ * using the platform default charset.
* @return the contents of the byte array as a String
* @see java.io.ByteArrayOutputStream#toString()
*/
@Override
public String toString() {
- return new String(toByteArray());
+ // make explicit the use of the default charset
+ return new String(toByteArray(), Charset.defaultCharset());
}
/**