Skip to content

Commit 25401d5

Browse files
committed
metafacture-io/ (main): Fix Checkstyle violations.
1 parent 7812615 commit 25401d5

27 files changed

+237
-166
lines changed

metafacture-io/src/main/java/org/metafacture/io/AbstractObjectWriter.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
1617
package org.metafacture.io;
1718

1819
/**

metafacture-io/src/main/java/org/metafacture/io/ByteStreamFileWriter.java

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
package org.metafacture.io;
22

3-
import static java.util.Objects.requireNonNull;
3+
import org.metafacture.framework.helpers.DefaultObjectReceiver;
44

55
import java.io.File;
66
import java.io.FileNotFoundException;
77
import java.io.FileOutputStream;
88
import java.io.IOException;
99
import java.io.OutputStream;
10+
import java.util.Objects;
1011
import java.util.function.Supplier;
1112

12-
import org.metafacture.framework.helpers.DefaultObjectReceiver;
13-
1413
/**
1514
* Writes byte arrays to regular output files.
1615
* <p>
@@ -28,6 +27,9 @@ public class ByteStreamFileWriter extends DefaultObjectReceiver<byte[]> {
2827

2928
private OutputStream outputStream;
3029

30+
public ByteStreamFileWriter() {
31+
}
32+
3133
/**
3234
* Supplier for file names.
3335
* <p>
@@ -42,9 +44,8 @@ public class ByteStreamFileWriter extends DefaultObjectReceiver<byte[]> {
4244
*
4345
* @param fileNameSupplier a supplier that returns file names.
4446
*/
45-
public void setFileNameSupplier(Supplier<File> fileNameSupplier) {
46-
47-
this.fileNameSupplier = requireNonNull(fileNameSupplier);
47+
public void setFileNameSupplier(final Supplier<File> fileNameSupplier) {
48+
this.fileNameSupplier = Objects.requireNonNull(fileNameSupplier);
4849
}
4950

5051
/**
@@ -58,8 +59,7 @@ public void setFileNameSupplier(Supplier<File> fileNameSupplier) {
5859
* @param appendIfFileExists true if new data should be appended,
5960
* false to overwrite the existing file.
6061
*/
61-
public void setAppendIfFileExists(boolean appendIfFileExists) {
62-
62+
public void setAppendIfFileExists(final boolean appendIfFileExists) {
6363
this.appendIfFileExists = appendIfFileExists;
6464
}
6565

@@ -75,8 +75,7 @@ public void setAppendIfFileExists(boolean appendIfFileExists) {
7575
* @param flushAfterWrite true if the output stream should be flushed
7676
* after every write.
7777
*/
78-
public void setFlushAfterWrite(boolean flushAfterWrite) {
79-
78+
public void setFlushAfterWrite(final boolean flushAfterWrite) {
8079
this.flushAfterWrite = flushAfterWrite;
8180
}
8281

@@ -88,15 +87,15 @@ public void setFlushAfterWrite(boolean flushAfterWrite) {
8887
*/
8988
@Override
9089
public void process(final byte[] bytes) {
91-
9290
ensureOpenStream();
9391
try {
9492
outputStream.write(bytes);
9593
if (flushAfterWrite) {
9694
outputStream.flush();
9795
}
9896

99-
} catch (IOException e) {
97+
}
98+
catch (final IOException e) {
10099
throw new WriteFailed("Error while writing bytes to output stream", e);
101100
}
102101
}
@@ -109,7 +108,6 @@ public void process(final byte[] bytes) {
109108
*/
110109
@Override
111110
public void resetStream() {
112-
113111
closeStream();
114112
ensureOpenStream();
115113
}
@@ -121,27 +119,27 @@ public void resetStream() {
121119
*/
122120
@Override
123121
public void closeStream() {
124-
125122
if (outputStream != null) {
126123
try {
127124
outputStream.close();
128125

129-
} catch (IOException e) {
126+
}
127+
catch (final IOException e) {
130128
throw new CloseFailed("Error while closing output stream", e);
131129
}
132130
outputStream = null;
133131
}
134132
}
135133

136134
private void ensureOpenStream() {
137-
138135
if (outputStream != null) {
139136
return;
140137
}
141138
try {
142139
outputStream = new FileOutputStream(fileNameSupplier.get(), appendIfFileExists);
143140

144-
} catch (FileNotFoundException e) {
141+
}
142+
catch (final FileNotFoundException e) {
145143
throw new OpenFailed("Cannot open output stream. File not found.", e);
146144
}
147145
}

metafacture-io/src/main/java/org/metafacture/io/CloseFailed.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
public class CloseFailed extends IoFailed {
44

5-
public CloseFailed(String message) {
5+
public CloseFailed(final String message) {
66
super(message);
77
}
88

9-
public CloseFailed(Throwable cause) {
9+
public CloseFailed(final Throwable cause) {
1010
super(cause);
1111
}
1212

13-
public CloseFailed(String message, Throwable cause) {
13+
public CloseFailed(final String message, final Throwable cause) {
1414
super(message, cause);
1515
}
1616

metafacture-io/src/main/java/org/metafacture/io/ConfigurableObjectWriter.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
1617
package org.metafacture.io;
1718

1819
import org.metafacture.framework.ObjectReceiver;
@@ -58,14 +59,14 @@ public interface ConfigurableObjectWriter<T> extends ObjectReceiver<T> {
5859
*
5960
* @param compression type of compression
6061
*/
61-
void setCompression(final FileCompression compression);
62+
void setCompression(FileCompression compression);
6263

6364
/**
6465
* Sets the compression mode.
6566
*
6667
* @param compression type of compression
6768
*/
68-
void setCompression(final String compression);
69+
void setCompression(String compression);
6970

7071
/**
7172
* Returns the header which is output before the first object.
@@ -79,7 +80,7 @@ public interface ConfigurableObjectWriter<T> extends ObjectReceiver<T> {
7980
*
8081
* @param header new header string
8182
*/
82-
void setHeader(final String header);
83+
void setHeader(String header);
8384

8485
/**
8586
* Returns the footer which is output after the last object.
@@ -93,7 +94,7 @@ public interface ConfigurableObjectWriter<T> extends ObjectReceiver<T> {
9394
*
9495
* @param footer new footer string
9596
*/
96-
void setFooter(final String footer);
97+
void setFooter(String footer);
9798

9899
/**
99100
* Returns the separator which is output between objects.
@@ -107,6 +108,6 @@ public interface ConfigurableObjectWriter<T> extends ObjectReceiver<T> {
107108
*
108109
* @param separator new separator string
109110
*/
110-
void setSeparator(final String separator);
111+
void setSeparator(String separator);
111112

112113
}

metafacture-io/src/main/java/org/metafacture/io/FileCompression.java

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,21 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
1617
package org.metafacture.io;
1718

18-
import java.io.BufferedInputStream;
19-
import java.io.BufferedOutputStream;
20-
import java.io.InputStream;
21-
import java.io.OutputStream;
19+
import org.metafacture.framework.MetafactureException;
2220

2321
import org.apache.commons.compress.compressors.CompressorException;
2422
import org.apache.commons.compress.compressors.CompressorStreamFactory;
2523
import org.apache.commons.io.FilenameUtils;
2624
import org.apache.commons.io.input.ProxyInputStream;
2725
import org.apache.commons.io.output.ProxyOutputStream;
28-
import org.metafacture.framework.MetafactureException;
26+
27+
import java.io.BufferedInputStream;
28+
import java.io.BufferedOutputStream;
29+
import java.io.InputStream;
30+
import java.io.OutputStream;
2931

3032
/**
3133
* Provides a convenient interface for using stream compressors
@@ -61,15 +63,20 @@ public OutputStream createCompressor(final OutputStream writeTo, final String fi
6163
final FileCompression compressor;
6264
if ("gz".equalsIgnoreCase(extension)) {
6365
compressor = GZIP;
64-
} else if ("gzip".equalsIgnoreCase(extension)) {
66+
}
67+
else if ("gzip".equalsIgnoreCase(extension)) {
6568
compressor = GZIP;
66-
} else if ("bz2".equalsIgnoreCase(extension)) {
69+
}
70+
else if ("bz2".equalsIgnoreCase(extension)) {
6771
compressor = BZIP2;
68-
} else if ("bzip2".equalsIgnoreCase(extension)) {
72+
}
73+
else if ("bzip2".equalsIgnoreCase(extension)) {
6974
compressor = BZIP2;
70-
} else if ("xz".equalsIgnoreCase(extension)) {
75+
}
76+
else if ("xz".equalsIgnoreCase(extension)) {
7177
compressor = XZ;
72-
} else {
78+
}
79+
else {
7380
compressor = NONE;
7481
}
7582

@@ -83,7 +90,8 @@ public InputStream createDecompressor(final InputStream readFrom, final boolean
8390
return decompressConcatenated ?
8491
APACHE_COMPRESSOR_FACTORY_DECOMPRESS_CONCATENATED.createCompressorInputStream(bufferedStream) :
8592
APACHE_COMPRESSOR_FACTORY_NO_DECOMPRESS_CONCATENATED.createCompressorInputStream(bufferedStream);
86-
} catch (CompressorException e) {
93+
}
94+
catch (final CompressorException e) {
8795
return NONE.createDecompressor(bufferedStream, decompressConcatenated);
8896
}
8997
}
@@ -95,7 +103,8 @@ public OutputStream createCompressor(final OutputStream writeTo, final String fi
95103
try {
96104
return APACHE_COMPRESSOR_FACTORY.createCompressorOutputStream(
97105
CompressorStreamFactory.BZIP2, bufferStream(writeTo));
98-
} catch (CompressorException e) {
106+
}
107+
catch (final CompressorException e) {
99108
throw new MetafactureException(e);
100109
}
101110
}
@@ -105,7 +114,8 @@ public InputStream createDecompressor(final InputStream readFrom, final boolean
105114
try {
106115
return APACHE_COMPRESSOR_FACTORY.createCompressorInputStream(
107116
CompressorStreamFactory.BZIP2, bufferStream(readFrom), decompressConcatenated);
108-
} catch (CompressorException e) {
117+
}
118+
catch (final CompressorException e) {
109119
throw new MetafactureException(e);
110120
}
111121
}
@@ -117,7 +127,8 @@ public OutputStream createCompressor(final OutputStream writeTo, final String fi
117127
try {
118128
return APACHE_COMPRESSOR_FACTORY.createCompressorOutputStream(
119129
CompressorStreamFactory.GZIP, bufferStream(writeTo));
120-
} catch (CompressorException e) {
130+
}
131+
catch (final CompressorException e) {
121132
throw new MetafactureException(e);
122133
}
123134
}
@@ -127,7 +138,8 @@ public InputStream createDecompressor(final InputStream readFrom, final boolean
127138
try {
128139
return APACHE_COMPRESSOR_FACTORY.createCompressorInputStream(
129140
CompressorStreamFactory.GZIP, bufferStream(readFrom), decompressConcatenated);
130-
} catch (CompressorException e) {
141+
}
142+
catch (final CompressorException e) {
131143
throw new MetafactureException(e);
132144
}
133145
}
@@ -139,7 +151,8 @@ public OutputStream createCompressor(final OutputStream writeTo, final String fi
139151
try {
140152
return APACHE_COMPRESSOR_FACTORY.createCompressorOutputStream(
141153
CompressorStreamFactory.PACK200, bufferStream(writeTo));
142-
} catch (CompressorException e) {
154+
}
155+
catch (final CompressorException e) {
143156
throw new MetafactureException(e);
144157
}
145158
}
@@ -149,7 +162,8 @@ public InputStream createDecompressor(final InputStream readFrom, final boolean
149162
try {
150163
return APACHE_COMPRESSOR_FACTORY.createCompressorInputStream(
151164
CompressorStreamFactory.PACK200, bufferStream(readFrom), decompressConcatenated);
152-
} catch (CompressorException e) {
165+
}
166+
catch (final CompressorException e) {
153167
throw new MetafactureException(e);
154168
}
155169
}
@@ -161,7 +175,8 @@ public OutputStream createCompressor(final OutputStream writeTo, final String fi
161175
try {
162176
return APACHE_COMPRESSOR_FACTORY.createCompressorOutputStream(
163177
CompressorStreamFactory.XZ, bufferStream(writeTo));
164-
} catch (CompressorException e) {
178+
}
179+
catch (final CompressorException e) {
165180
throw new MetafactureException(e);
166181
}
167182
}
@@ -171,7 +186,8 @@ public InputStream createDecompressor(final InputStream readFrom, final boolean
171186
try {
172187
return APACHE_COMPRESSOR_FACTORY.createCompressorInputStream(
173188
CompressorStreamFactory.XZ, bufferStream(readFrom), decompressConcatenated);
174-
} catch (CompressorException e) {
189+
}
190+
catch (final CompressorException e) {
175191
throw new MetafactureException(e);
176192
}
177193
}
@@ -186,9 +202,9 @@ public InputStream createDecompressor(final InputStream readFrom, final boolean
186202

187203
private static final int BUFFER_SIZE = 8 * 1024 * 1024;
188204

189-
public abstract OutputStream createCompressor(final OutputStream writeTo, final String fileName);
205+
public abstract OutputStream createCompressor(OutputStream writeTo, String fileName);
190206

191-
public abstract InputStream createDecompressor(final InputStream readFrom, final boolean decompressConcatenated);
207+
public abstract InputStream createDecompressor(InputStream readFrom, boolean decompressConcatenated);
192208

193209
public InputStream createDecompressor(final InputStream readFrom) {
194210
return createDecompressor(readFrom, DEFAULT_DECOMPRESS_CONCATENATED);

0 commit comments

Comments
 (0)