diff options
Diffstat (limited to 'src/java/org/apache/fop/util')
-rw-r--r-- | src/java/org/apache/fop/util/ASCII85Constants.java | 58 | ||||
-rw-r--r-- | src/java/org/apache/fop/util/ASCII85InputStream.java | 161 | ||||
-rw-r--r-- | src/java/org/apache/fop/util/ASCII85OutputStream.java | 220 | ||||
-rw-r--r-- | src/java/org/apache/fop/util/ASCIIHexOutputStream.java | 102 | ||||
-rw-r--r-- | src/java/org/apache/fop/util/ContentHandlerFactoryRegistry.java | 9 | ||||
-rw-r--r-- | src/java/org/apache/fop/util/Finalizable.java | 42 | ||||
-rw-r--r-- | src/java/org/apache/fop/util/FlateEncodeOutputStream.java | 53 | ||||
-rw-r--r-- | src/java/org/apache/fop/util/RunLengthEncodeOutputStream.java | 186 | ||||
-rw-r--r-- | src/java/org/apache/fop/util/Service.java | 113 | ||||
-rw-r--r-- | src/java/org/apache/fop/util/SubInputStream.java | 92 |
10 files changed, 5 insertions, 1031 deletions
diff --git a/src/java/org/apache/fop/util/ASCII85Constants.java b/src/java/org/apache/fop/util/ASCII85Constants.java deleted file mode 100644 index e8e3a8bd1..000000000 --- a/src/java/org/apache/fop/util/ASCII85Constants.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright 1999-2004 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* $Id$ */ - -package org.apache.fop.util; - -/** - * This interface defines constants used by the ASCII85 filters. - * - * @author <a href="mailto:jeremias@apache.org">Jeremias Maerki</a> - * @version $Id$ - */ -public interface ASCII85Constants { - - /** Special character "z" stands for four NULL bytes (short-cut for !!!!!) */ - public static final int ZERO = 0x7A; //"z" - /** ZERO as a byte array */ - public static final byte[] ZERO_ARRAY = {(byte)ZERO}; - /** The start index for ASCII85 characters (!) */ - public static final int START = 0x21; //"!" - /** The end index for ASCII85 characters (u) */ - public static final int END = 0x75; //"u" - /** The EOL indicator (LF) */ - public static final int EOL = 0x0A; //"\n" - /** The EOD (end of data) indicator */ - public static final byte[] EOD = {0x7E, 0x3E}; //"~>" - - /** Array of powers of 85 (4, 3, 2, 1, 0) */ - public static final long POW85[] = new long[] {85 * 85 * 85 * 85, - 85 * 85 * 85, - 85 * 85, - 85, - 1}; - - /* - public static final long BASE85_4 = 85; - public static final long BASE85_3 = BASE85_4 * BASE85_4; - public static final long BASE85_2 = BASE85_3 * BASE85_4; - public static final long BASE85_1 = BASE85_2 * BASE85_4; - */ - -} - - diff --git a/src/java/org/apache/fop/util/ASCII85InputStream.java b/src/java/org/apache/fop/util/ASCII85InputStream.java deleted file mode 100644 index d9b3fae91..000000000 --- a/src/java/org/apache/fop/util/ASCII85InputStream.java +++ /dev/null @@ -1,161 +0,0 @@ -/* - * Copyright 1999-2004 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* $Id$ */ - -package org.apache.fop.util; - -import java.io.InputStream; -import java.io.IOException; - -/** - * This class applies a ASCII85 decoding to the stream. - * <p> - * The class is derived from InputStream instead of FilteredInputStream because - * we can use the read(byte[], int, int) method from InputStream which simply - * delegates to read(). This makes the implementation easier. - * <p> - * The filter is described in chapter 3.13.3 of the PostScript Language - * Reference (third edition). - * - * @version $Id$ - */ -public class ASCII85InputStream extends InputStream - implements ASCII85Constants { - - private InputStream in; - private boolean eodReached = false; - private int[] b = new int[4]; //decoded - private int bSize = 0; - private int bIndex = 0; - - /** @see java.io.FilterInputStream **/ - public ASCII85InputStream(InputStream in) { - super(); - this.in = in; - } - - /** @see java.io.FilterInputStream **/ - public int read() throws IOException { - //Check if we need to read the next tuple - if (bIndex >= bSize) { - if (eodReached) { - return -1; - } - readNextTuple(); - if (bSize == 0) { - if (!eodReached) { - throw new IllegalStateException("Internal error"); - } - return -1; - } - } - int result = b[bIndex]; - result = (result < 0 ? 256 + result : result); - bIndex++; - return result; - } - - private int filteredRead() throws IOException { - int buf; - while (true) { - buf = in.read(); - switch (buf) { - case 0: //null - case 9: //tab - case 10: //LF - case 12: //FF - case 13: //CR - case 32: //space - continue; //ignore - case ZERO: - case 126: //= EOD[0] = '~' - return buf; - default: - if ((buf >= START) && (buf <= END)) { - return buf; - } else { - throw new IOException("Illegal character detected: " + buf); - } - } - } - } - - private void handleEOD() throws IOException { - final int buf = in.read(); - if (buf != EOD[1]) { - throw new IOException("'>' expected after '~' (EOD)"); - } - eodReached = true; - bSize = 0; - bIndex = 0; - } - - private void readNextTuple() throws IOException { - int buf; - long tuple = 0; - //Read ahead and check for special "z" - buf = filteredRead(); - if (buf == ZERO) { - java.util.Arrays.fill(b, 0); - bSize = 4; - bIndex = 0; - } else if (buf == EOD[0]) { - handleEOD(); - } else { - int cIndex = 0; - tuple = (buf - START) * POW85[cIndex]; - cIndex++; - while (cIndex < 5) { - buf = filteredRead(); - if (buf == EOD[0]) { - handleEOD(); - break; - } else if (buf == ZERO) { - //Violation 2 - throw new IOException("Illegal 'z' within tuple"); - } else { - tuple += (buf - START) * POW85[cIndex]; - cIndex++; - } - } - int cSize = cIndex; - if (cSize == 1) { - //Violation 3 - throw new IOException("Only one character in tuple"); - } - //Handle optional, trailing, incomplete tuple - while (cIndex < 5) { - tuple += POW85[cIndex - 1]; - cIndex++; - } - if (tuple > (2L << 31) - 1) { - //Violation 1 - throw new IOException("Illegal tuple (> 2^32 - 1)"); - } - //Convert tuple - b[0] = (byte)((tuple >> 24) & 0xFF); - b[1] = (byte)((tuple >> 16) & 0xFF); - b[2] = (byte)((tuple >> 8) & 0xFF); - b[3] = (byte)((tuple) & 0xFF); - bSize = cSize - 1; - bIndex = 0; - } - } - -} - - diff --git a/src/java/org/apache/fop/util/ASCII85OutputStream.java b/src/java/org/apache/fop/util/ASCII85OutputStream.java deleted file mode 100644 index 02bc613dc..000000000 --- a/src/java/org/apache/fop/util/ASCII85OutputStream.java +++ /dev/null @@ -1,220 +0,0 @@ -/* - * Copyright 1999-2004 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* $Id$ */ - -package org.apache.fop.util; - -import java.io.OutputStream; -import java.io.FilterOutputStream; -import java.io.IOException; - -/** - * This class applies a ASCII85 encoding to the stream. - * - * @version $Id$ - */ -public class ASCII85OutputStream extends FilterOutputStream - implements ASCII85Constants, Finalizable { - - private static final boolean DEBUG = false; - - private int pos = 0; - private long buffer = 0; - private int posinline = 0; - private int bw = 0; - - /** @see java.io.FilterOutputStream **/ - public ASCII85OutputStream(OutputStream out) { - super(out); - } - - /** @see java.io.FilterOutputStream **/ - public void write(int b) throws IOException { - if (pos == 0) { - buffer += (b << 24) & 0xff000000L; - } else if (pos == 1) { - buffer += (b << 16) & 0xff0000L; - } else if (pos == 2) { - buffer += (b << 8) & 0xff00L; - } else { - buffer += b & 0xffL; - } - pos++; - - if (pos > 3) { - checkedWrite(convertWord(buffer)); - buffer = 0; - pos = 0; - } - } - - /* UNUSED ATM - private void checkedWrite(int b) throws IOException { - if (posinline == 80) { - out.write(EOL); bw++; - posinline = 0; - } - checkedWrite(b); - posinline++; - bw++; - }*/ - - private void checkedWrite(byte[] buf) throws IOException { - checkedWrite(buf, buf.length, false); - } - - private void checkedWrite(byte[] buf, boolean nosplit) throws IOException { - checkedWrite(buf, buf.length, nosplit); - } - - private void checkedWrite(byte[] buf , int len) throws IOException { - checkedWrite(buf, len, false); - } - - private void checkedWrite(byte[] buf , int len, boolean nosplit) throws IOException { - if (posinline + len > 80) { - int firstpart = (nosplit ? 0 : len - (posinline + len - 80)); - if (firstpart > 0) { - out.write(buf, 0, firstpart); - } - out.write(EOL); bw++; - int rest = len - firstpart; - if (rest > 0) { - out.write(buf, firstpart, rest); - } - posinline = rest; - } else { - out.write(buf, 0, len); - posinline += len; - } - bw += len; - } - - /** - * This converts a 32 bit value (4 bytes) into 5 bytes using base 85. - * each byte in the result starts with zero at the '!' character so - * the resulting base85 number fits into printable ascii chars - * - * @param word the 32 bit unsigned (hence the long datatype) word - * @return 5 bytes (or a single byte of the 'z' character for word - * values of 0) - */ - private byte[] convertWord(long word) { - word = word & 0xffffffff; - - if (word == 0) { - return ZERO_ARRAY; - } else { - if (word < 0) { - word = -word; - } - byte c1 = - (byte)((word - / POW85[0]) & 0xFF); - byte c2 = - (byte)(((word - (c1 * POW85[0])) - / POW85[1]) & 0xFF); - byte c3 = - (byte)(((word - (c1 * POW85[0]) - - (c2 * POW85[1])) - / POW85[2]) & 0xFF); - byte c4 = - (byte)(((word - (c1 * POW85[0]) - - (c2 * POW85[1]) - - (c3 * POW85[2])) - / POW85[3]) & 0xFF); - byte c5 = - (byte)(((word - (c1 * POW85[0]) - - (c2 * POW85[1]) - - (c3 * POW85[2]) - - (c4 * POW85[3]))) - & 0xFF); - - byte[] ret = { - (byte)(c1 + START), (byte)(c2 + START), - (byte)(c3 + START), (byte)(c4 + START), - (byte)(c5 + START) - }; - - if (DEBUG) { - for (int i = 0; i < ret.length; i++) { - if (ret[i] < 33 || ret[i] > 117) { - System.out.println("Illegal char value " - + new Integer(ret[i])); - } - } - } - return ret; - } - } - - /** @see Finalizable **/ - public void finalizeStream() throws IOException { - // now take care of the trailing few bytes. - // with n leftover bytes, we append 0 bytes to make a full group of 4 - // then convert like normal (except not applying the special zero rule) - // and write out the first n+1 bytes from the result - if (pos > 0) { - int rest = pos; - /* - byte[] lastdata = new byte[4]; - int i = 0; - for (int j = 0; j < 4; j++) { - if (j < rest) { - lastdata[j] = data[i++]; - } else { - lastdata[j] = 0; - } - } - - long val = ((lastdata[0] << 24) & 0xff000000L) - + ((lastdata[1] << 16) & 0xff0000L) - + ((lastdata[2] << 8) & 0xff00L) - + (lastdata[3] & 0xffL); - */ - - byte[] conv; - // special rule for handling zeros at the end - if (buffer != 0) { - conv = convertWord(buffer); - } else { - conv = new byte[5]; - for (int j = 0; j < 5; j++) { - conv[j] = (byte)'!'; - } - } - // assert rest+1 <= 5 - checkedWrite(conv, rest + 1); - } - // finally write the two character end of data marker - checkedWrite(EOD, true); - - flush(); - if (out instanceof Finalizable) { - ((Finalizable)out).finalizeStream(); - } - } - - /** @see java.io.FilterOutputStream **/ - public void close() throws IOException { - finalizeStream(); - super.close(); - } - -} - - diff --git a/src/java/org/apache/fop/util/ASCIIHexOutputStream.java b/src/java/org/apache/fop/util/ASCIIHexOutputStream.java deleted file mode 100644 index d2ac48a3e..000000000 --- a/src/java/org/apache/fop/util/ASCIIHexOutputStream.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright 1999-2004 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* $Id$ */ - -package org.apache.fop.util; - -import java.io.OutputStream; -import java.io.FilterOutputStream; -import java.io.IOException; - -/** - * This class applies a ASCII Hex encoding to the stream. - * - * @author <a href="mailto:jeremias@apache.org">Jeremias Maerki</a> - * @version $Id$ - */ -public class ASCIIHexOutputStream extends FilterOutputStream - implements Finalizable { - - private static final int EOL = 0x0A; //"\n" - private static final int EOD = 0x3E; //">" - private static final int ZERO = 0x30; //"0" - private static final int NINE = 0x39; //"9" - private static final int A = 0x41; //"A" - private static final int ADIFF = A - NINE - 1; - - private int posinline = 0; - - - /** @see java.io.FilterOutputStream **/ - public ASCIIHexOutputStream(OutputStream out) { - super(out); - } - - - /** @see java.io.FilterOutputStream **/ - public void write(int b) throws IOException { - b &= 0xFF; - - int digit1 = ((b & 0xF0) >> 4) + ZERO; - if (digit1 > NINE) { - digit1 += ADIFF; - } - out.write(digit1); - - int digit2 = (b & 0x0F) + ZERO; - if (digit2 > NINE) { - digit2 += ADIFF; - } - out.write(digit2); - - posinline++; - checkLineWrap(); - } - - - private void checkLineWrap() throws IOException { - //Maximum line length is 80 characters - if (posinline >= 40) { - out.write(EOL); - posinline = 0; - } - } - - - /** @see Finalizable **/ - public void finalizeStream() throws IOException { - checkLineWrap(); - //Write closing character ">" - super.write(EOD); - - flush(); - if (out instanceof Finalizable) { - ((Finalizable) out).finalizeStream(); - } - } - - - /** @see java.io.FilterOutputStream **/ - public void close() throws IOException { - finalizeStream(); - super.close(); - } - - -} - - diff --git a/src/java/org/apache/fop/util/ContentHandlerFactoryRegistry.java b/src/java/org/apache/fop/util/ContentHandlerFactoryRegistry.java index 5fd68fd2b..3d95d91a3 100644 --- a/src/java/org/apache/fop/util/ContentHandlerFactoryRegistry.java +++ b/src/java/org/apache/fop/util/ContentHandlerFactoryRegistry.java @@ -24,7 +24,7 @@ import java.util.Map; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.fop.util.Service; +import org.apache.xmlgraphics.util.Service; /** * This class holds references to various XML handlers used by FOP. It also @@ -101,12 +101,13 @@ public class ContentHandlerFactoryRegistry { Iterator providers = Service.providers(ContentHandlerFactory.class); if (providers != null) { while (providers.hasNext()) { - String str = (String)providers.next(); + ContentHandlerFactory factory = (ContentHandlerFactory)providers.next(); try { if (log.isDebugEnabled()) { - log.debug("Dynamically adding ContentHandlerFactory: " + str); + log.debug("Dynamically adding ContentHandlerFactory: " + + factory.getClass().getName()); } - addContentHandlerFactory(str); + addContentHandlerFactory(factory); } catch (IllegalArgumentException e) { log.error("Error while adding ContentHandlerFactory", e); } diff --git a/src/java/org/apache/fop/util/Finalizable.java b/src/java/org/apache/fop/util/Finalizable.java deleted file mode 100644 index 365f0cae6..000000000 --- a/src/java/org/apache/fop/util/Finalizable.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 1999-2004 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* $Id$ */ - -package org.apache.fop.util; - -/** - * This interface is used for special FilteredOutputStream classes that won't - * be closed (since this causes the target OutputStream to be closed, too) but - * where flush() is not enough, for example because a final marker has to be - * written to the target stream. - * - * @author <a href="mailto:jeremias@apache.org">Jeremias Maerki</a> - * @version $Id$ - */ -public interface Finalizable { - - /** - * This method can be called instead of close() on a subclass of - * FilteredOutputStream when a final marker has to be written to the target - * stream, but close() cannot be called. - * - * @exception java.io.IOException In case of an IO problem - */ - void finalizeStream() - throws java.io.IOException; - -} diff --git a/src/java/org/apache/fop/util/FlateEncodeOutputStream.java b/src/java/org/apache/fop/util/FlateEncodeOutputStream.java deleted file mode 100644 index 9789929e4..000000000 --- a/src/java/org/apache/fop/util/FlateEncodeOutputStream.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright 1999-2004 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* $Id$ */ - -package org.apache.fop.util; - -import java.io.OutputStream; -import java.io.IOException; - -/** - * This class applies a FlateEncode filter to the stream. It is basically the - * normal DeflaterOutputStream except now also implementing the Finalizable - * interface. - * - * @author <a href="mailto:jeremias@apache.org">Jeremias Maerki</a> - * @version $Id$ - */ -public class FlateEncodeOutputStream extends java.util.zip.DeflaterOutputStream - implements Finalizable { - - - /** @see java.util.zip.DeflaterOutputStream **/ - public FlateEncodeOutputStream(OutputStream out) { - super(out); - } - - - /** @see Finalizable **/ - public void finalizeStream() throws IOException { - finish(); - flush(); - if (out instanceof Finalizable) { - ((Finalizable)out).finalizeStream(); - } - } - -} - - diff --git a/src/java/org/apache/fop/util/RunLengthEncodeOutputStream.java b/src/java/org/apache/fop/util/RunLengthEncodeOutputStream.java deleted file mode 100644 index f3cd225be..000000000 --- a/src/java/org/apache/fop/util/RunLengthEncodeOutputStream.java +++ /dev/null @@ -1,186 +0,0 @@ -/* - * Copyright 1999-2004 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* $Id$ */ - -package org.apache.fop.util; - -import java.io.FilterOutputStream; -import java.io.OutputStream; -import java.io.IOException; - - -/** - * This class applies a RunLengthEncode filter to the stream. - * - * @author <a href="mailto:smwolke@geistig.com">Stephen Wolke</a> - * @version $Id$ - */ -public class RunLengthEncodeOutputStream extends FilterOutputStream - implements Finalizable { - - private static final int MAX_SEQUENCE_COUNT = 127; - private static final int END_OF_DATA = 128; - private static final int BYTE_MAX = 256; - - private static final int NOT_IDENTIFY_SEQUENCE = 0; - private static final int START_SEQUENCE = 1; - private static final int IN_SEQUENCE = 2; - private static final int NOT_IN_SEQUENCE = 3; - - private int runCount = 0; - private int isSequence = NOT_IDENTIFY_SEQUENCE; - private byte[] runBuffer = new byte[MAX_SEQUENCE_COUNT + 1]; - - - /** @see java.io.FilterOutputStream **/ - public RunLengthEncodeOutputStream(OutputStream out) { - super(out); - } - - - /** @see java.io.FilterOutputStream **/ - public void write(byte b) - throws java.io.IOException { - runBuffer[runCount] = b; - - switch (runCount) { - case 0: - runCount = 0; - isSequence = NOT_IDENTIFY_SEQUENCE; - runCount++; - break; - case 1: - if (runBuffer[runCount] != runBuffer[runCount - 1]) { - isSequence = NOT_IN_SEQUENCE; - } - runCount++; - break; - case 2: - if (runBuffer[runCount] != runBuffer[runCount - 1]) { - isSequence = NOT_IN_SEQUENCE; - } else { - if (isSequence == NOT_IN_SEQUENCE) { - isSequence = START_SEQUENCE; - } else { - isSequence = IN_SEQUENCE; - } - } - runCount++; - break; - case MAX_SEQUENCE_COUNT: - if (isSequence == IN_SEQUENCE) { - out.write(BYTE_MAX - (MAX_SEQUENCE_COUNT - 1)); - out.write(runBuffer[runCount - 1]); - runBuffer[0] = runBuffer[runCount]; - runCount = 1; - } else { - out.write(MAX_SEQUENCE_COUNT); - out.write(runBuffer, 0, runCount + 1); - runCount = 0; - } - isSequence = NOT_IDENTIFY_SEQUENCE; - break; - default: - switch (isSequence) { - case IN_SEQUENCE: - if (runBuffer[runCount] != runBuffer[runCount - 1]) { - out.write(BYTE_MAX - (runCount - 1)); - out.write(runBuffer[runCount - 1]); - runBuffer[0] = runBuffer[runCount]; - runCount = 1; - isSequence = NOT_IDENTIFY_SEQUENCE; - break; - } - runCount++; - break; - case NOT_IN_SEQUENCE: - if (runBuffer[runCount] == runBuffer[runCount - 1]) { - isSequence = START_SEQUENCE; - } - runCount++; - break; - case START_SEQUENCE: - if (runBuffer[runCount] == runBuffer[runCount - 1]) { - out.write(runCount - 3); - out.write(runBuffer, 0, runCount - 2); - runBuffer[0] = runBuffer[runCount]; - runBuffer[1] = runBuffer[runCount]; - runBuffer[2] = runBuffer[runCount]; - runCount = 3; - isSequence = IN_SEQUENCE; - break; - } else { - isSequence = NOT_IN_SEQUENCE; - runCount++; - break; - } - } - } - } - - - /** @see java.io.FilterOutputStream **/ - public void write(byte[] b) - throws IOException { - - for (int i = 0; i < b.length; i++) { - this.write(b[i]); - } - } - - - /** @see java.io.FilterOutputStream **/ - public void write(byte[] b, int off, int len) - throws IOException { - - for (int i = 0; i < len; i++) { - this.write(b[off + i]); - } - } - - - /** @see Finalizable **/ - public void finalizeStream() - throws IOException { - switch (isSequence) { - case IN_SEQUENCE: - out.write(BYTE_MAX - (runCount - 1)); - out.write(runBuffer[runCount - 1]); - break; - default: - out.write(runCount - 1); - out.write(runBuffer, 0, runCount); - } - - out.write(END_OF_DATA); - - flush(); - if (out instanceof Finalizable) { - ((Finalizable) out).finalizeStream(); - } - } - - - /** @see java.io.FilterOutputStream **/ - public void close() - throws IOException { - finalizeStream(); - super.close(); - } - -} - diff --git a/src/java/org/apache/fop/util/Service.java b/src/java/org/apache/fop/util/Service.java deleted file mode 100644 index 717b0f47f..000000000 --- a/src/java/org/apache/fop/util/Service.java +++ /dev/null @@ -1,113 +0,0 @@ -/*
- * Copyright 1999-2005 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/* $Id$ */
-
-package org.apache.fop.util;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.Reader;
-import java.util.Enumeration;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-//code stolen from org.apache.batik.util and modified slightly
-//does what sun.misc.Service probably does, but it cannot be relied on.
-//hopefully will be part of standard jdk sometime.
-
-/**
- * This class loads services present in the class path.
- */
-public class Service {
-
- private static Map providerMap = new java.util.Hashtable();
-
- public static synchronized Iterator providers(Class cls) {
- ClassLoader cl = cls.getClassLoader();
- // null if loaded by bootstrap class loader
- if (cl == null) {
- cl = ClassLoader.getSystemClassLoader();
- }
- String serviceFile = "META-INF/services/" + cls.getName();
-
- // log.debug("File: " + serviceFile);
-
- List lst = (List)providerMap.get(serviceFile);
- if (lst != null) {
- return lst.iterator();
- }
-
- lst = new java.util.Vector();
- providerMap.put(serviceFile, lst);
-
- Enumeration e;
- try {
- e = cl.getResources(serviceFile);
- } catch (IOException ioe) {
- return lst.iterator();
- }
-
- while (e.hasMoreElements()) {
- try {
- java.net.URL u = (java.net.URL)e.nextElement();
- //log.debug("URL: " + u);
-
- InputStream is = u.openStream();
- Reader r = new InputStreamReader(is, "UTF-8");
- BufferedReader br = new BufferedReader(r);
-
- String line = br.readLine();
- while (line != null) {
- try {
- // First strip any comment...
- int idx = line.indexOf('#');
- if (idx != -1) {
- line = line.substring(0, idx);
- }
-
- // Trim whitespace.
- line = line.trim();
-
- // If nothing left then loop around...
- if (line.length() == 0) {
- line = br.readLine();
- continue;
- }
- // log.debug("Line: " + line);
-
- // Try and load the class
- // Object obj = cl.loadClass(line).newInstance();
- // stick it into our vector...
- lst.add(line);
- } catch (Exception ex) {
- // Just try the next line
- }
-
- line = br.readLine();
- }
- } catch (Exception ex) {
- // Just try the next file...
- }
-
- }
- return lst.iterator();
- }
-
- }
\ No newline at end of file diff --git a/src/java/org/apache/fop/util/SubInputStream.java b/src/java/org/apache/fop/util/SubInputStream.java deleted file mode 100644 index 83b146402..000000000 --- a/src/java/org/apache/fop/util/SubInputStream.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright 2005 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* $Id$ */ - -package org.apache.fop.util; - -import java.io.FilterInputStream; -import java.io.IOException; -import java.io.InputStream; - -/** - * This class is a FilterInputStream descendant that reads from an underlying InputStream - * up to a defined number of bytes or the end of the underlying stream. Closing this InputStream - * will not result in the underlying InputStream to be closed, too. - * <p> - * This InputStream can be used to read chunks from a larger file of which the length is - * known in advance. - */ -public class SubInputStream extends FilterInputStream { - - /** Indicates the number of bytes remaning to be read from the underlying InputStream. */ - private long bytesToRead; - - /** - * Creates a new SubInputStream. - * @param in the InputStream to read from - * @param maxLen the maximum number of bytes to read from the underlying InputStream until - * the end-of-file is signalled. - */ - public SubInputStream(InputStream in, long maxLen) { - super(in); - this.bytesToRead = maxLen; - } - - /** @see java.io.InputStream#read() */ - public int read() throws IOException { - if (bytesToRead > 0) { - int result = super.read(); - if (result <= 0) { - bytesToRead--; - return result; - } else { - return -1; - } - } else { - return -1; - } - } - - /** @see java.io.InputStream#read(byte[], int, int) */ - public int read(byte[] b, int off, int len) throws IOException { - if (bytesToRead == 0) { - return -1; - } - int effRead = (int)Math.min(bytesToRead, len); - //cast to int is safe because len can never be bigger than Integer.MAX_VALUE - - int result = super.read(b, off, effRead); - if (result >= 0) { - bytesToRead -= result; - } - return result; - } - - /** @see java.io.InputStream#skip(long) */ - public long skip(long n) throws IOException { - long effRead = Math.min(bytesToRead, n); - long result = super.skip(effRead); - bytesToRead -= result; - return result; - } - - /** @see java.io.InputStream#close() */ - public void close() throws IOException { - //Don't close the underlying InputStream!!! - this.bytesToRead = 0; - } -} |