}
ByteArrayInputStream bin = new ByteArrayInputStream(baout.toByteArray());
+ IOUtils.closeQuietly(baout);
DataInputStream din = new DataInputStream(bin);
long len = din.readInt() & 0xFFFFFFFFL;
println("Length: " + len);
import java.awt.Color;
import java.awt.color.ColorSpace;
-import java.io.DataOutput;
+import java.io.DataOutputStream;
import java.io.IOException;
import java.io.OutputStream;
+import org.apache.commons.io.IOUtils;
import org.apache.commons.io.output.ByteArrayOutputStream;
import org.apache.xmlgraphics.java2d.color.CIELabColorSpace;
ColorSpace cs = color.getColorSpace();
int colSpaceType = cs.getType();
ByteArrayOutputStream baout = new ByteArrayOutputStream();
+ DataOutputStream dout = null;
byte[] colsizes;
if (colSpaceType == ColorSpace.TYPE_CMYK) {
colspace = CMYK;
} else if (cs instanceof CIELabColorSpace) {
colspace = CIELAB;
colsizes = new byte[] {0x08, 0x08, 0x08, 0x00};
- DataOutput dout = new java.io.DataOutputStream(baout);
+ dout = new DataOutputStream(baout);
//According to GOCA, I'd expect the multiplicator below to be 255f, not 100f
//But only IBM AFP Workbench seems to support Lab colors and it requires "c * 100f"
int l = Math.round(colorComponents[0] * 100f);
dout.writeByte(a);
dout.writeByte(b);
} else {
+ IOUtils.closeQuietly(dout);
+ IOUtils.closeQuietly(baout);
throw new IllegalStateException();
}
os.write(data);
baout.writeTo(os);
+ IOUtils.closeQuietly(dout);
+ IOUtils.closeQuietly(baout);
}
/** {@inheritDoc} */
short sh2 = in.readByte();
if (sh1 == 128 && sh2 == 1) {
//Found the first section header of a PFB file!
+ IOUtils.closeQuietly(in);
throw new IOException("Cannot parse PFM file. You probably specified the PFB file"
+ " of a Type 1 font as parameter instead of the PFM.");
}
bufin.read(b);
if (new String(b, "US-ASCII").equalsIgnoreCase("StartFontMetrics")) {
//Found the header of a AFM file!
+ IOUtils.closeQuietly(in);
throw new IOException("Cannot parse PFM file. You probably specified the AFM file"
+ " of a Type 1 font as parameter instead of the PFM.");
}
import org.xml.sax.InputSource;
+import org.apache.commons.io.IOUtils;
+
/**
* <p>This tree structure stores the hyphenation patterns in an efficient
* way for fast lookup. It provides the provides the method to
token = in.readLine().trim();
long starttime = 0;
int counter = 0;
+ BufferedReader reader = null;
try {
- BufferedReader reader
- = new BufferedReader(new FileReader(token));
+ reader = new BufferedReader(new FileReader(token));
String line;
starttime = System.currentTimeMillis();
} catch (Exception ioe) {
System.out.println("Exception " + ioe);
ioe.printStackTrace();
+ } finally {
+ IOUtils.closeQuietly(reader);
}
long endtime = System.currentTimeMillis();
long result = endtime - starttime;
int magic = EndianUtils.swapInteger(din.readInt());
din.reset();
if (magic != WMFConstants.META_ALDUS_APM) {
+ IOUtils.closeQuietly(din);
return null; //Not a WMF file
}
log.error(
"Failed to write CIDSet [" + cidFont + "] "
+ cidFont.getEmbedFontName(), ioe);
+ } finally {
+ IOUtils.closeQuietly(baout);
}
}
import java.io.IOException;
+import org.apache.commons.io.IOUtils;
import org.apache.commons.io.output.ByteArrayOutputStream;
/**
} catch (IOException ioe) {
log.error("Ignored I/O exception", ioe);
}
- return bout.toByteArray();
+ byte[] bytes = bout.toByteArray();
+ IOUtils.closeQuietly(bout);
+ return bytes;
}
import java.text.DecimalFormatSymbols;
import java.util.Locale;
+import org.apache.commons.io.IOUtils;
import org.apache.commons.io.output.ByteArrayOutputStream;
import org.apache.xmlgraphics.image.GraphicsUtil;
writeCommand("*c" + patternID + "G");
writeCommand("*c" + baout.size() + "W");
baout.writeTo(this.out);
+ IOUtils.closeQuietly(data);
+ IOUtils.closeQuietly(baout);
writeCommand("*c4Q"); //temporary pattern
}
import java.io.IOException;
import java.util.Arrays;
+import org.apache.commons.io.IOUtils;
import org.apache.commons.io.output.ByteArrayOutputStream;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+ " The image may not be handled correctly." + " Base color space: "
+ icm.getColorSpace() + " Image: " + image.getInfo());
}
- ByteArrayOutputStream baout = new ByteArrayOutputStream();
int c = icm.getMapSize();
int hival = c - 1;
if (hival > MAX_HIVAL) {
throw new UnsupportedOperationException("hival must not go beyond " + MAX_HIVAL);
}
+ ByteArrayOutputStream baout = new ByteArrayOutputStream();
boolean isDeviceGray = false;
int[] palette = new int[c];
icm.getRGBs(palette);
indexed.add(hival);
indexed.add(baout.toByteArray());
+ IOUtils.closeQuietly(baout);
dict.put("ColorSpace", indexed);
import java.util.List;
import java.util.StringTokenizer;
+import org.apache.commons.io.IOUtils;
import org.apache.tools.ant.BuildException;
/**
* @return true if files are same byte-by-byte, false otherwise
*/
private static boolean compareBytes(File file1, File file2) throws IOException {
+ boolean same = true;
BufferedInputStream file1Input
= new BufferedInputStream(new java.io.FileInputStream(file1));
BufferedInputStream file2Input
charact1 = file1Input.read();
charact2 = file2Input.read();
} else {
- return false;
+ same = false;
+ break;
}
}
- return true;
+ IOUtils.closeQuietly(file1Input);
+ IOUtils.closeQuietly(file2Input);
+
+ return same;
}
/**