From d1699f53b71bf38df92430ed019f327156341840 Mon Sep 17 00:00:00 2001 From: Jeremias Maerki Date: Fri, 6 Feb 2004 21:49:48 +0000 Subject: [PATCH] Adapt to changes in Commons IO's APIs. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@197334 13f79535-47bb-0310-9956-ffa450edef68 --- .../fop/fonts/truetype/FontFileReader.java | 16 +++++----------- .../fop/fonts/truetype/TTFDirTabEntry.java | 19 +++++++++++++++++-- .../org/apache/fop/fonts/type1/PFBParser.java | 6 +++--- .../org/apache/fop/fonts/type1/PFMFile.java | 6 +++--- src/java/org/apache/fop/pdf/PDFFactory.java | 6 +++--- .../apache/fop/pdf/TempFileStreamCache.java | 6 +++--- .../rtf/rtflib/rtfdoc/RtfExternalGraphic.java | 8 ++++---- .../fop/util/ASCII85InputStreamTestCase.java | 4 ++-- 8 files changed, 40 insertions(+), 31 deletions(-) diff --git a/src/java/org/apache/fop/fonts/truetype/FontFileReader.java b/src/java/org/apache/fop/fonts/truetype/FontFileReader.java index d141435c6..61c3a0eda 100644 --- a/src/java/org/apache/fop/fonts/truetype/FontFileReader.java +++ b/src/java/org/apache/fop/fonts/truetype/FontFileReader.java @@ -4,7 +4,7 @@ * The Apache Software License, Version 1.1 * ============================================================================ * - * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * Copyright (C) 1999-2004 The Apache Software Foundation. All rights reserved. * * Redistribution and use in source and binary forms, with or without modifica- * tion, are permitted provided that the following conditions are met: @@ -54,7 +54,7 @@ import java.io.InputStream; import java.io.File; import java.io.IOException; -import org.apache.commons.io.IOUtil; +import org.apache.commons.io.IOUtils; /** * Reads a TrueType font file into a byte array and @@ -73,15 +73,9 @@ public class FontFileReader { * @throws IOException In case of an I/O problem */ private void init(InputStream in) throws java.io.IOException { - java.io.ByteArrayOutputStream bout = new java.io.ByteArrayOutputStream(); - try { - IOUtil.copy(in, bout); - this.file = bout.toByteArray(); - this.fsize = this.file.length; - this.current = 0; - } finally { - bout.close(); - } + this.file = IOUtils.toByteArray(in); + this.fsize = this.file.length; + this.current = 0; } /** diff --git a/src/java/org/apache/fop/fonts/truetype/TTFDirTabEntry.java b/src/java/org/apache/fop/fonts/truetype/TTFDirTabEntry.java index 6907cb27d..1e89b562c 100644 --- a/src/java/org/apache/fop/fonts/truetype/TTFDirTabEntry.java +++ b/src/java/org/apache/fop/fonts/truetype/TTFDirTabEntry.java @@ -51,6 +51,7 @@ package org.apache.fop.fonts.truetype; import java.io.IOException; +import java.io.UnsupportedEncodingException; /** @@ -76,9 +77,11 @@ class TTFDirTabEntry { offset = in.readTTFULong(); length = in.readTTFULong(); + String tagStr = new String(tag, "ISO-8859-1"); + // System.err.println("tag='" + tagStr + "'"); //System.out.println(this.toString()); - return new String(tag, "ISO-8859-1"); + return tagStr; } @@ -115,11 +118,23 @@ class TTFDirTabEntry { } /** - * Returns the tag. + * Returns the tag bytes. * @return byte[] */ public byte[] getTag() { return tag; } + /** + * Returns the tag bytes. + * @return byte[] + */ + public String getTagString() { + try { + return new String(tag, "ISO-8859-1"); + } catch (UnsupportedEncodingException e) { + return this.toString(); // Should never happen. + } + } + } diff --git a/src/java/org/apache/fop/fonts/type1/PFBParser.java b/src/java/org/apache/fop/fonts/type1/PFBParser.java index e59bc94b2..a1badc402 100644 --- a/src/java/org/apache/fop/fonts/type1/PFBParser.java +++ b/src/java/org/apache/fop/fonts/type1/PFBParser.java @@ -4,7 +4,7 @@ * The Apache Software License, Version 1.1 * ============================================================================ * - * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * Copyright (C) 1999-2004 The Apache Software Foundation. All rights reserved. * * Redistribution and use in source and binary forms, with or without modifica- * tion, are permitted provided that the following conditions are met: @@ -56,7 +56,7 @@ import java.io.DataInputStream; import java.io.BufferedInputStream; //Commons -import org.apache.commons.io.IOUtil; +import org.apache.commons.io.IOUtils; /** * This class represents a parser for Adobe Type 1 PFB files. @@ -261,7 +261,7 @@ public class PFBParser { private void parseRAWFormat(PFBData pfb, BufferedInputStream bin) throws IOException { - calcLengths(pfb, IOUtil.toByteArray(bin)); + calcLengths(pfb, IOUtils.toByteArray(bin)); } } \ No newline at end of file diff --git a/src/java/org/apache/fop/fonts/type1/PFMFile.java b/src/java/org/apache/fop/fonts/type1/PFMFile.java index 58a7cceb5..bc74c6cfe 100644 --- a/src/java/org/apache/fop/fonts/type1/PFMFile.java +++ b/src/java/org/apache/fop/fonts/type1/PFMFile.java @@ -4,7 +4,7 @@ * The Apache Software License, Version 1.1 * ============================================================================ * - * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * Copyright (C) 1999-2004 The Apache Software Foundation. All rights reserved. * * Redistribution and use in source and binary forms, with or without modifica- * tion, are permitted provided that the following conditions are met: @@ -57,7 +57,7 @@ import java.util.Map; // Apache libs import org.apache.avalon.framework.logger.AbstractLogEnabled; -import org.apache.commons.io.IOUtil; +import org.apache.commons.io.IOUtils; // FOP import org.apache.fop.fonts.Glyphs; @@ -101,7 +101,7 @@ public class PFMFile extends AbstractLogEnabled { * @throws IOException In case of an I/O problem */ public void load(InputStream inStream) throws IOException { - final byte[] buf = IOUtil.toByteArray(inStream); + final byte[] buf = IOUtils.toByteArray(inStream); final InputStream bufin = new java.io.ByteArrayInputStream(buf); PFMInputStream in = new PFMInputStream(bufin); /*final int version =*/ in.readShort(); diff --git a/src/java/org/apache/fop/pdf/PDFFactory.java b/src/java/org/apache/fop/pdf/PDFFactory.java index fc9a19640..ff6afd3e7 100644 --- a/src/java/org/apache/fop/pdf/PDFFactory.java +++ b/src/java/org/apache/fop/pdf/PDFFactory.java @@ -4,7 +4,7 @@ * The Apache Software License, Version 1.1 * ============================================================================ * - * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * Copyright (C) 1999-2004 The Apache Software Foundation. All rights reserved. * * Redistribution and use in source and binary forms, with or without modifica- * tion, are permitted provided that the following conditions are met: @@ -59,7 +59,7 @@ import java.util.Map; // Apache libs import org.apache.avalon.framework.container.ContainerUtil; -import org.apache.commons.io.IOUtil; +import org.apache.commons.io.IOUtils; // FOP import org.apache.fop.fonts.CIDFont; @@ -1180,7 +1180,7 @@ public class PDFFactory { embeddedFont = new PDFT1Stream(); ((PDFT1Stream)embeddedFont).setData(pfb); } else { - byte[] file = IOUtil.toByteArray(in); + byte[] file = IOUtils.toByteArray(in); embeddedFont = new PDFTTFStream(file.length); ((PDFTTFStream)embeddedFont).setData(file, file.length); } diff --git a/src/java/org/apache/fop/pdf/TempFileStreamCache.java b/src/java/org/apache/fop/pdf/TempFileStreamCache.java index a387b9a1b..50cef94ef 100644 --- a/src/java/org/apache/fop/pdf/TempFileStreamCache.java +++ b/src/java/org/apache/fop/pdf/TempFileStreamCache.java @@ -4,7 +4,7 @@ * The Apache Software License, Version 1.1 * ============================================================================ * - * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * Copyright (C) 1999-2004 The Apache Software Foundation. All rights reserved. * * Redistribution and use in source and binary forms, with or without modifica- * tion, are permitted provided that the following conditions are met: @@ -57,7 +57,7 @@ import java.io.IOException; import java.io.File; //Commons -import org.apache.commons.io.IOUtil; +import org.apache.commons.io.CopyUtils; /** * StreamCache implementation that uses temporary files rather than heap. @@ -124,7 +124,7 @@ public class TempFileStreamCache implements StreamCache { // don't need a buffer because streamCopy is buffered InputStream input = new java.io.FileInputStream(tempFile); - final long bytesCopied = IOUtil.copy(input, out); + final long bytesCopied = CopyUtils.copy(input, out); input.close(); return (int)bytesCopied; } diff --git a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfExternalGraphic.java b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfExternalGraphic.java index ea861511b..0e648a488 100644 --- a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfExternalGraphic.java +++ b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfExternalGraphic.java @@ -4,7 +4,7 @@ * The Apache Software License, Version 1.1 * ============================================================================ * - * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * Copyright (C) 1999-2004 The Apache Software Foundation. All rights reserved. * * Redistribution and use in source and binary forms, with or without modifica- * tion, are permitted provided that the following conditions are met: @@ -58,7 +58,7 @@ package org.apache.fop.render.rtf.rtflib.rtfdoc; -import org.apache.commons.io.IOUtil; +import org.apache.commons.io.IOUtils; import org.apache.fop.render.rtf.rtflib.tools.ImageConstants; import org.apache.fop.render.rtf.rtflib.tools.ImageUtil; //import org.apache.fop.render.rtf.rtflib.tools.jpeg.Encoder; @@ -248,9 +248,9 @@ public class RtfExternalGraphic extends RtfElement { try { final InputStream in = url.openStream(); try { - imagedata = IOUtil.toByteArray(url.openStream()); + imagedata = IOUtils.toByteArray(url.openStream()); } finally { - IOUtil.shutdownStream(in); + IOUtils.closeQuietly(in); } } catch (Exception e) { throw new ExternalGraphicException("The attribute 'src' of " diff --git a/test/java/org/apache/fop/util/ASCII85InputStreamTestCase.java b/test/java/org/apache/fop/util/ASCII85InputStreamTestCase.java index 33387894e..df7259d58 100644 --- a/test/java/org/apache/fop/util/ASCII85InputStreamTestCase.java +++ b/test/java/org/apache/fop/util/ASCII85InputStreamTestCase.java @@ -54,7 +54,7 @@ import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; -import org.apache.commons.io.IOUtil; +import org.apache.commons.io.CopyUtils; import org.apache.commons.io.output.ByteArrayOutputStream; import org.apache.fop.pdf.PDFText; @@ -85,7 +85,7 @@ public class ASCII85InputStreamTestCase extends TestCase { InputStream in = new ByteArrayInputStream(ascii85); InputStream decoder = new ASCII85InputStream(in); ByteArrayOutputStream baout = new ByteArrayOutputStream(); - IOUtil.copy(decoder, baout); + CopyUtils.copy(decoder, baout); baout.close(); return baout.toByteArray(); } -- 2.39.5