/** * Copyright (c) 2006 by Know-Center, Graz, Austria * * This software is the confidential and proprietary information of Know-Center, * Graz, Austria. You shall not disclose such Confidential Information and shall * use it only in accordance with the terms of the license agreement you entered * into with Know-Center. * * KNOW-CENTER MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR * NON-INFRINGEMENT. KNOW-CENTER SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY * LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS * DERIVATIVES. * * $Id: Utils.java,v 1.3 2006/10/31 08:13:02 wprinz Exp $ */ package at.knowcenter.wag.egov.egiz.pdf; import java.io.IOException; import java.io.PrintWriter; import java.io.StringWriter; /** * Abstract class that contains helpful utility functions used by the digital * signatures. * * @author wprinz */ public abstract class Utils { /** * Extracts the pure content text from a given content stream. * *

* The pure content text is just an assembly of all strings that occur within the content stream in * stream order. * Each of these strings will be set on a new line. *

* * @param stream_bytes The content stream. * @return Returns the extracted string. * @throws IOException Forwarded exception. */ public static String extractPureTextFromContentStream( final byte[] stream_bytes) throws IOException { // logger_.debug("stream_bytes:"); // logger_.debug(new String(stream_bytes, "US-ASCII")); // logger_.debug(":end of stream_bytes"); final byte OPEN = '('; final byte CLOSE = ')'; StringWriter strwrtr = new StringWriter(); PrintWriter printer = new PrintWriter(strwrtr); int open_index = -1; int close_index = -1; for (int i = 0; i < stream_bytes.length; i++) { if (stream_bytes[i] == OPEN) { open_index = i; continue; } if (stream_bytes[i] == CLOSE) { close_index = i; // logger_.debug("open = " + open_index + ", close = " + // close_index); int len = close_index - open_index - 1; // logger_.debug("len = " + len); byte[] bytes = new byte[len]; System.arraycopy(stream_bytes, open_index + 1, bytes, 0, len); String str = new String(bytes, "ISO-8859-1"); // logger_.debug("string = " + str); printer.println(str); continue; } } strwrtr.close(); String signature_text = new String(strwrtr.getBuffer()); // logger_.debug(signature_text); return signature_text; } }