From 195f60f264f5af9aaba5239e0a80b6ca29616bfb Mon Sep 17 00:00:00 2001 From: Jeremias Maerki Date: Mon, 13 Nov 2006 17:42:28 +0000 Subject: [PATCH] Bugzilla #40387: Dealing with IOExceptions for certain large PFM files in a more radical way: load everything into memory, since we basically need random access here. The biggest PFMs I've seen so far are around 20KB so this shouldn't be a big problem, especially as the memory is freed pretty quickly. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@474410 13f79535-47bb-0310-9956-ffa450edef68 --- src/java/org/apache/fop/fonts/type1/PFMFile.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/java/org/apache/fop/fonts/type1/PFMFile.java b/src/java/org/apache/fop/fonts/type1/PFMFile.java index 4a009ae38..b2d2ee933 100644 --- a/src/java/org/apache/fop/fonts/type1/PFMFile.java +++ b/src/java/org/apache/fop/fonts/type1/PFMFile.java @@ -21,10 +21,12 @@ package org.apache.fop.fonts.type1; // Java import java.io.BufferedInputStream; +import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.util.Map; +import org.apache.commons.io.IOUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -76,12 +78,11 @@ public class PFMFile { * @throws IOException In case of an I/O problem */ public void load(InputStream inStream) throws IOException { + byte[] pfmBytes = IOUtils.toByteArray(inStream); InputStream bufin = inStream; - if (!bufin.markSupported()) { - bufin = new BufferedInputStream(bufin); - } + bufin = new ByteArrayInputStream(pfmBytes); PFMInputStream in = new PFMInputStream(bufin); - bufin.mark(16); + bufin.mark(512); short sh1 = in.readByte(); short sh2 = in.readByte(); if (sh1 == 128 && sh2 == 1) { -- 2.39.5