/* * $Id$ * Copyright (C) 2001-2002 The Apache Software Foundation. All rights reserved. * For details on use and redistribution please refer to the * LICENSE file included with these sources. */packageorg.apache.fop.pdf;importjava.io.OutputStream;importjava.io.InputStream;importjava.io.Writer;importjava.io.OutputStreamWriter;importjava.io.IOException;/** * ASCII Hex filter for PDF streams. * This filter converts a pdf stream to ASCII hex data. */publicclassASCIIHexFilterextendsPDFFilter{privatestaticfinalStringASCIIHEX_EOD=">";/** * Get the name of this filter. * * @return the name of this filter for pdf */publicStringgetName(){return"/ASCIIHexDecode";}/** * Get the decode params. * * @return always null */publicStringgetDecodeParms(){returnnull;}/** * Encode the pdf stream using this filter. * * @param in the input stream to read the data from * @param out the output stream to write data to * @param length the length of data to read from the stream * @throws IOException if an error occurs reading or writing to * the streams */publicvoidencode(InputStreamin,OutputStreamout,intlength)throwsIOException{Writerwriter=newOutputStreamWriter(out);for(inti=0;i<length;i++){intval=(int)(in.read()&0xFF);if(val<16){writer.write("0");}writer.write(Integer.toHexString(val));}writer.write(ASCIIHEX_EOD);writer.close();}}