Skip to content

Commit

Permalink
Reducing duplicate code in MRJAR using VersionSpecifics class
Browse files Browse the repository at this point in the history
Signed-off-by: Markus KARG <markus@headcrashing.eu>
  • Loading branch information
mkarg committed Jan 2, 2021
1 parent be51d3a commit bc5b0ab
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 1,774 deletions.
29 changes: 29 additions & 0 deletions src/main/java/org/codehaus/plexus/util/CommonImplementation.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package org.codehaus.plexus.util;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Reader;
import java.io.Writer;

/**
* Fallback implementation for all Java SE versions not
* overwriting a method version-specifically.
*/
abstract class CommonImplementation
{
private static final int DEFAULT_BUFFER_SIZE = 1024 * 16;

void copy( final InputStream input, final OutputStream output )
throws IOException
{
IOUtil.copy( input, output, DEFAULT_BUFFER_SIZE );
}

void copy( final Reader input, final Writer output )
throws IOException
{
IOUtil.copy( input, output, DEFAULT_BUFFER_SIZE );
}

}
4 changes: 2 additions & 2 deletions src/main/java/org/codehaus/plexus/util/IOUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ private IOUtil()
public static void copy( final InputStream input, final OutputStream output )
throws IOException
{
copy( input, output, DEFAULT_BUFFER_SIZE );
VersionSpecifics.INSTANCE.copy( input, output );
}

/**
Expand Down Expand Up @@ -186,7 +186,7 @@ public static void copy( final InputStream input, final OutputStream output, fin
public static void copy( final Reader input, final Writer output )
throws IOException
{
copy( input, output, DEFAULT_BUFFER_SIZE );
VersionSpecifics.INSTANCE.copy( input, output );
}

/**
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/org/codehaus/plexus/util/VersionSpecifics.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.codehaus.plexus.util;

/**
* Implementation specific to Java SE 8 version.
*/
final class VersionSpecifics extends CommonImplementation
{
static final VersionSpecifics INSTANCE = new VersionSpecifics();

private VersionSpecifics() {
// singleton
}
}
Loading

0 comments on commit bc5b0ab

Please sign in to comment.