Repository: maven-resolver Updated Branches: refs/heads/MRESOLVER-6 [created] a05222b5e
[MRESOLVER-6] Use java.nio.charset.StandardCharsets wherever possible Project: http://git-wip-us.apache.org/repos/asf/maven-resolver/repo Commit: http://git-wip-us.apache.org/repos/asf/maven-resolver/commit/a05222b5 Tree: http://git-wip-us.apache.org/repos/asf/maven-resolver/tree/a05222b5 Diff: http://git-wip-us.apache.org/repos/asf/maven-resolver/diff/a05222b5 Branch: refs/heads/MRESOLVER-6 Commit: a05222b5ea377cdbbf42fd509eda0f5588041eba Parents: 5fae685 Author: Michael Osipov <micha...@apache.org> Authored: Mon Oct 31 23:10:27 2016 +0100 Committer: Michael Osipov <micha...@apache.org> Committed: Thu May 11 23:48:03 2017 +0200 ---------------------------------------------------------------------- .../aether/repository/AuthenticationDigest.java | 11 ++-------- .../connector/basic/ChecksumCalculatorTest.java | 10 ++------- .../internal/impl/DefaultFileProcessor.java | 3 ++- .../aether/internal/impl/SimpleDigest.java | 10 ++------- .../internal/impl/DefaultInstallerTest.java | 3 +-- .../internal/impl/TrackingFileManagerTest.java | 3 ++- .../aether/spi/connector/transport/GetTask.java | 14 ++++-------- .../aether/spi/connector/transport/PutTask.java | 16 +++++--------- .../test/util/DependencyGraphParser.java | 8 +++---- .../test/util/IniArtifactDataReader.java | 3 ++- .../internal/test/util/TestFileProcessor.java | 3 ++- .../internal/test/util/TestFileUtils.java | 7 +++--- .../test/util/DependencyGraphParserTest.java | 5 ++--- .../classpath/ClasspathTransporterTest.java | 7 +++--- .../transport/file/FileTransporterTest.java | 7 +++--- .../aether/transport/http/HttpServer.java | 1 + .../transport/http/HttpTransporterTest.java | 23 ++++++++++---------- .../wagon/AbstractWagonTransporterTest.java | 7 +++--- .../aether/transport/wagon/MemStreamWagon.java | 22 +++---------------- .../aether/transport/wagon/MemWagon.java | 22 +++---------------- .../org/eclipse/aether/util/ChecksumUtils.java | 7 +++--- .../eclipse/aether/util/ChecksumUtilTest.java | 3 ++- 22 files changed, 70 insertions(+), 125 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/a05222b5/maven-resolver-api/src/main/java/org/eclipse/aether/repository/AuthenticationDigest.java ---------------------------------------------------------------------- diff --git a/maven-resolver-api/src/main/java/org/eclipse/aether/repository/AuthenticationDigest.java b/maven-resolver-api/src/main/java/org/eclipse/aether/repository/AuthenticationDigest.java index 03725b6..e186060 100644 --- a/maven-resolver-api/src/main/java/org/eclipse/aether/repository/AuthenticationDigest.java +++ b/maven-resolver-api/src/main/java/org/eclipse/aether/repository/AuthenticationDigest.java @@ -19,7 +19,7 @@ package org.eclipse.aether.repository; * under the License. */ -import java.io.UnsupportedEncodingException; +import java.nio.charset.StandardCharsets; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; @@ -157,14 +157,7 @@ public final class AuthenticationDigest { if ( string != null ) { - try - { - digest.update( string.getBytes( "UTF-8" ) ); - } - catch ( UnsupportedEncodingException e ) - { - throw new IllegalStateException( e ); - } + digest.update( string.getBytes( StandardCharsets.UTF_8 ) ); } } } http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/a05222b5/maven-resolver-connector-basic/src/test/java/org/eclipse/aether/connector/basic/ChecksumCalculatorTest.java ---------------------------------------------------------------------- diff --git a/maven-resolver-connector-basic/src/test/java/org/eclipse/aether/connector/basic/ChecksumCalculatorTest.java b/maven-resolver-connector-basic/src/test/java/org/eclipse/aether/connector/basic/ChecksumCalculatorTest.java index 0dc43af..616eb1d 100644 --- a/maven-resolver-connector-basic/src/test/java/org/eclipse/aether/connector/basic/ChecksumCalculatorTest.java +++ b/maven-resolver-connector-basic/src/test/java/org/eclipse/aether/connector/basic/ChecksumCalculatorTest.java @@ -26,6 +26,7 @@ import java.io.IOException; import java.io.UnsupportedEncodingException; import java.net.URI; import java.nio.ByteBuffer; +import java.nio.charset.StandardCharsets; import java.security.NoSuchAlgorithmException; import java.util.ArrayList; import java.util.List; @@ -57,14 +58,7 @@ public class ChecksumCalculatorTest private ByteBuffer toBuffer( String data ) { - try - { - return ByteBuffer.wrap( data.getBytes( "UTF-8" ) ); - } - catch ( UnsupportedEncodingException e ) - { - throw new IllegalStateException( e ); - } + return ByteBuffer.wrap( data.getBytes( StandardCharsets.UTF_8 ) ); } @Before http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/a05222b5/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultFileProcessor.java ---------------------------------------------------------------------- diff --git a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultFileProcessor.java b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultFileProcessor.java index a77e353..eb2226d 100644 --- a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultFileProcessor.java +++ b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultFileProcessor.java @@ -26,6 +26,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.nio.ByteBuffer; +import java.nio.charset.StandardCharsets; import javax.inject.Named; @@ -90,7 +91,7 @@ public class DefaultFileProcessor if ( data != null ) { - out.write( data.getBytes( "UTF-8" ) ); + out.write( data.getBytes( StandardCharsets.UTF_8 ) ); } out.close(); http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/a05222b5/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/SimpleDigest.java ---------------------------------------------------------------------- diff --git a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/SimpleDigest.java b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/SimpleDigest.java index 9b51e98..d948ac3 100644 --- a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/SimpleDigest.java +++ b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/SimpleDigest.java @@ -20,6 +20,7 @@ package org.eclipse.aether.internal.impl; */ import java.io.UnsupportedEncodingException; +import java.nio.charset.StandardCharsets; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; @@ -61,14 +62,7 @@ class SimpleDigest } if ( digest != null ) { - try - { - digest.update( data.getBytes( "UTF-8" ) ); - } - catch ( UnsupportedEncodingException e ) - { - // broken JVM - } + digest.update( data.getBytes( StandardCharsets.UTF_8 ) ); } else { http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/a05222b5/maven-resolver-impl/src/test/java/org/eclipse/aether/internal/impl/DefaultInstallerTest.java ---------------------------------------------------------------------- diff --git a/maven-resolver-impl/src/test/java/org/eclipse/aether/internal/impl/DefaultInstallerTest.java b/maven-resolver-impl/src/test/java/org/eclipse/aether/internal/impl/DefaultInstallerTest.java index 99d57bc..efabedd 100644 --- a/maven-resolver-impl/src/test/java/org/eclipse/aether/internal/impl/DefaultInstallerTest.java +++ b/maven-resolver-impl/src/test/java/org/eclipse/aether/internal/impl/DefaultInstallerTest.java @@ -23,7 +23,6 @@ import static org.junit.Assert.*; import java.io.File; import java.io.IOException; -import java.io.UnsupportedEncodingException; import java.util.List; import org.eclipse.aether.DefaultRepositorySystemSession; @@ -108,7 +107,7 @@ public class DefaultInstallerTest @Test public void testSuccessfulInstall() - throws InstallationException, UnsupportedEncodingException, IOException + throws InstallationException, IOException { File artifactFile = new File( session.getLocalRepositoryManager().getRepository().getBasedir(), localArtifactPath ); http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/a05222b5/maven-resolver-impl/src/test/java/org/eclipse/aether/internal/impl/TrackingFileManagerTest.java ---------------------------------------------------------------------- diff --git a/maven-resolver-impl/src/test/java/org/eclipse/aether/internal/impl/TrackingFileManagerTest.java b/maven-resolver-impl/src/test/java/org/eclipse/aether/internal/impl/TrackingFileManagerTest.java index d730d7e..a3f4bb8 100644 --- a/maven-resolver-impl/src/test/java/org/eclipse/aether/internal/impl/TrackingFileManagerTest.java +++ b/maven-resolver-impl/src/test/java/org/eclipse/aether/internal/impl/TrackingFileManagerTest.java @@ -22,6 +22,7 @@ package org.eclipse.aether.internal.impl; import static org.junit.Assert.*; import java.io.File; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; @@ -79,7 +80,7 @@ public class TrackingFileManagerTest TrackingFileManager tfm = new TrackingFileManager(); // NOTE: The excessive repetitions are to check the update properly truncates the file - File propFile = TestFileUtils.createTempFile( "key1=value1\nkey2 : value2\n".getBytes( "UTF-8" ), 1000 ); + File propFile = TestFileUtils.createTempFile( "key1=value1\nkey2 : value2\n".getBytes( StandardCharsets.UTF_8 ), 1000 ); Map<String, String> updates = new HashMap<String, String>(); updates.put( "key1", "v" ); http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/a05222b5/maven-resolver-spi/src/main/java/org/eclipse/aether/spi/connector/transport/GetTask.java ---------------------------------------------------------------------- diff --git a/maven-resolver-spi/src/main/java/org/eclipse/aether/spi/connector/transport/GetTask.java b/maven-resolver-spi/src/main/java/org/eclipse/aether/spi/connector/transport/GetTask.java index e77de77..cef6712 100644 --- a/maven-resolver-spi/src/main/java/org/eclipse/aether/spi/connector/transport/GetTask.java +++ b/maven-resolver-spi/src/main/java/org/eclipse/aether/spi/connector/transport/GetTask.java @@ -26,13 +26,14 @@ import java.io.IOException; import java.io.OutputStream; import java.io.UnsupportedEncodingException; import java.net.URI; +import java.nio.charset.StandardCharsets; import java.util.Collections; import java.util.HashMap; import java.util.Map; /** * A task to download a resource from the remote repository. - * + * * @see Transporter#get(GetTask) */ public final class GetTask @@ -192,19 +193,12 @@ public final class GetTask { return ""; } - try - { - return dataBytes.toString( "UTF-8" ); - } - catch ( UnsupportedEncodingException e ) - { - throw new IllegalStateException( e ); - } + return new String( dataBytes.toByteArray(), StandardCharsets.UTF_8 ); } /** * Sets the listener that is to be notified during the transfer. - * + * * @param listener The listener to notify of progress, may be {@code null}. * @return This task for chaining, never {@code null}. */ http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/a05222b5/maven-resolver-spi/src/main/java/org/eclipse/aether/spi/connector/transport/PutTask.java ---------------------------------------------------------------------- diff --git a/maven-resolver-spi/src/main/java/org/eclipse/aether/spi/connector/transport/PutTask.java b/maven-resolver-spi/src/main/java/org/eclipse/aether/spi/connector/transport/PutTask.java index 1208a64..a8416fa 100644 --- a/maven-resolver-spi/src/main/java/org/eclipse/aether/spi/connector/transport/PutTask.java +++ b/maven-resolver-spi/src/main/java/org/eclipse/aether/spi/connector/transport/PutTask.java @@ -26,10 +26,11 @@ import java.io.IOException; import java.io.InputStream; import java.io.UnsupportedEncodingException; import java.net.URI; +import java.nio.charset.StandardCharsets; /** * A task to upload a resource to the remote repository. - * + * * @see Transporter#put(PutTask) */ public final class PutTask @@ -120,25 +121,18 @@ public final class PutTask /** * Sets the textual data to be uploaded. The text is encoded using UTF-8 before transmission. - * + * * @param str The textual data, may be {@code null}. * @return This task for chaining, never {@code null}. */ public PutTask setDataString( String str ) { - try - { - return setDataBytes( ( str != null ) ? str.getBytes( "UTF-8" ) : null ); - } - catch ( UnsupportedEncodingException e ) - { - throw new IllegalStateException( e ); - } + return setDataBytes( ( str != null ) ? str.getBytes( StandardCharsets.UTF_8 ) : null ); } /** * Sets the listener that is to be notified during the transfer. - * + * * @param listener The listener to notify of progress, may be {@code null}. * @return This task for chaining, never {@code null}. */ http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/a05222b5/maven-resolver-test-util/src/main/java/org/eclipse/aether/internal/test/util/DependencyGraphParser.java ---------------------------------------------------------------------- diff --git a/maven-resolver-test-util/src/main/java/org/eclipse/aether/internal/test/util/DependencyGraphParser.java b/maven-resolver-test-util/src/main/java/org/eclipse/aether/internal/test/util/DependencyGraphParser.java index d6f7a17..d3d3d02 100644 --- a/maven-resolver-test-util/src/main/java/org/eclipse/aether/internal/test/util/DependencyGraphParser.java +++ b/maven-resolver-test-util/src/main/java/org/eclipse/aether/internal/test/util/DependencyGraphParser.java @@ -24,6 +24,7 @@ import java.io.IOException; import java.io.InputStreamReader; import java.io.StringReader; import java.net.URL; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -169,7 +170,7 @@ public class DependencyGraphParser throw new IOException( "Could not find classpath resource " + prefix + resource ); } - BufferedReader reader = new BufferedReader( new InputStreamReader( res.openStream(), "UTF-8" ) ); + BufferedReader reader = new BufferedReader( new InputStreamReader( res.openStream(), StandardCharsets.UTF_8 ) ); List<DependencyNode> ret = new ArrayList<DependencyNode>(); DependencyNode root = null; @@ -189,10 +190,8 @@ public class DependencyGraphParser BufferedReader reader = null; try { - reader = new BufferedReader( new InputStreamReader( resource.openStream(), "UTF-8" ) ); + reader = new BufferedReader( new InputStreamReader( resource.openStream(), StandardCharsets.UTF_8 ) ); final DependencyNode node = parse( reader ); - reader.close(); - reader = null; return node; } finally @@ -202,6 +201,7 @@ public class DependencyGraphParser if ( reader != null ) { reader.close(); + reader = null; } } catch ( final IOException e ) http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/a05222b5/maven-resolver-test-util/src/main/java/org/eclipse/aether/internal/test/util/IniArtifactDataReader.java ---------------------------------------------------------------------- diff --git a/maven-resolver-test-util/src/main/java/org/eclipse/aether/internal/test/util/IniArtifactDataReader.java b/maven-resolver-test-util/src/main/java/org/eclipse/aether/internal/test/util/IniArtifactDataReader.java index 0b5d08b..063a135 100644 --- a/maven-resolver-test-util/src/main/java/org/eclipse/aether/internal/test/util/IniArtifactDataReader.java +++ b/maven-resolver-test-util/src/main/java/org/eclipse/aether/internal/test/util/IniArtifactDataReader.java @@ -25,6 +25,7 @@ import java.io.InputStreamReader; import java.io.Reader; import java.io.StringReader; import java.net.URL; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; @@ -86,7 +87,7 @@ class IniArtifactDataReader public ArtifactDescription parse( URL res ) throws IOException { - return parse( new InputStreamReader( res.openStream(), "UTF-8" ) ); + return parse( new InputStreamReader( res.openStream(), StandardCharsets.UTF_8 ) ); } /** http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/a05222b5/maven-resolver-test-util/src/main/java/org/eclipse/aether/internal/test/util/TestFileProcessor.java ---------------------------------------------------------------------- diff --git a/maven-resolver-test-util/src/main/java/org/eclipse/aether/internal/test/util/TestFileProcessor.java b/maven-resolver-test-util/src/main/java/org/eclipse/aether/internal/test/util/TestFileProcessor.java index 5ec38e0..0277442 100644 --- a/maven-resolver-test-util/src/main/java/org/eclipse/aether/internal/test/util/TestFileProcessor.java +++ b/maven-resolver-test-util/src/main/java/org/eclipse/aether/internal/test/util/TestFileProcessor.java @@ -27,6 +27,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.nio.ByteBuffer; +import java.nio.charset.StandardCharsets; import org.eclipse.aether.spi.io.FileProcessor; @@ -79,7 +80,7 @@ public class TestFileProcessor if ( data != null ) { - fos.write( data.getBytes( "UTF-8" ) ); + fos.write( data.getBytes( StandardCharsets.UTF_8 ) ); } fos.close(); http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/a05222b5/maven-resolver-test-util/src/main/java/org/eclipse/aether/internal/test/util/TestFileUtils.java ---------------------------------------------------------------------- diff --git a/maven-resolver-test-util/src/main/java/org/eclipse/aether/internal/test/util/TestFileUtils.java b/maven-resolver-test-util/src/main/java/org/eclipse/aether/internal/test/util/TestFileUtils.java index a948c01..f59199f 100644 --- a/maven-resolver-test-util/src/main/java/org/eclipse/aether/internal/test/util/TestFileUtils.java +++ b/maven-resolver-test-util/src/main/java/org/eclipse/aether/internal/test/util/TestFileUtils.java @@ -26,6 +26,7 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; import java.io.RandomAccessFile; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Collection; import java.util.Properties; @@ -150,7 +151,7 @@ public class TestFileUtils public static File createTempFile( String contents ) throws IOException { - return createTempFile( contents.getBytes( "UTF-8" ), 1 ); + return createTempFile( contents.getBytes( StandardCharsets.UTF_8 ), 1 ); } public static File createTempFile( byte[] pattern, int repeat ) @@ -309,13 +310,13 @@ public class TestFileUtils throws IOException { byte[] content = readBytes( file ); - return new String( content, "UTF-8" ); + return new String( content, StandardCharsets.UTF_8 ); } public static void writeString( File file, String content ) throws IOException { - writeBytes( file, content.getBytes( "UTF-8" ), 1 ); + writeBytes( file, content.getBytes( StandardCharsets.UTF_8 ), 1 ); } public static void readProps( File file, Properties props ) http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/a05222b5/maven-resolver-test-util/src/test/java/org/eclipse/aether/internal/test/util/DependencyGraphParserTest.java ---------------------------------------------------------------------- diff --git a/maven-resolver-test-util/src/test/java/org/eclipse/aether/internal/test/util/DependencyGraphParserTest.java b/maven-resolver-test-util/src/test/java/org/eclipse/aether/internal/test/util/DependencyGraphParserTest.java index 86e8a77..ac0a368 100644 --- a/maven-resolver-test-util/src/test/java/org/eclipse/aether/internal/test/util/DependencyGraphParserTest.java +++ b/maven-resolver-test-util/src/test/java/org/eclipse/aether/internal/test/util/DependencyGraphParserTest.java @@ -22,7 +22,6 @@ package org.eclipse.aether.internal.test.util; import static org.junit.Assert.*; import java.io.IOException; -import java.io.UnsupportedEncodingException; import java.util.Arrays; import java.util.List; import java.util.Map; @@ -182,7 +181,7 @@ public class DependencyGraphParserTest @Test public void testResourceLoading() - throws UnsupportedEncodingException, IOException + throws IOException { String prefix = "org/eclipse/aether/internal/test/util/"; String name = "testResourceLoading.txt"; @@ -194,7 +193,7 @@ public class DependencyGraphParserTest @Test public void testResourceLoadingWithPrefix() - throws UnsupportedEncodingException, IOException + throws IOException { String prefix = "org/eclipse/aether/internal/test/util/"; parser = new DependencyGraphParser( prefix ); http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/a05222b5/maven-resolver-transport-classpath/src/test/java/org/eclipse/aether/transport/classpath/ClasspathTransporterTest.java ---------------------------------------------------------------------- diff --git a/maven-resolver-transport-classpath/src/test/java/org/eclipse/aether/transport/classpath/ClasspathTransporterTest.java b/maven-resolver-transport-classpath/src/test/java/org/eclipse/aether/transport/classpath/ClasspathTransporterTest.java index 0c91685..6022cb2 100644 --- a/maven-resolver-transport-classpath/src/test/java/org/eclipse/aether/transport/classpath/ClasspathTransporterTest.java +++ b/maven-resolver-transport-classpath/src/test/java/org/eclipse/aether/transport/classpath/ClasspathTransporterTest.java @@ -24,6 +24,7 @@ import static org.junit.Assert.*; import java.io.File; import java.io.FileNotFoundException; import java.net.URI; +import java.nio.charset.StandardCharsets; import org.eclipse.aether.DefaultRepositorySystemSession; import org.eclipse.aether.internal.test.util.TestFileUtils; @@ -147,7 +148,7 @@ public class ClasspathTransporterTest assertEquals( 4, listener.dataLength ); assertEquals( 1, listener.startedCount ); assertTrue( "Count: " + listener.progressedCount, listener.progressedCount > 0 ); - assertEquals( task.getDataString(), listener.baos.toString( "UTF-8" ) ); + assertEquals( task.getDataString(), new String( listener.baos.toByteArray(), StandardCharsets.UTF_8 ) ); } @Test @@ -163,7 +164,7 @@ public class ClasspathTransporterTest assertEquals( 4, listener.dataLength ); assertEquals( 1, listener.startedCount ); assertTrue( "Count: " + listener.progressedCount, listener.progressedCount > 0 ); - assertEquals( "test", listener.baos.toString( "UTF-8" ) ); + assertEquals( "test", new String( listener.baos.toByteArray(), StandardCharsets.UTF_8 ) ); } @Test @@ -179,7 +180,7 @@ public class ClasspathTransporterTest assertEquals( 0, listener.dataLength ); assertEquals( 1, listener.startedCount ); assertEquals( 0, listener.progressedCount ); - assertEquals( "", listener.baos.toString( "UTF-8" ) ); + assertEquals( "", new String( listener.baos.toByteArray(), StandardCharsets.UTF_8 ) ); } @Test http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/a05222b5/maven-resolver-transport-file/src/test/java/org/eclipse/aether/transport/file/FileTransporterTest.java ---------------------------------------------------------------------- diff --git a/maven-resolver-transport-file/src/test/java/org/eclipse/aether/transport/file/FileTransporterTest.java b/maven-resolver-transport-file/src/test/java/org/eclipse/aether/transport/file/FileTransporterTest.java index 6c4e361..b4bf066 100644 --- a/maven-resolver-transport-file/src/test/java/org/eclipse/aether/transport/file/FileTransporterTest.java +++ b/maven-resolver-transport-file/src/test/java/org/eclipse/aether/transport/file/FileTransporterTest.java @@ -24,6 +24,7 @@ import static org.junit.Assert.*; import java.io.File; import java.io.FileNotFoundException; import java.net.URI; +import java.nio.charset.StandardCharsets; import org.eclipse.aether.DefaultRepositorySystemSession; import org.eclipse.aether.internal.test.util.TestFileUtils; @@ -153,7 +154,7 @@ public class FileTransporterTest assertEquals( 4, listener.dataLength ); assertEquals( 1, listener.startedCount ); assertTrue( "Count: " + listener.progressedCount, listener.progressedCount > 0 ); - assertEquals( task.getDataString(), listener.baos.toString( "UTF-8" ) ); + assertEquals( task.getDataString(), new String( listener.baos.toByteArray(), StandardCharsets.UTF_8 ) ); } @Test @@ -169,7 +170,7 @@ public class FileTransporterTest assertEquals( 4, listener.dataLength ); assertEquals( 1, listener.startedCount ); assertTrue( "Count: " + listener.progressedCount, listener.progressedCount > 0 ); - assertEquals( "test", listener.baos.toString( "UTF-8" ) ); + assertEquals( "test", new String( listener.baos.toByteArray(), StandardCharsets.UTF_8 ) ); } @Test @@ -185,7 +186,7 @@ public class FileTransporterTest assertEquals( 0, listener.dataLength ); assertEquals( 1, listener.startedCount ); assertEquals( 0, listener.progressedCount ); - assertEquals( "", listener.baos.toString( "UTF-8" ) ); + assertEquals( "", new String( listener.baos.toByteArray(), StandardCharsets.UTF_8 ) ); } @Test http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/a05222b5/maven-resolver-transport-http/src/test/java/org/eclipse/aether/transport/http/HttpServer.java ---------------------------------------------------------------------- diff --git a/maven-resolver-transport-http/src/test/java/org/eclipse/aether/transport/http/HttpServer.java b/maven-resolver-transport-http/src/test/java/org/eclipse/aether/transport/http/HttpServer.java index 44e32ed..0a7349f 100644 --- a/maven-resolver-transport-http/src/test/java/org/eclipse/aether/transport/http/HttpServer.java +++ b/maven-resolver-transport-http/src/test/java/org/eclipse/aether/transport/http/HttpServer.java @@ -24,6 +24,7 @@ import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.UnsupportedEncodingException; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Collections; import java.util.Enumeration; http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/a05222b5/maven-resolver-transport-http/src/test/java/org/eclipse/aether/transport/http/HttpTransporterTest.java ---------------------------------------------------------------------- diff --git a/maven-resolver-transport-http/src/test/java/org/eclipse/aether/transport/http/HttpTransporterTest.java b/maven-resolver-transport-http/src/test/java/org/eclipse/aether/transport/http/HttpTransporterTest.java index b1ba731..6af7b16 100644 --- a/maven-resolver-transport-http/src/test/java/org/eclipse/aether/transport/http/HttpTransporterTest.java +++ b/maven-resolver-transport-http/src/test/java/org/eclipse/aether/transport/http/HttpTransporterTest.java @@ -27,6 +27,7 @@ import java.net.ConnectException; import java.net.ServerSocket; import java.net.SocketTimeoutException; import java.net.URI; +import java.nio.charset.StandardCharsets; import java.util.HashMap; import java.util.Map; import java.util.concurrent.atomic.AtomicReference; @@ -277,7 +278,7 @@ public class HttpTransporterTest assertEquals( 4, listener.dataLength ); assertEquals( 1, listener.startedCount ); assertTrue( "Count: " + listener.progressedCount, listener.progressedCount > 0 ); - assertEquals( task.getDataString(), listener.baos.toString( "UTF-8" ) ); + assertEquals( task.getDataString(), new String( listener.baos.toByteArray(), StandardCharsets.UTF_8 ) ); } @Test @@ -293,7 +294,7 @@ public class HttpTransporterTest assertEquals( 4, listener.dataLength ); assertEquals( 1, listener.startedCount ); assertTrue( "Count: " + listener.progressedCount, listener.progressedCount > 0 ); - assertEquals( "test", listener.baos.toString( "UTF-8" ) ); + assertEquals( "test", new String( listener.baos.toByteArray(), StandardCharsets.UTF_8 ) ); } @Test @@ -309,7 +310,7 @@ public class HttpTransporterTest assertEquals( 0, listener.dataLength ); assertEquals( 1, listener.startedCount ); assertEquals( 0, listener.progressedCount ); - assertEquals( "", listener.baos.toString( "UTF-8" ) ); + assertEquals( "", new String( listener.baos.toByteArray(), StandardCharsets.UTF_8 ) ); } @Test @@ -336,7 +337,7 @@ public class HttpTransporterTest assertEquals( 4, listener.dataLength ); assertEquals( 1, listener.startedCount ); assertTrue( "Count: " + listener.progressedCount, listener.progressedCount > 0 ); - assertEquals( task.getDataString(), listener.baos.toString( "UTF-8" ) ); + assertEquals( task.getDataString(), new String( listener.baos.toByteArray(), StandardCharsets.UTF_8 ) ); } @Test @@ -372,7 +373,7 @@ public class HttpTransporterTest assertEquals( 4, listener.dataLength ); assertEquals( 1, listener.startedCount ); assertTrue( "Count: " + listener.progressedCount, listener.progressedCount > 0 ); - assertEquals( task.getDataString(), listener.baos.toString( "UTF-8" ) ); + assertEquals( task.getDataString(), new String( listener.baos.toByteArray(), StandardCharsets.UTF_8 ) ); } @Test @@ -408,7 +409,7 @@ public class HttpTransporterTest assertEquals( 4, listener.dataLength ); assertEquals( 1, listener.startedCount ); assertTrue( "Count: " + listener.progressedCount, listener.progressedCount > 0 ); - assertEquals( task.getDataString(), listener.baos.toString( "UTF-8" ) ); + assertEquals( task.getDataString(), new String( listener.baos.toByteArray(), StandardCharsets.UTF_8 ) ); } @Test @@ -425,7 +426,7 @@ public class HttpTransporterTest assertEquals( 4, listener.dataLength ); assertEquals( 1, listener.startedCount ); assertTrue( "Count: " + listener.progressedCount, listener.progressedCount > 0 ); - assertEquals( task.getDataString(), listener.baos.toString( "UTF-8" ) ); + assertEquals( task.getDataString(), new String( listener.baos.toByteArray(), StandardCharsets.UTF_8 ) ); assertEquals( httpServer.getLogEntries().toString(), 1, httpServer.getLogEntries().size() ); } @@ -442,7 +443,7 @@ public class HttpTransporterTest assertEquals( 4, listener.dataLength ); assertEquals( 1, listener.startedCount ); assertTrue( "Count: " + listener.progressedCount, listener.progressedCount > 0 ); - assertEquals( task.getDataString(), listener.baos.toString( "UTF-8" ) ); + assertEquals( task.getDataString(), new String( listener.baos.toByteArray(), StandardCharsets.UTF_8 ) ); } @Test @@ -458,7 +459,7 @@ public class HttpTransporterTest assertEquals( 2, listener.dataOffset ); assertEquals( 9, listener.dataLength ); assertTrue( "Count: " + listener.progressedCount, listener.progressedCount > 0 ); - assertEquals( "sumable", listener.baos.toString( "UTF-8" ) ); + assertEquals( "sumable", new String( listener.baos.toByteArray(), StandardCharsets.UTF_8 ) ); } @Test @@ -475,7 +476,7 @@ public class HttpTransporterTest assertEquals( 0, listener.dataOffset ); assertEquals( 9, listener.dataLength ); assertTrue( "Count: " + listener.progressedCount, listener.progressedCount > 0 ); - assertEquals( "resumable", listener.baos.toString( "UTF-8" ) ); + assertEquals( "resumable", new String( listener.baos.toByteArray(), StandardCharsets.UTF_8 ) ); } @Test @@ -492,7 +493,7 @@ public class HttpTransporterTest assertEquals( 0, listener.dataOffset ); assertEquals( 9, listener.dataLength ); assertTrue( "Count: " + listener.progressedCount, listener.progressedCount > 0 ); - assertEquals( "resumable", listener.baos.toString( "UTF-8" ) ); + assertEquals( "resumable", new String( listener.baos.toByteArray(), StandardCharsets.UTF_8 ) ); } @Test http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/a05222b5/maven-resolver-transport-wagon/src/test/java/org/eclipse/aether/transport/wagon/AbstractWagonTransporterTest.java ---------------------------------------------------------------------- diff --git a/maven-resolver-transport-wagon/src/test/java/org/eclipse/aether/transport/wagon/AbstractWagonTransporterTest.java b/maven-resolver-transport-wagon/src/test/java/org/eclipse/aether/transport/wagon/AbstractWagonTransporterTest.java index 61f8a8e..5a168d1 100644 --- a/maven-resolver-transport-wagon/src/test/java/org/eclipse/aether/transport/wagon/AbstractWagonTransporterTest.java +++ b/maven-resolver-transport-wagon/src/test/java/org/eclipse/aether/transport/wagon/AbstractWagonTransporterTest.java @@ -25,6 +25,7 @@ import static org.junit.Assert.fail; import java.io.File; import java.net.URI; +import java.nio.charset.StandardCharsets; import java.util.Map; import java.util.UUID; @@ -195,7 +196,7 @@ public abstract class AbstractWagonTransporterTest assertEquals( 4, listener.dataLength ); assertEquals( 1, listener.startedCount ); assertTrue( "Count: " + listener.progressedCount, listener.progressedCount > 0 ); - assertEquals( task.getDataString(), listener.baos.toString( "UTF-8" ) ); + assertEquals( task.getDataString(), new String( listener.baos.toByteArray(), StandardCharsets.UTF_8 ) ); } @Test @@ -211,7 +212,7 @@ public abstract class AbstractWagonTransporterTest assertEquals( 4, listener.dataLength ); assertEquals( 1, listener.startedCount ); assertTrue( "Count: " + listener.progressedCount, listener.progressedCount > 0 ); - assertEquals( "test", listener.baos.toString( "UTF-8" ) ); + assertEquals( "test", new String( listener.baos.toByteArray(), StandardCharsets.UTF_8 ) ); } @Test @@ -228,7 +229,7 @@ public abstract class AbstractWagonTransporterTest assertEquals( 0, listener.dataLength ); assertEquals( 1, listener.startedCount ); assertEquals( 0, listener.progressedCount ); - assertEquals( "", listener.baos.toString( "UTF-8" ) ); + assertEquals( "", new String( listener.baos.toByteArray(), StandardCharsets.UTF_8 ) ); } @Test http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/a05222b5/maven-resolver-transport-wagon/src/test/java/org/eclipse/aether/transport/wagon/MemStreamWagon.java ---------------------------------------------------------------------- diff --git a/maven-resolver-transport-wagon/src/test/java/org/eclipse/aether/transport/wagon/MemStreamWagon.java b/maven-resolver-transport-wagon/src/test/java/org/eclipse/aether/transport/wagon/MemStreamWagon.java index 35efca1..6b4be8f 100644 --- a/maven-resolver-transport-wagon/src/test/java/org/eclipse/aether/transport/wagon/MemStreamWagon.java +++ b/maven-resolver-transport-wagon/src/test/java/org/eclipse/aether/transport/wagon/MemStreamWagon.java @@ -23,8 +23,8 @@ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.InputStream; import java.io.OutputStream; -import java.io.UnsupportedEncodingException; import java.net.URI; +import java.nio.charset.StandardCharsets; import java.util.Map; import java.util.Properties; @@ -104,15 +104,7 @@ public class MemStreamWagon { throw new ResourceDoesNotExistException( "Missing resource: " + inputData.getResource().getName() ); } - byte[] bytes; - try - { - bytes = data.getBytes( "UTF-8" ); - } - catch ( UnsupportedEncodingException e ) - { - throw new TransferFailedException( e.getMessage(), e ); - } + byte[] bytes = data.getBytes( StandardCharsets.UTF_8 ); inputData.getResource().setContentLength( bytes.length ); inputData.setInputStream( new ByteArrayInputStream( bytes ) ); } @@ -128,15 +120,7 @@ public class MemStreamWagon protected void finishPutTransfer( Resource resource, InputStream input, OutputStream output ) throws TransferFailedException, AuthorizationException, ResourceDoesNotExistException { - String data; - try - { - data = ( (ByteArrayOutputStream) output ).toString( "UTF-8" ); - } - catch ( UnsupportedEncodingException e ) - { - throw new TransferFailedException( e.getMessage(), e ); - } + String data = new String( ( (ByteArrayOutputStream) output ).toByteArray(), StandardCharsets.UTF_8 ); fs.put( URI.create( resource.getName() ).getSchemeSpecificPart(), data ); } http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/a05222b5/maven-resolver-transport-wagon/src/test/java/org/eclipse/aether/transport/wagon/MemWagon.java ---------------------------------------------------------------------- diff --git a/maven-resolver-transport-wagon/src/test/java/org/eclipse/aether/transport/wagon/MemWagon.java b/maven-resolver-transport-wagon/src/test/java/org/eclipse/aether/transport/wagon/MemWagon.java index ec3d7d6..17c82f2 100644 --- a/maven-resolver-transport-wagon/src/test/java/org/eclipse/aether/transport/wagon/MemWagon.java +++ b/maven-resolver-transport-wagon/src/test/java/org/eclipse/aether/transport/wagon/MemWagon.java @@ -24,8 +24,8 @@ import java.io.ByteArrayOutputStream; import java.io.File; import java.io.InputStream; import java.io.OutputStream; -import java.io.UnsupportedEncodingException; import java.net.URI; +import java.nio.charset.StandardCharsets; import java.util.Map; import java.util.Properties; @@ -158,15 +158,7 @@ public class MemWagon { throw new ResourceDoesNotExistException( "Missing resource: " + inputData.getResource().getName() ); } - byte[] bytes; - try - { - bytes = data.getBytes( "UTF-8" ); - } - catch ( UnsupportedEncodingException e ) - { - throw new TransferFailedException( e.getMessage(), e ); - } + byte[] bytes = data.getBytes( StandardCharsets.UTF_8 ); inputData.getResource().setContentLength( bytes.length ); inputData.setInputStream( new ByteArrayInputStream( bytes ) ); } @@ -217,15 +209,7 @@ public class MemWagon protected void finishPutTransfer( Resource resource, InputStream input, OutputStream output ) throws TransferFailedException, AuthorizationException, ResourceDoesNotExistException { - String data; - try - { - data = ( (ByteArrayOutputStream) output ).toString( "UTF-8" ); - } - catch ( UnsupportedEncodingException e ) - { - throw new TransferFailedException( e.getMessage(), e ); - } + String data = new String( ( (ByteArrayOutputStream) output ).toByteArray(), StandardCharsets.UTF_8 ); fs.put( URI.create( resource.getName() ).getSchemeSpecificPart(), data ); } http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/a05222b5/maven-resolver-util/src/main/java/org/eclipse/aether/util/ChecksumUtils.java ---------------------------------------------------------------------- diff --git a/maven-resolver-util/src/main/java/org/eclipse/aether/util/ChecksumUtils.java b/maven-resolver-util/src/main/java/org/eclipse/aether/util/ChecksumUtils.java index 3134c80..415e712 100644 --- a/maven-resolver-util/src/main/java/org/eclipse/aether/util/ChecksumUtils.java +++ b/maven-resolver-util/src/main/java/org/eclipse/aether/util/ChecksumUtils.java @@ -25,6 +25,7 @@ import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.Collection; @@ -56,7 +57,7 @@ public final class ChecksumUtils BufferedReader br = null; try { - br = new BufferedReader( new InputStreamReader( new FileInputStream( checksumFile ), "UTF-8" ), 512 ); + br = new BufferedReader( new InputStreamReader( new FileInputStream( checksumFile ), StandardCharsets.UTF_8 ), 512 ); while ( true ) { String line = br.readLine(); @@ -71,9 +72,6 @@ public final class ChecksumUtils break; } } - - br.close(); - br = null; } finally { @@ -82,6 +80,7 @@ public final class ChecksumUtils if ( br != null ) { br.close(); + br = null; } } catch ( IOException e ) http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/a05222b5/maven-resolver-util/src/test/java/org/eclipse/aether/util/ChecksumUtilTest.java ---------------------------------------------------------------------- diff --git a/maven-resolver-util/src/test/java/org/eclipse/aether/util/ChecksumUtilTest.java b/maven-resolver-util/src/test/java/org/eclipse/aether/util/ChecksumUtilTest.java index 05da6f4..b249e82 100644 --- a/maven-resolver-util/src/test/java/org/eclipse/aether/util/ChecksumUtilTest.java +++ b/maven-resolver-util/src/test/java/org/eclipse/aether/util/ChecksumUtilTest.java @@ -24,6 +24,7 @@ import static org.junit.Assert.*; import java.io.File; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.HashMap; import java.util.Map; @@ -75,7 +76,7 @@ public class ChecksumUtilTest createTempFile( new byte[] { 0, 1, 2, 4, 8, 16, 32, 64, 127, -1, -2, -4, -8, -16, -32, -64, -127 }, 1000 ); sums.put( patternFile, patternFileChecksums ); - textFile = createTempFile( "the quick brown fox jumps over the lazy dog\n".getBytes( "UTF-8" ), 500 ); + textFile = createTempFile( "the quick brown fox jumps over the lazy dog\n".getBytes( StandardCharsets.UTF_8 ), 500 ); sums.put( textFile, textFileChecksums ); }