Permalink
Browse files

Merge branch 'findbugs' into spotbugs

  • Loading branch information...
mebigfatguy committed Dec 1, 2018
2 parents d92fed5 + 38da756 commit b25da666c23f2d0d96bf8dc7db35f85c2d9cab59
Showing with 45 additions and 28 deletions.
  1. +1 −1 etc/messages.xml
  2. +44 −27 src/samples/java/ex/IOI_Sample.java
@@ -1599,7 +1599,7 @@ a[0] = new A(); // results in ArrayStoreException (Runtime)
<Detector class="com.mebigfatguy.fbcontrib.detect.IOIssues">
<Details>
<![CDATA[
<p>Looks for various issues around doing I/O with streams and reader/writers.</p>
<p>Looks for various issues around doing I/O with streams and reader/writers, and compression of byte buffers.</p>
<p>It is a fast detector.</p>
]]>
</Details>
@@ -9,47 +9,64 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.zip.DataFormatException;
import java.util.zip.Deflater;
import java.util.zip.Inflater;
import org.apache.commons.io.IOUtils;
public class IOI_Sample {
public byte[] getIOIData(File f) throws IOException {
try (InputStream is = new BufferedInputStream(new FileInputStream(f)); ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
public byte[] getIOIData(File f) throws IOException {
try (InputStream is = new BufferedInputStream(new FileInputStream(f));
ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
IOUtils.copy(is, baos);
IOUtils.copy(is, baos);
return baos.toByteArray();
}
}
return baos.toByteArray();
}
}
public byte[] getIOIReaderData(File f) throws IOException {
try (FileReader r = new FileReader(f); ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
public byte[] getIOIReaderData(File f) throws IOException {
try (FileReader r = new FileReader(f); ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
IOUtils.copy(r, baos);
IOUtils.copy(r, baos);
return baos.toByteArray();
}
}
return baos.toByteArray();
}
}
public void copy(String inName, String outName) throws IOException {
byte[] buf = new byte[1024];
public void copy(String inName, String outName) throws IOException {
byte[] buf = new byte[1024];
try (InputStream is = new FileInputStream(inName); OutputStream os = new FileOutputStream(outName);) {
try (InputStream is = new FileInputStream(inName); OutputStream os = new FileOutputStream(outName);) {
int size = is.read(buf);
while (size >= 0) {
os.write(buf, 0, size);
size = is.read(buf);
}
}
}
int size = is.read(buf);
while (size >= 0) {
os.write(buf, 0, size);
size = is.read(buf);
}
}
}
class FPBofoStream extends FileInputStream {
public void deflatorMisuse(byte[] in, byte[] out) {
Deflater compresser = new Deflater();
compresser.setInput(in);
compresser.finish();
compresser.deflate(out);
}
public FPBofoStream(File f) throws IOException {
super(f);
}
public void inflatorMisuse(byte[] in, byte[] out) throws DataFormatException {
Inflater expander = new Inflater();
expander.setInput(in);
expander.inflate(out);
}
}
class FPBofoStream extends FileInputStream {
public FPBofoStream(File f) throws IOException {
super(f);
}
}
}

0 comments on commit b25da66

Please sign in to comment.