freehep-io-2.0.2/0000755012010301201030000000000011274277015014532 5ustar mascellanimascellanifreehep-io-2.0.2/src/0000755012010301201030000000000011274277015015321 5ustar mascellanimascellanifreehep-io-2.0.2/src/test/0000755012010301201030000000000011274277015016300 5ustar mascellanimascellanifreehep-io-2.0.2/src/test/java/0000755012010301201030000000000011274277015017221 5ustar mascellanimascellanifreehep-io-2.0.2/src/test/java/org/0000755012010301201030000000000011274277015020010 5ustar mascellanimascellanifreehep-io-2.0.2/src/test/java/org/freehep/0000755012010301201030000000000011274277015021426 5ustar mascellanimascellanifreehep-io-2.0.2/src/test/java/org/freehep/util/0000755012010301201030000000000011274277015022403 5ustar mascellanimascellanifreehep-io-2.0.2/src/test/java/org/freehep/util/io/0000755012010301201030000000000011274277015023012 5ustar mascellanimascellanifreehep-io-2.0.2/src/test/java/org/freehep/util/io/test/0000755012010301201030000000000011274277015023771 5ustar mascellanimascellanifreehep-io-2.0.2/src/test/java/org/freehep/util/io/test/ASCIIHexOutputStreamTest.java0000644012010301201030000000250210466735775031403 0ustar mascellanimascellani// Copyright 2001-2005, FreeHEP. package org.freehep.util.io.test; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.InputStream; import org.freehep.util.Assert; import org.freehep.util.io.ASCIIHexOutputStream; /** * Test for ASCII Hex Output Stream. * * @author Mark Donszelmann * @version $Id: ASCIIHexOutputStreamTest.java 8584 2006-08-10 23:06:37Z duns $ */ public class ASCIIHexOutputStreamTest extends AbstractStreamTest { /** * Test method for 'org.freehep.util.io.ASCIIHexOutputStream.write()' * @throws Exception if ref file cannot be found */ public void testWrite() throws Exception { // this XML file needs to be fixed: eol-style=CRLF File testFile = new File(testDir, "TestFile.xml"); File outFile = new File(outDir, "TestFile.hex"); File refFile = new File(refDir, "TestFile.hex"); ASCIIHexOutputStream out = new ASCIIHexOutputStream(new FileOutputStream(outFile)); // NOTE: read byte by byte, so the test will work on all platforms InputStream in = new FileInputStream(testFile); int b; while ((b = in.read()) >= 0) { out.write(b); } in.close(); out.close(); Assert.assertEquals(refFile, outFile, false); } } freehep-io-2.0.2/src/test/java/org/freehep/util/io/test/RoutedInputStreamTest.java0000644012010301201030000000500610466735775031151 0ustar mascellanimascellani// Copyright 2002-2005, FreeHEP. package org.freehep.util.io.test; import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.PrintStream; import org.freehep.util.Assert; import org.freehep.util.io.RouteListener; import org.freehep.util.io.RoutedInputStream; /** * Test for Routed Input Stream. * * @author Mark Donszelmann * @version $Id: RoutedInputStreamTest.java 8584 2006-08-10 23:06:37Z duns $ */ public class RoutedInputStreamTest extends AbstractStreamTest { /** * Tests RoutiedInputStream.read() * * @throws Exception when reference file cannot be found */ public void testRead() throws Exception { File testFile = new File(testDir, "RoutedInputStream.txt"); File refFile = new File(refDir, "RoutedInputStream.out"); File outFile = new File(outDir, "RoutedInputStream.out"); RoutedInputStream in = new RoutedInputStream(new BufferedInputStream( new FileInputStream(testFile))); final PrintStream out = new PrintStream(new FileOutputStream(outFile)); RouteListener listener = new RouteListener() { public void routeFound(RoutedInputStream.Route route) throws IOException { out.write('['); out.write(route.getStart()); out.write(':'); int b = route.read(); while (b != -1) { out.write(b); b = route.read(); } route.close(); out.write(']'); out.flush(); } }; in.addRoute("StartA", "EndA", listener); in.addRoute("StartB", "EndB", listener); in.addRoute("StartC", "EndC", listener); in.addRoute("SClosed", "EClosed", new RouteListener() { public void routeFound(RoutedInputStream.Route route) throws IOException { out.print("[EarlyClosed:"); for (int i = 0; i < 6; i++) { out.write(route.read()); } route.close(); out.write(']'); out.flush(); } }); int b = in.read(); while (b != -1) { out.write(b); b = in.read(); } in.close(); out.close(); Assert.assertEquals(refFile, outFile, false); } } freehep-io-2.0.2/src/test/java/org/freehep/util/io/test/AbstractStreamTest.java0000644012010301201030000000142710466735775030435 0ustar mascellanimascellani// Copyright 2005, FreeHEP. package org.freehep.util.io.test; import java.io.File; import junit.framework.TestCase; /** * Abstract Test for ASCII85 Output Stream * * @author Mark Donszelmann * @version $Id: AbstractStreamTest.java 8584 2006-08-10 23:06:37Z duns $ */ public abstract class AbstractStreamTest extends TestCase { protected File refDir; protected File testDir; protected File outDir; protected void setUp() throws Exception { String baseDir = System.getProperty("basedir"); if (baseDir == null) baseDir = ""; refDir = new File(baseDir, "src/test/resources/ref"); testDir = refDir; outDir = new File(baseDir, "target/test-output/ref"); if (!outDir.exists()) outDir.mkdirs(); } } freehep-io-2.0.2/src/test/java/org/freehep/util/io/test/RunLengthOutputStreamTest.java0000644012010301201030000000224510466735775032020 0ustar mascellanimascellani// Copyright 2001, FreeHEP. package org.freehep.util.io.test; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import org.freehep.util.Assert; import org.freehep.util.io.RunLengthOutputStream; /** * Test for Run Length Output Stream. * * @author Mark Donszelmann * @version $Id: RunLengthOutputStreamTest.java 8584 2006-08-10 23:06:37Z duns $ */ public class RunLengthOutputStreamTest extends AbstractStreamTest { /** * Test method for 'org.freehep.util.io.RunLengthOutputStream.write()' * @throws Exception if ref file cannot be found */ public void testWrite() throws Exception { File testFile = new File(testDir, "TestFile.xml"); File outFile = new File(outDir, "TestFile.rnl"); File refFile = new File(refDir, "TestFile.rnl"); RunLengthOutputStream out = new RunLengthOutputStream(new FileOutputStream(outFile)); FileInputStream in = new FileInputStream(testFile); int b; while ((b = in.read()) >= 0) { out.write(b); } in.close(); out.close(); Assert.assertEquals(refFile, outFile, true); } } freehep-io-2.0.2/src/test/java/org/freehep/util/io/test/ASCII85InputStreamTest.java0000644012010301201030000000163710466735775030722 0ustar mascellanimascellani// Copyright 2001-2005, FreeHEP. package org.freehep.util.io.test; import java.io.File; import java.io.FileInputStream; import org.freehep.util.Assert; import org.freehep.util.io.ASCII85InputStream; /** * Test for ASCII85 Input Stream. * * @author Mark Donszelmann * @version $Id: ASCII85InputStreamTest.java 8584 2006-08-10 23:06:37Z duns $ */ public class ASCII85InputStreamTest extends AbstractStreamTest { /** * Test method for 'org.freehep.util.io.ASCII85InputStream.read()' * @throws Exception if ref file cannot be found */ public void testRead() throws Exception { File testFile = new File(testDir, "TestFile.a85"); File refFile = new File(refDir, "TestFile.xml"); ASCII85InputStream in = new ASCII85InputStream(new FileInputStream(testFile)); Assert.assertEquals(new FileInputStream(refFile), in, false, refFile.getPath()); } } freehep-io-2.0.2/src/test/java/org/freehep/util/io/test/BitOutputStreamTest.java0000644012010301201030000000236410466735775030632 0ustar mascellanimascellani// Copyright 2002, FreeHEP. package org.freehep.util.io.test; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import org.freehep.util.Assert; import org.freehep.util.io.BitOutputStream; /** * Test for Bit Output Stream. * * @author Mark Donszelmann * @version $Id: BitOutputStreamTest.java 8584 2006-08-10 23:06:37Z duns $ */ public class BitOutputStreamTest extends AbstractStreamTest { /** * Test method for 'org.freehep.util.io.BitOutputStream.writeUBits()' * @throws Exception if ref file cannot be found */ public void testWrite() throws Exception { File testFile = new File(testDir, "TestFile.xml"); File outFile = new File(outDir, "TestFile.bit"); File refFile = new File(refDir, "TestFile.bit"); BitOutputStream out = new BitOutputStream(new FileOutputStream(outFile)); FileInputStream in = new FileInputStream(testFile); int b; while ((b = in.read()) >= 0) { int n = BitOutputStream.minBits(b); out.writeUBits(n-1, 3); // min = 1, max is 8 out.writeUBits(b, n); } in.close(); out.close(); Assert.assertEquals(refFile, outFile, true); } } freehep-io-2.0.2/src/test/java/org/freehep/util/io/test/Base64OutputStreamTest.java0000644012010301201030000000246310466735775031140 0ustar mascellanimascellani// Copyright 2001-2005, FreeHEP. package org.freehep.util.io.test; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.InputStream; import org.freehep.util.Assert; import org.freehep.util.io.Base64OutputStream; /** * Test for Base64 Output Stream. * * @author Mark Donszelmann * @version $Id: Base64OutputStreamTest.java 8584 2006-08-10 23:06:37Z duns $ */ public class Base64OutputStreamTest extends AbstractStreamTest { /** * Test method for 'org.freehep.util.io.Base64OutputStream.write()' * @throws Exception if ref file cannot be found */ public void testWrite() throws Exception { // this XML file needs to be fixed: eol-style=CRLF File testFile = new File(testDir, "TestFile.xml"); File outFile = new File(outDir, "TestFile.b64"); File refFile = new File(refDir, "TestFile.b64"); Base64OutputStream out = new Base64OutputStream(new FileOutputStream(outFile)); // NOTE: read byte by byte, so the test will work on all platforms InputStream in = new FileInputStream(testFile); int b; while ((b = in.read()) >= 0) { out.write(b); } in.close(); out.close(); Assert.assertEquals(refFile, outFile, false); } } freehep-io-2.0.2/src/test/java/org/freehep/util/io/test/Base64InputStreamTest.java0000644012010301201030000000162010466735775030731 0ustar mascellanimascellani// Copyright 2003-2005, FreeHEP. package org.freehep.util.io.test; import java.io.File; import java.io.FileInputStream; import org.freehep.util.Assert; import org.freehep.util.io.Base64InputStream; /** * Test for Base64 Input Stream. * * @author Mark Donszelmann * @version $Id: Base64InputStreamTest.java 8584 2006-08-10 23:06:37Z duns $ */ public class Base64InputStreamTest extends AbstractStreamTest { /** * Test method for 'org.freehep.util.io.Base64InputStream.read()' * @throws Exception if ref file cannot be found */ public void testRead() throws Exception { File testFile = new File(testDir, "TestFile.b64"); File refFile = new File(refDir, "TestFile.xml"); Base64InputStream in = new Base64InputStream(new FileInputStream(testFile)); Assert.assertEquals(new FileInputStream(refFile), in, false, refFile.getPath()); } } freehep-io-2.0.2/src/test/java/org/freehep/util/io/test/RunLengthInputStreamTest.java0000644012010301201030000000164510466735775031622 0ustar mascellanimascellani// Copyright 2001-2005, FreeHEP. package org.freehep.util.io.test; import java.io.File; import java.io.FileInputStream; import org.freehep.util.Assert; import org.freehep.util.io.RunLengthInputStream; /** * Test for Run Length Input Stream. * * @author Mark Donszelmann * @version $Id: RunLengthInputStreamTest.java 8584 2006-08-10 23:06:37Z duns $ */ public class RunLengthInputStreamTest extends AbstractStreamTest { /** * Test method for 'org.freehep.util.io.RunLengthInputStream.read()' * @throws Exception if ref file cannot be found */ public void testRead() throws Exception { File testFile = new File(testDir, "TestFile.rnl"); File refFile = new File(refDir, "TestFile.xml"); RunLengthInputStream in = new RunLengthInputStream(new FileInputStream(testFile)); Assert.assertEquals(new FileInputStream(refFile), in, true, refFile.getPath()); } } freehep-io-2.0.2/src/test/java/org/freehep/util/io/test/PromptInputStreamTest.java0000644012010301201030000000320310466735775031165 0ustar mascellanimascellani// Copyright 2001-2005, FreeHEP. package org.freehep.util.io.test; import java.io.File; import java.io.FileInputStream; import java.io.FileWriter; import java.io.PrintWriter; import org.freehep.util.Assert; import org.freehep.util.io.PromptInputStream; import org.freehep.util.io.PromptListener; import org.freehep.util.io.RoutedInputStream; /** * Test for Prompt Input Stream * @author Mark Donszelmann * @version $Id: PromptInputStreamTest.java 8584 2006-08-10 23:06:37Z duns $ */ public class PromptInputStreamTest extends AbstractStreamTest { /** * Test PromptInputStream.read() * @throws Exception when ref file cannot be found */ public void testPrompt() throws Exception { File testFile = new File(testDir, "PromptInputStream.txt"); File refFile = new File(refDir, "PromptInputStream.out"); File outFile = new File(outDir, "PromptInputStream.out"); PromptInputStream in = new PromptInputStream(new FileInputStream(testFile)); final PrintWriter writer = new PrintWriter(new FileWriter(outFile)); final int promptNo = 0; in.addPromptListener("Idle>", new PromptListener() { public void promptFound(RoutedInputStream.Route route) { writer.println(); writer.println("PROMPT[" + promptNo + "]: " + (new String(route.getStart()))); } }); int b = in.read(); while (b >= 0) { writer.write(b); b = in.read(); } in.close(); writer.close(); Assert.assertEquals(refFile, outFile, false); } } freehep-io-2.0.2/src/test/java/org/freehep/util/io/test/ASCIIHexInputStreamTest.java0000644012010301201030000000163610466735775031211 0ustar mascellanimascellani// Copyright 2001-2005, FreeHEP. package org.freehep.util.io.test; import java.io.File; import java.io.FileInputStream; import org.freehep.util.Assert; import org.freehep.util.io.ASCIIHexInputStream; /** * Test for ASCII Hex Input Stream * * @author Mark Donszelmann * @version $Id: ASCIIHexInputStreamTest.java 8584 2006-08-10 23:06:37Z duns $ */ public class ASCIIHexInputStreamTest extends AbstractStreamTest { /** * Test method for 'org.freehep.util.io.ASCIIHexInputStream.read()' * @throws Exception if ref file cannot be found */ public void testRead() throws Exception { File testFile = new File(testDir, "TestFile.hex"); File refFile = new File(refDir, "TestFile.xml"); ASCIIHexInputStream in = new ASCIIHexInputStream(new FileInputStream(testFile)); Assert.assertEquals(new FileInputStream(refFile), in, false, refFile.getPath()); } } freehep-io-2.0.2/src/test/java/org/freehep/util/io/test/ConditionalInputStreamTest.java0000644012010301201030000000476110466735775032161 0ustar mascellanimascellani// Copyright 2001-2005, FreeHEP. package org.freehep.util.io.test; import java.io.File; import java.io.FileInputStream; import java.util.Properties; import org.freehep.util.Assert; import org.freehep.util.io.ConditionalInputStream; /** * Test for Conditional Input Stream. * * @author Mark Donszelmann * @version $Id: ConditionalInputStreamTest.java 8584 2006-08-10 23:06:37Z duns $ */ public class ConditionalInputStreamTest extends AbstractStreamTest { private File testFile; protected void setUp() throws Exception { super.setUp(); testFile = new File(testDir, "ConditionalInputStream.txt"); } /** * Test method for 'org.freehep.util.io.RunLengthInputStream.read()' * @throws Exception if ref file cannot be found */ public void testRead1() throws Exception { File refFile = new File(refDir, "ConditionalInputStream.ref1"); Properties defines = new Properties(); ConditionalInputStream in = new ConditionalInputStream(new FileInputStream(testFile), defines); Assert.assertEquals(new FileInputStream(refFile), in, false, refFile.getPath()); } /** * Test method for 'org.freehep.util.io.RunLengthInputStream.read()' * @throws Exception if ref file cannot be found */ public void testRead2() throws Exception { File refFile = new File(refDir, "ConditionalInputStream.ref2"); Properties defines = new Properties(); defines.setProperty("FREEHEP", "1"); ConditionalInputStream in = new ConditionalInputStream(new FileInputStream(testFile), defines); Assert.assertEquals(new FileInputStream(refFile), in, false, refFile.getPath()); } /** * Test method for 'org.freehep.util.io.RunLengthInputStream.read()' * @throws Exception if ref file cannot be found */ public void testRead3() throws Exception { File refFile = new File(refDir, "ConditionalInputStream.ref3"); Properties defines = new Properties(); defines.setProperty("FREEHEP", "1"); defines.setProperty("WIRED", "1"); ConditionalInputStream in = new ConditionalInputStream(new FileInputStream(testFile), defines); // OutputStream out = new FileOutputStream("ConditionalInputStream.ref3"); // int b; // while ((b = in.read()) >= 0) out.write(b); // out.close(); Assert.assertEquals(new FileInputStream(refFile), in, false, refFile.getPath()); } }freehep-io-2.0.2/src/test/java/org/freehep/util/io/test/package.html0000644012010301201030000000012210470537377026254 0ustar mascellanimascellani Tests for the I/O Streams, Readers, Writers, Encoders and Decoders. freehep-io-2.0.2/src/test/java/org/freehep/util/io/test/EncryptionTest.java0000644012010301201030000000523710466735775027653 0ustar mascellanimascellani// Copyright 2001-2005 freehep package org.freehep.util.io.test; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.PipedInputStream; import java.io.PipedOutputStream; import java.io.PrintStream; import org.freehep.util.Assert; import org.freehep.util.io.EEXECConstants; import org.freehep.util.io.EEXECDecryption; import org.freehep.util.io.EEXECEncryption; /** * Test for EEXECEncryption. * * @author duns * @version $Id: EncryptionTest.java 8584 2006-08-10 23:06:37Z duns $ */ public class EncryptionTest extends AbstractStreamTest { /** * Tests EExecEncryption and EExecDecryption. * * @throws Exception when ref file cannot be found. */ public void testEncryption() throws Exception { File refFile = new File(refDir, "Encryption.out"); File outFile = new File(outDir, "Encryption.out"); PrintStream out = new PrintStream(new FileOutputStream(outFile)); ByteArrayOutputStream bo = new ByteArrayOutputStream(); int[] ba = new int[] { 0x0010, 0x00BF, 0x0031, 0x0070, 0x004F, 0x00AB, 0x005B, 0x001F }; for (int i = 0; i < ba.length; i++) bo.write(ba[i]); EEXECDecryption in = new EEXECDecryption(new ByteArrayInputStream(bo .toByteArray()), EEXECConstants.CHARSTRING_R, 4); int r = 0; while ((r = in.read()) != -1) { out.print(Integer.toHexString(r) + " "); } out.println(); int result[] = EEXECEncryption.encryptString(new int[] { 0x00BD, 0x00F9, 0x00B4, 0x000D }, EEXECEncryption.CHARSTRING_R, EEXECEncryption.N); for (int i = 0; i < result.length; i++) out.print(Integer.toHexString(result[i]) + " "); out.println("\n"); PipedOutputStream pipeOut = new PipedOutputStream(); PipedInputStream pipeIn = new PipedInputStream(); pipeOut.connect(pipeIn); EEXECEncryption outEncrypted = new EEXECEncryption(pipeOut, EEXECConstants.EEXEC_R, EEXECEncryption.N); EEXECDecryption inEncrypted = new EEXECDecryption(pipeIn, EEXECConstants.EEXEC_R, EEXECEncryption.N); byte[] bytes = "Hello World! - advanced version (by Adobe)".getBytes(); for (int i = 0; i < bytes.length; i++) outEncrypted.write(bytes[i]); outEncrypted.close(); int b = -1; while ((b = inEncrypted.read()) != -1) out.print((char) b + " "); inEncrypted.close(); out.close(); Assert.assertEquals(refFile, outFile, false); } } freehep-io-2.0.2/src/test/java/org/freehep/util/io/test/ASCII85OutputStreamTest.java0000644012010301201030000000250110466735775031112 0ustar mascellanimascellani// Copyright 2001-2005, FreeHEP. package org.freehep.util.io.test; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.InputStream; import org.freehep.util.Assert; import org.freehep.util.io.ASCII85OutputStream; /** * Test for ASCII85 Output Stream * * @author Mark Donszelmann * @version $Id: ASCII85OutputStreamTest.java 8584 2006-08-10 23:06:37Z duns $ */ public class ASCII85OutputStreamTest extends AbstractStreamTest { /** * Test method for 'org.freehep.util.io.ASCII85OutputStream.write()' * @throws Exception if ref file cannot be found */ public void testWrite() throws Exception { // this XML file needs to be fixed: eol-style=CRLF File testFile = new File(testDir, "TestFile.xml"); File outFile = new File(outDir, "TestFile.a85"); File refFile = new File(refDir, "TestFile.a85"); ASCII85OutputStream out = new ASCII85OutputStream(new FileOutputStream(outFile)); // NOTE: read byte by byte, so the test will work on all platforms InputStream in = new FileInputStream(testFile); int b; while ((b = in.read()) >= 0) { out.write(b); } in.close(); out.close(); Assert.assertEquals(refFile, outFile, false); } } freehep-io-2.0.2/src/test/java/org/freehep/util/io/test/StandardFileFilterTest.java0000644012010301201030000000166210466735775031225 0ustar mascellanimascellani// Copyright 2003, SLAC, Stanford, U.S.A package org.freehep.util.io.test; import java.io.File; import java.io.FileFilter; import org.freehep.util.Assert; import org.freehep.util.io.StandardFileFilter; /** * Test for the Standard File Filter. * * @author duns * @version $Id: StandardFileFilterTest.java 8584 2006-08-10 23:06:37Z duns $ */ public class StandardFileFilterTest extends AbstractStreamTest { /** * Counts *.txt files in the ref directory */ public void testFileFilterTxt() { FileFilter filter = new StandardFileFilter("*.txt"); File[] files = refDir.listFiles(filter); Assert.assertEquals(4, files.length); } /** * Counts *.ref* files in the ref directory */ public void testFileFilterRef() { FileFilter filter = new StandardFileFilter("*.ref*"); File[] files = refDir.listFiles(filter); Assert.assertEquals(3, files.length); } } freehep-io-2.0.2/src/test/java/org/freehep/util/io/test/BitInputStreamTest.java0000644012010301201030000000252710466735775030432 0ustar mascellanimascellani// Copyright 2002, FreeHEP. package org.freehep.util.io.test; import java.io.EOFException; import java.io.File; import java.io.FileInputStream; import junit.framework.AssertionFailedError; import org.freehep.util.io.BitInputStream; /** * Test for Bit Input Stream * * @author Mark Donszelmann * @version $Id: BitInputStreamTest.java 8584 2006-08-10 23:06:37Z duns $ */ public class BitInputStreamTest extends AbstractStreamTest { /** * Test method for 'org.freehep.util.io.RunLengthInputStream.read()' * @throws Exception if ref file cannot be found */ public void testRead() throws Exception { File testFile = new File(testDir, "TestFile.bit"); File refFile = new File(refDir, "TestFile.xml"); BitInputStream in = new BitInputStream(new FileInputStream(testFile)); FileInputStream ref = new FileInputStream(refFile); int i = 0; try { while (true) { int n = (int)in.readUBits(3) + 1; long b = in.readUBits(n); int r = ref.read(); i++; if (r != b) throw new AssertionFailedError(refFile+": comparison failed at offset "+(i-1)); } } catch (EOFException e) { // ignored } in.close(); ref.close(); } } freehep-io-2.0.2/src/test/java/org/freehep/util/io/test/XMLSequenceTest.java0000644012010301201030000000351510466735775027647 0ustar mascellanimascellani// Copyright 2003-2005, FreeHEP. package org.freehep.util.io.test; import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; import java.io.InputStream; import javax.xml.parsers.SAXParserFactory; import junit.framework.AssertionFailedError; import org.freehep.util.io.XMLSequence; import org.xml.sax.InputSource; import org.xml.sax.XMLReader; /** * Test for XML Sequence. * * @author Mark Donszelmann * @version $Id: XMLSequenceTest.java 8584 2006-08-10 23:06:37Z duns $ */ public class XMLSequenceTest extends AbstractStreamTest { /** * Test XMLSequence reading using XML Parsers. * * @throws Exception if something goes wrong */ public void testXMLSequence() throws Exception { File testFile = new File(testDir, "XMLSequence.txt"); XMLSequence sequence = new XMLSequence(new BufferedInputStream( new FileInputStream(testFile))); if (!sequence.markSupported()) throw new AssertionFailedError("Mark is not supported for XMLSequence"); sequence.mark((int) testFile.length() + 1); SAXParserFactory factory = SAXParserFactory.newInstance(); factory.setNamespaceAware(true); XMLReader xmlReader = factory.newSAXParser().getXMLReader(); int i = 0; while (sequence.hasNext()) { InputStream input = sequence.next(); InputSource source = new InputSource(input); xmlReader.parse(source); input.close(); i++; } sequence.reset(); i = 0; while (sequence.hasNext()) { InputStream input = sequence.next(); InputSource source = new InputSource(input); xmlReader.parse(source); input.close(); i++; } sequence.close(); } } freehep-io-2.0.2/src/test/resources/0000755012010301201030000000000011274277015020312 5ustar mascellanimascellanifreehep-io-2.0.2/src/test/resources/ref/0000755012010301201030000000000011274277015021066 5ustar mascellanimascellanifreehep-io-2.0.2/src/test/resources/ref/ConditionalInputStream.ref10000644012010301201030000000100410470537377026306 0ustar mascellanimascellaniHere is a small file to test the ConditionalInputStream. It is all based on the statements: - @ifdef - @ifndef - @else - @endif which can be escaped like \ @ifdef So: defined some other @cvs and @java signs WIRED is NOT defined. moreover, empty lines and spaces should be output for every character removed. This is line number 34. freehep-io-2.0.2/src/test/resources/ref/TestFile.xml0000644012010301201030000000746310470537377023350 0ustar mascellanimascellani User Manual - Introduction Mark Donszelmann

WIRED[1] is an event display system which allows users to visualize single event data on any platform using JAS 3 (Java Analysis Studio). Events can be browsed by WIRED from any source that can provide data in the HepRep standard[2]. Data can be particle physics events, detector geometries, or any other hierarchical graphics information. HepRep data can be supplied to WIRED in XML format from files, converted from some other format on the fly, or by using communication mechanisms such as CORBA or RMI.

WIRED 4 is an experiment independent plugin module for JAS 3. It is written in pure Java and runs on any platform that runs Java and JAS 3[3]. These platforms include the whole range of Windows operating systems (95, 98, ME, 2000, NT and XP), MacOS X, Linux and other Unix systems. WIRED 4 handles data in the HepRep standard. To supply WIRED 4 with the necessary HepRep you need other plugin modules, some of which may be experiment specific. To handle HepRep XML files you need to install the HepRep plugin, see installation. See the appendix for your experiment (BaBar, GLAST, Linear Collider, Geant4) to see what plugins to load into JAS.

The WIRED 4 system takes HepRep data, runs it through some projection and displays it on the screen. The following features are currently available in WIRED 4:

  • Data Access
    • Access HepRep 2 data.
    • Access HepRep 1 data via converter.
    • Browse multiple events in XML format in either plain files, zip files or gzipped files.
  • Interactivity
    • Selection of multiple euclidian and non-euclidian projections: Parallel, FishEye, RhoZ, etc.
    • Interactive scaling, translation and rotation, including feedback.
    • Interactive changes to settings such as projectsions, global variables, etc...
    • Advanced picking of pre-selected objects and showing physics (and non-physics) information from the HepRep data.
    • 3D translations using picking, for instance to select a calorimeter hit and center it for rotation.
    • Tree representation of HepRep data to control the detector and or event visibility.
    • Almost all interactive commands can be undone and redone.
  • Output
    • Layering of Hits on Tracks on Geometry, making all visible at any time.
    • Change of quality settings for both display and file output.
    • Low quality output in bitmap graphics formats, such as PNG and GIF.
    • High quality output in vector graphics formats, such as PostScript, PDF, EMF, SVG, Macromedia Flash and others.
    • Copy on the Windows platform to the clipboard (in EMF format) for pasting in PowerPoint or Word.

Among the features on the list for post version 4.0 are:

  • Interactive cuts on physics (and non physics) information, so users can for instance hide all tracks below a certain energy.
  • Scripting to allow users to run small programs to manipulate the HepRep data.
  • Labeling of objects on the screen.
  • Interactive 3D translations using orthogonal views.
  • Full implementation to save the state of the application.
  • Use of the plugin to create histograms in JAS 3.
  • Other user requests.
freehep-io-2.0.2/src/test/resources/ref/RoutedInputStream.out0000644012010301201030000000074410470537377025271 0ustar mascellanimascellaniStartDThis is part of the main stream,[StartA:StartAbut this is part of the A stream.EndA]while this is again part of the main stream. Of course it could be more difficult: SStStaStarStart[StartB:StartBis where stream B starts and this can be several lines long and ends when we see EndB] and... [StartC:StartC Lets see if this ends up again in the main stream EndC]StartE, because it should not... EndE and the next one should be [EarlyClosed:SClose] and this is the end. EndDfreehep-io-2.0.2/src/test/resources/ref/TestFile.hex0000644012010301201030000001731110470537377023325 0ustar mascellanimascellani3c3f786d6c2076657273696f6e3d22312e30223f3e0d0a0d0a3c646f63756d656e743e200d0a2020 20203c70726f706572746965733e0d0a20202020202020203c7469746c653e55736572204d616e75 616c202d20496e74726f64756374696f6e3c2f7469746c653e0d0a20202020202020203c61757468 6f7220656d61696c3d224d61726b2e446f6e737a656c6d616e6e40736c61632e7374616e666f7264 2e656475223e4d61726b20446f6e737a656c6d616e6e3c2f617574686f723e0d0a202020203c2f70 726f706572746965733e0d0a0d0a3c626f64793e0d0a0d0a3c73656374696f6e206e616d653d2249 6e74726f64756374696f6e223e0d0a3c703e57495245443c6120687265663d225265666572656e63 65732e68746d6c2357495245445f34223e5b315d3c2f613e20697320616e206576656e7420646973 706c61792073797374656d20776869636820616c6c6f7773207573657273200d0a746f2076697375 616c697a652073696e676c65206576656e742064617461206f6e20616e7920706c6174666f726d20 7573696e67204a4153203320284a61766120416e616c797369732053747564696f292e204576656e 74732063616e206265200d0a62726f777365642062792057495245442066726f6d20616e7920736f 7572636520746861742063616e2070726f76696465206461746120696e2074686520486570526570 207374616e646172643c6120687265663d225265666572656e6365732e68746d6c23486570526570 223e5b325d3c2f613e2e200d0a446174612063616e206265207061727469636c6520706879736963 73206576656e74732c206465746563746f722067656f6d6574726965732c206f7220616e79206f74 686572200d0a68696572617263686963616c20677261706869637320696e666f726d6174696f6e2e 2048657052657020646174612063616e20626520737570706c69656420746f20574952454420696e 20584d4c200d0a666f726d61742066726f6d2066696c65732c20636f6e7665727465642066726f6d 20736f6d65206f7468657220666f726d6174206f6e2074686520666c792c206f7220627920757369 6e67200d0a636f6d6d756e69636174696f6e206d656368616e69736d73207375636820617320434f 524241206f7220524d492e3c2f703e0d0a3c703e5749524544203420697320616e20657870657269 6d656e7420696e646570656e64656e7420706c7567696e206d6f64756c6520666f72204a41532033 2e204974206973207772697474656e200d0a696e2070757265204a61766120616e642072756e7320 6f6e20616e7920706c6174666f726d20746861742072756e73204a61766120616e64204a41532033 3c6120687265663d225265666572656e6365732e68746d6c234a41535f33223e5b335d3c2f613e2e 200d0a546865736520706c6174666f726d7320696e636c756465207468652077686f6c652072616e 6765206f662057696e646f7773206f7065726174696e672073797374656d73202839352c2039382c 200d0a4d452c20323030302c204e5420616e64205850292c204d61634f5320582c204c696e757820 616e64206f7468657220556e69782073797374656d732e20574952454420342068616e646c657320 64617461200d0a696e2074686520486570526570207374616e646172642e20546f20737570706c79 2057495245442034207769746820746865206e65636573736172792048657052657020796f75206e 656564200d0a6f7468657220706c7567696e206d6f64756c65732c20736f6d65206f662077686963 68206d6179206265206578706572696d656e742073706563696669632e20546f2068616e646c6520 486570526570200d0a584d4c2066696c657320796f75206e65656420746f20696e7374616c6c2074 68652048657052657020706c7567696e2c20736565203c6120687265663d22496e7374616c6c6174 696f6e2e68746d6c223e696e7374616c6c6174696f6e3c2f613e2e2053656520746865200d0a6170 70656e64697820666f7220796f7572206578706572696d656e74202842614261722c20474c415354 2c204c696e65617220436f6c6c696465722c204765616e74342920746f2073656520776861742070 6c7567696e7320746f200d0a6c6f616420696e746f204a41532e3c2f703e0d0a3c703e5468652057 4952454420342073797374656d2074616b65732048657052657020646174612c2072756e73206974 207468726f75676820736f6d652070726f6a656374696f6e20616e64200d0a646973706c61797320 6974206f6e207468652073637265656e2e2054686520666f6c6c6f77696e67206665617475726573 206172652063757272656e746c7920617661696c61626c6520696e200d0a574952454420343a3c2f 703e0d0a3c756c3e0d0a093c6c693e3c623e44617461204163636573733c2f623e0d0a093c756c3e 0d0a09093c6c693e41636365737320486570526570203220646174612e3c2f6c693e0d0a09093c6c 693e41636365737320486570526570203120646174612076696120636f6e7665727465722e3c2f6c 693e0d0a09093c6c693e42726f777365206d756c7469706c65206576656e747320696e20584d4c20 666f726d617420696e2065697468657220706c61696e2066696c65732c207a6970200d0a09096669 6c6573206f7220677a69707065642066696c65732e3c2f6c693e0d0a093c2f756c3e0d0a093c2f6c 693e0d0a093c6c693e3c623e496e74657261637469766974793c2f623e0d0a093c756c3e0d0a0909 3c6c693e53656c656374696f6e206f66206d756c7469706c65206575636c696469616e20616e6420 6e6f6e2d6575636c696469616e2070726f6a656374696f6e733a200d0a0909506172616c6c656c2c 20466973684579652c2052686f5a2c206574632e3c2f6c693e0d0a09093c6c693e496e7465726163 74697665207363616c696e672c207472616e736c6174696f6e20616e6420726f746174696f6e2c20 696e636c7564696e6720666565646261636b2e3c2f6c693e0d0a09093c6c693e496e746572616374 697665206368616e67657320746f2073657474696e677320737563682061732070726f6a65637473 696f6e732c20676c6f62616c207661726961626c65732c206574632e2e2e3c2f6c693e0d0a09093c 6c693e416476616e636564207069636b696e67206f66207072652d73656c6563746564206f626a65 63747320616e642073686f77696e6720706879736963732028616e64200d0a09096e6f6e2d706879 736963732920696e666f726d6174696f6e2066726f6d207468652048657052657020646174612e3c 2f6c693e0d0a09093c6c693e3344207472616e736c6174696f6e73207573696e67207069636b696e 672c20666f7220696e7374616e636520746f2073656c65637420612063616c6f72696d6574657220 68697420616e642063656e74657220697420666f7220726f746174696f6e2e3c2f6c693e0d0a0909 3c6c693e5472656520726570726573656e746174696f6e206f662048657052657020646174612074 6f20636f6e74726f6c20746865206465746563746f7220616e64206f72200d0a09096576656e7420 7669736962696c6974792e3c2f6c693e0d0a09093c6c693e416c6d6f737420616c6c20696e746572 61637469766520636f6d6d616e64732063616e20626520756e646f6e6520616e64207265646f6e65 2e3c2f6c693e0d0a093c2f756c3e0d0a093c2f6c693e0d0a093c6c693e3c623e4f75747075743c2f 623e0d0a093c756c3e0d0a09093c6c693e4c61796572696e67206f662048697473206f6e20547261 636b73206f6e2047656f6d657472792c206d616b696e6720616c6c2076697369626c652061742061 6e79200d0a090974696d652e3c2f6c693e0d0a09093c6c693e4368616e6765206f66207175616c69 74792073657474696e677320666f7220626f746820646973706c617920616e642066696c65206f75 747075742e3c2f6c693e0d0a09093c6c693e4c6f77207175616c697479206f757470757420696e20 6269746d617020677261706869637320666f726d6174732c207375636820617320504e4720616e64 204749462e3c2f6c693e0d0a09093c6c693e48696768207175616c697479206f757470757420696e 20766563746f7220677261706869637320666f726d6174732c207375636820617320506f73745363 726970742c200d0a09095044462c20454d462c205356472c204d6163726f6d6564696120466c6173 6820616e64206f74686572732e3c2f6c693e0d0a09093c6c693e436f7079206f6e20746865205769 6e646f777320706c6174666f726d20746f2074686520636c6970626f6172642028696e20454d4620 666f726d61742920666f72200d0a090970617374696e6720696e20506f776572506f696e74206f72 20576f72642e3c2f6c693e0d0a093c2f756c3e0d0a093c2f6c693e0d0a3c2f756c3e0d0a3c703e41 6d6f6e6720746865206665617475726573206f6e20746865206c69737420666f7220706f73742076 657273696f6e20342e30206172653a3c2f703e0d0a3c756c3e0d0a093c6c693e496e746572616374 6976652063757473206f6e20706879736963732028616e64206e6f6e20706879736963732920696e 666f726d6174696f6e2c20736f2075736572732063616e200d0a09666f7220696e7374616e636520 6869646520616c6c20747261636b732062656c6f772061206365727461696e20656e657267792e3c 2f6c693e0d0a093c6c693e536372697074696e6720746f20616c6c6f7720757365727320746f2072 756e20736d616c6c2070726f6772616d7320746f206d616e6970756c617465207468652048657052 6570200d0a09646174612e3c2f6c693e0d0a093c6c693e4c6162656c696e67206f66206f626a6563 7473206f6e207468652073637265656e2e3c2f6c693e0d0a093c6c693e496e746572616374697665 203344207472616e736c6174696f6e73207573696e67206f7274686f676f6e616c2076696577732e 3c2f6c693e0d0a093c6c693e46756c6c20696d706c656d656e746174696f6e20746f207361766520 746865207374617465206f6620746865206170706c69636174696f6e2e3c2f6c693e0d0a093c6c69 3e557365206f662074686520706c7567696e20746f2063726561746520686973746f6772616d7320 696e204a415320332e3c2f6c693e0d0a093c6c693e4f746865722075736572207265717565737473 2e3c2f6c693e0d0a3c2f756c3e0d0a3c2f73656374696f6e3e0d0a0d0a3c2f626f64793e0d0a0d0a 3c2f646f63756d656e743e> freehep-io-2.0.2/src/test/resources/ref/PromptInputStream.out0000644012010301201030000000604010470537377025303 0ustar mascellanimascellani PROMPT[0]: Idle> Idle> /vis/scene/create PROMPT[0]: Idle> Idle> /vis/open HepRep G4HepRepSceneHandler::G4HepRepSceneHandler: 1 0 HepRep scene handlers extanct. WARNING: objects with visibility flag set to "false" will not be drawn! "/vis/set/culling off" to Draw such objects. Also see other "/vis/set" commands. PROMPT[0]: Idle> Idle> /vis/scene/add/trajectories PROMPT[0]: Idle> Idle> /vis/scene/add/hits PROMPT[0]: Idle> Idle> /run/beamOn 2 >>> Event 0 >>> Simulation truth : e+ (15.3593,0,993.198) Hodoscope 1 has 1 hits. Hodoscope[7] 4.98737 (nsec) Hodoscope 2 has 1 hits. Hodoscope[10] 43.3934 (nsec) Drift Chamber 1 has 5 hits. Layer[0] : time 6.67178 (nsec) --- local (x,y) 31.162, 3.28589 Layer[1] : time 8.33984 (nsec) --- local (x,y) 39.2208, 5.83581 Layer[2] : time 10.0079 (nsec) --- local (x,y) 47.1582, 8.21818 Layer[3] : time 11.6759 (nsec) --- local (x,y) 55.1988, 10.4779 Layer[4] : time 13.344 (nsec) --- local (x,y) 63.2974, 12.95 Drift Chamber 2 has 5 hits. Layer[0] : time 35.0509 (nsec) --- local (x,y) -55.4342, 31.7825 Layer[1] : time 36.7227 (nsec) --- local (x,y) -90.0998, 33.0307 Layer[2] : time 38.3946 (nsec) --- local (x,y) -124.84, 34.3552 Layer[3] : time 40.0663 (nsec) --- local (x,y) -159.163, 35.7569 Layer[4] : time 41.7381 (nsec) --- local (x,y) -193.348, 36.9011 EM Calorimeter has 8 hits. Total Edep is 931.959 (MeV) Hadron Calorimeter has 0 hits. Total Edep is 0 (MeV) G4Scene::AddWorldIfEmpty: The scene was empty, "world" has been added. WARNING: G4VisManager: the scene was empty, "world" has been added and the view parameters have been reset. G4HepRepSceneHandler::open(G4Output-0.heprep) G4HepRepViewer::ShowView G4HepRepSceneHandler::close() >>> Event 1 >>> Simulation truth : mu+ (-10.7804,0,979.927) Hodoscope 1 has 1 hits. Hodoscope[7] 5.01597 (nsec) Hodoscope 2 has 1 hits. Hodoscope[8] 43.3069 (nsec) Drift Chamber 1 has 5 hits. Layer[0] : time 6.71002 (nsec) --- local (x,y) -20.7036, 0.411097 Layer[1] : time 8.38763 (nsec) --- local (x,y) -25.7662, 1.06724 Layer[2] : time 10.0652 (nsec) --- local (x,y) -30.8135, 1.81038 Layer[3] : time 11.7429 (nsec) --- local (x,y) -35.9321, 2.49463 Layer[4] : time 13.4205 (nsec) --- local (x,y) -40.9426, 3.05739 Drift Chamber 2 has 5 hits. Layer[0] : time 34.9164 (nsec) --- local (x,y) -250.688, 11.7331 Layer[1] : time 36.5978 (nsec) --- local (x,y) -284.472, 12.6951 Layer[2] : time 38.2792 (nsec) --- local (x,y) -318.308, 13.6141 Layer[3] : time 39.9606 (nsec) --- local (x,y) -352.234, 14.5495 Layer[4] : time 41.642 (nsec) --- local (x,y) -386.18, 15.5419 EM Calorimeter has 3 hits. Total Edep is 190.003 (MeV) Hadron Calorimeter has 2 hits. Total Edep is 25.7177 (MeV) G4HepRepSceneHandler::open(G4Output-0.heprep) G4HepRepViewer::ShowView G4HepRepSceneHandler::close() PROMPT[0]: Idle> Idle> /vis/viewer/flush G4HepRepViewer::SetView G4HepRepViewer::ClearView G4HepRepViewer::DrawView G4HepRepViewer::SetView G4HepRepSceneHandler::open(G4Output-0.heprep) G4HepRepViewer::ShowView G4HepRepSceneHandler::close() PROMPT[0]: Idle> Idle>freehep-io-2.0.2/src/test/resources/ref/TestFile.rnl0000644012010301201030000000756110344137171023326 0ustar mascellanimascellani% *User Manual - Introduction Mark Donszelman 

WIRED[1] is an event display system which alows users to visualize single event data on any platform using JAS 3 (Java Analysis Studio). Events can be browsed by WIRED from any source that can provide data in the HepRep standard[2]. Data can be particle phyhsics events, detector geometries, or any other hierarchical graphics information. HepRep data can be supflied to WIRED in XML format from files, converted from some other format on the fly, or by using comyunication mechanisms such as CORBA or RMI.

WIRED 4 is an experiment independent plugin module for JAS 3. It is writen in pure Java and runs on any platform that runs Java and JAS 3[3]. These platforms inBclude the whole range of Windows operating systems (95, 98, ME, 20h, NT and XP), MacOS X, Linux and other Unix systems. WIRED 4 handles data in the HepRep standard. To suply WIRED 4 with the necesary HepRep you need other plugin modules, some of which may be experiment specific. To handle HepRep XML files you ne d to instal the HepRep plugin, se instal ation. Se the ap1endix for your experiment (BaBar, GLAST, Linear Colider, Geant4) to se what plugins to load into JAS.

The WIRED 4 system takes HepRep data, runs it through some projection and displays i t on the scren. The folowing features are cur6ently available in WIRED 4:

  • Data Aces
      
    • Aces HepRep 2 data.
    • 
    • Aces# HepRep 1 data via converter.
    • E
    • Browse multiple events in XML format in either plain files, zip files or gzipAed files.
  • Interactivity
      D
    • Selection of multiple euclidian and non-euclidian projections: Paralel, FishEye, RhoZ, etc.
    • =
    • Interactive scaling, translation and rotation, including fe dback.
    • 
    • Interactive changes to set/ings such as projectsions, global variables, etc.
    • G
    • Advanced picking of pre-selected objects and showing physics (and 4non-physics) information from the HepRep data.
    • m
    • 3D translations using picking, for instance to select a calorimeter hit and center it for rotation.
    • 
    • Tre? representation of HepRep data to control the detector and or event visibility.
    • Almost al interactive comOands can be undone and redone.
  • Output
      3
    • Layering of Hits on Tracks on Geometry, making al visible at any time.
    • 
    • Change of quality set,ings for both display and file output.
    • M
    • Low quality output in bitmap graphics formats, such as PNG and GIF.
    • I
    • High quality output in vector graphics formats, such as PostScript, 1PDF, EMF, SVG, Macromedia Flash and others.
    • G
    • Copy on the Windows platform to the clipboard (in EMF format) for pasting in PowerPoint or Word.

Among the features on the list for post version 4.0 are:

  • Interactive cuts on physics (and non physics) information, so users can for instance hide al8 tracks below a certain energy.
  • Scripting to alow users to run smalT programs to manipulate the HepRep data.
  • Labeling of objects on the screNn.
  • Interactive 3D translations using orthogonal views.
  • Ful) implementation to save the state of the aplication.
  • Use of the plugin to create histograms in JAS 3.
  • Other user requests.
  •  freehep-io-2.0.2/src/test/resources/ref/ConditionalInputStream.ref30000644012010301201030000000100410470537377026310 0ustar mascellanimascellaniHere is a small file to test the ConditionalInputStream. It is all based on the statements: - @ifdef - @ifndef - @else - @endif which can be escaped like \ @ifdef So: FREEHEP is defined FREEHEP and WIRED are defined some other @cvs and @java signs moreover, empty lines and spaces should be output for every character removed. This is line number 34. freehep-io-2.0.2/src/test/resources/ref/TestFile.a850000644012010301201030000001147710470537377023145 0ustar mascellanimascellani4?n(-C`mn4EcYr5DET0u/heJ64q.i.$9Vj;@s)X"DKJ&b%144#+p;FNu9@3B6(AS+(L;IsHOEb0,uATKJ;FDYh==%Q:Y6shbp5$KaI4>1,,+DGm>@;[3!G%GQ5+Co2- E,8s.+EMgLFCf;3GA(]#BHU`"Ci=N=+E_a:EcW?4$?U2/G%l#?@;KY(AKZ&.DJ*cs+D#_-DKI"3@<>p# Df-\+DL!@DCghEtDfT\;F`V87B-9f4;]mk=-q[ok@3@jR@;L41BlbCqFEM,.D^d:]7s'cK4t[re$:JDJ(($$=e!kD09`1@psInDf-\7ARfC^DJ=0/F!,OH @qZunF!*hG;F3YlDfQsu9h?s"05s)a$9W8k=%Q:Y6m+B5)6+D/Ws-Ch4`$DfQsm5uSm^/g*`-+DGm>GB.D>FCf>4%16fe+E2IDAKXTRG$uM%DIal1F`)7C Df-\+DL!@DCghEtDfT\;FD,*)+EDUBF!+(`G$uM%DIak^5uSm^4CK@GEb/iG,#VuaATD@"@qB^6BQS*- ,>(7#?S`li>;KPI04@$s+:SZWBOu6r+E2.*FCoH3D0$h6DI[L*A7Zm*BOr<1BQ%]u+ECn.B4W3(Aft/h DId[0F!,C?ATD4$Bl7Q+F*VhKASlK2-oj.9+?;D4+:SZP74]Q:0JG13+APlY@;]Tu=AUFt+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ATAo9F(KA7Eb065ATMs7 /j(e'Bg)t54>1hn4q.i]06:]7FD5Z24q.i.$9TtNDe+,W%13OO4>15`@s)X"DKJ&~> freehep-io-2.0.2/src/test/resources/ref/ConditionalInputStream.txt0000644012010301201030000000100410470537377026270 0ustar mascellanimascellaniHere is a small file to test the ConditionalInputStream. It is all based on the statements: - \@ifdef - \@ifndef - \@else - \@endif which can be escaped like \\@ifdef So: @ifdef FREEHEP FREEHEP is defined @ifdef WIRED FREEHEP and WIRED are defined @else FREEHEP is defined but WIRED is NOT @endif @else defined @endif some other @cvs and @java signs @ifndef WIRED WIRED is NOT defined. @endif moreover, empty lines and spaces should be output for every character removed. This is line number 34. freehep-io-2.0.2/src/test/resources/ref/TestFile.b640000644012010301201030000001221010470537377023125 0ustar mascellanimascellaniPD94bWwgdmVyc2lvbj0iMS4wIj8+DQoNCjxkb2N1bWVudD4gDQogICAgPHByb3BlcnRpZXM+DQog ICAgICAgIDx0aXRsZT5Vc2VyIE1hbnVhbCAtIEludHJvZHVjdGlvbjwvdGl0bGU+DQogICAgICAg IDxhdXRob3IgZW1haWw9Ik1hcmsuRG9uc3plbG1hbm5Ac2xhYy5zdGFuZm9yZC5lZHUiPk1hcmsg RG9uc3plbG1hbm48L2F1dGhvcj4NCiAgICA8L3Byb3BlcnRpZXM+DQoNCjxib2R5Pg0KDQo8c2Vj dGlvbiBuYW1lPSJJbnRyb2R1Y3Rpb24iPg0KPHA+V0lSRUQ8YSBocmVmPSJSZWZlcmVuY2VzLmh0 bWwjV0lSRURfNCI+WzFdPC9hPiBpcyBhbiBldmVudCBkaXNwbGF5IHN5c3RlbSB3aGljaCBhbGxv d3MgdXNlcnMgDQp0byB2aXN1YWxpemUgc2luZ2xlIGV2ZW50IGRhdGEgb24gYW55IHBsYXRmb3Jt IHVzaW5nIEpBUyAzIChKYXZhIEFuYWx5c2lzIFN0dWRpbykuIEV2ZW50cyBjYW4gYmUgDQpicm93 c2VkIGJ5IFdJUkVEIGZyb20gYW55I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]t+÷l r=t˻lv`ݶiضi7u߶m7箜mMA6ݿs,ٶX6tw-c6el{~۶;vɹ6=nl[-u۶MnlݲX7-d|M7~_s|M7ͳi_6+_-7l=tlofü컖ӷl fiN6n[ǵv nh.߶컦,nõ;v`vͲm;ӱm-a,ݼrtvݖ|M.of~n[߳X7a6yn{.m;vϹ6mrl[~X6Ms6͇yl;v`ٶemno6N\6ͦmqvi7ߺX6m;۰ rw i;ͷ[núnv{Ea6dhNn[ͦӗ7ͳiiNϴX7a6ymni۬˱~`-p6sl~;ln{ǴX6m{ӸnN\&lhnljzliǹmn˲m; F6hl;v`Meܷ;u߶m7箜mMC hlӷl~7 a6mrl`6NmX-N`tm۰ͷV6tv Co]PtmW-|M7~_s|Mu/]_7 v`6l[.`l iKͷV oK[ӷ `w-|箯~zloNݺlñN6=t~`6sv=hvmup7i;Mi۶mrviesvNvmrm;vl;vDz6dlٶX7Malf߻6Dz[ô nw-y_-f~zloڞǹm;=tٶmu]sn}rv;f`7-gܶsn}mvpv͇tlѲ4pԶ]ӝa6u߶m7箜6ͦl;˶m;v`k߱m[.Ǻnv nnF`=evu߶m7箜6ͦۦ˹l;-X7Ma۷=a6n=oܷMoa,Ӳo6Nof~ѷ]lm;nln˷nutûl hl-o٬Ѳ6p6a6n_-f~zloڮ6m-p7]i۬`-a6[Ѵ{߳[۹6h:n[ͦӛٴߴhw+컕rweM|Mu/]_-˱N߷_zoضy=t߲mv~freehep-io-2.0.2/src/test/resources/ref/XMLSequence.txt0000644012010301201030000000025410470537377023770 0ustar mascellanimascellani File 1 File 2 File 3 freehep-io-2.0.2/src/test/resources/ref/PromptInputStream.txt0000644012010301201030000000564210470537377025322 0ustar mascellanimascellaniIdle> /vis/scene/create Idle> /vis/open HepRep G4HepRepSceneHandler::G4HepRepSceneHandler: 1 0 HepRep scene handlers extanct. WARNING: objects with visibility flag set to "false" will not be drawn! "/vis/set/culling off" to Draw such objects. Also see other "/vis/set" commands. Idle> /vis/scene/add/trajectories Idle> /vis/scene/add/hits Idle> /run/beamOn 2 >>> Event 0 >>> Simulation truth : e+ (15.3593,0,993.198) Hodoscope 1 has 1 hits. Hodoscope[7] 4.98737 (nsec) Hodoscope 2 has 1 hits. Hodoscope[10] 43.3934 (nsec) Drift Chamber 1 has 5 hits. Layer[0] : time 6.67178 (nsec) --- local (x,y) 31.162, 3.28589 Layer[1] : time 8.33984 (nsec) --- local (x,y) 39.2208, 5.83581 Layer[2] : time 10.0079 (nsec) --- local (x,y) 47.1582, 8.21818 Layer[3] : time 11.6759 (nsec) --- local (x,y) 55.1988, 10.4779 Layer[4] : time 13.344 (nsec) --- local (x,y) 63.2974, 12.95 Drift Chamber 2 has 5 hits. Layer[0] : time 35.0509 (nsec) --- local (x,y) -55.4342, 31.7825 Layer[1] : time 36.7227 (nsec) --- local (x,y) -90.0998, 33.0307 Layer[2] : time 38.3946 (nsec) --- local (x,y) -124.84, 34.3552 Layer[3] : time 40.0663 (nsec) --- local (x,y) -159.163, 35.7569 Layer[4] : time 41.7381 (nsec) --- local (x,y) -193.348, 36.9011 EM Calorimeter has 8 hits. Total Edep is 931.959 (MeV) Hadron Calorimeter has 0 hits. Total Edep is 0 (MeV) G4Scene::AddWorldIfEmpty: The scene was empty, "world" has been added. WARNING: G4VisManager: the scene was empty, "world" has been added and the view parameters have been reset. G4HepRepSceneHandler::open(G4Output-0.heprep) G4HepRepViewer::ShowView G4HepRepSceneHandler::close() >>> Event 1 >>> Simulation truth : mu+ (-10.7804,0,979.927) Hodoscope 1 has 1 hits. Hodoscope[7] 5.01597 (nsec) Hodoscope 2 has 1 hits. Hodoscope[8] 43.3069 (nsec) Drift Chamber 1 has 5 hits. Layer[0] : time 6.71002 (nsec) --- local (x,y) -20.7036, 0.411097 Layer[1] : time 8.38763 (nsec) --- local (x,y) -25.7662, 1.06724 Layer[2] : time 10.0652 (nsec) --- local (x,y) -30.8135, 1.81038 Layer[3] : time 11.7429 (nsec) --- local (x,y) -35.9321, 2.49463 Layer[4] : time 13.4205 (nsec) --- local (x,y) -40.9426, 3.05739 Drift Chamber 2 has 5 hits. Layer[0] : time 34.9164 (nsec) --- local (x,y) -250.688, 11.7331 Layer[1] : time 36.5978 (nsec) --- local (x,y) -284.472, 12.6951 Layer[2] : time 38.2792 (nsec) --- local (x,y) -318.308, 13.6141 Layer[3] : time 39.9606 (nsec) --- local (x,y) -352.234, 14.5495 Layer[4] : time 41.642 (nsec) --- local (x,y) -386.18, 15.5419 EM Calorimeter has 3 hits. Total Edep is 190.003 (MeV) Hadron Calorimeter has 2 hits. Total Edep is 25.7177 (MeV) G4HepRepSceneHandler::open(G4Output-0.heprep) G4HepRepViewer::ShowView G4HepRepSceneHandler::close() Idle> /vis/viewer/flush G4HepRepViewer::SetView G4HepRepViewer::ClearView G4HepRepViewer::DrawView G4HepRepViewer::SetView G4HepRepSceneHandler::open(G4Output-0.heprep) G4HepRepViewer::ShowView G4HepRepSceneHandler::close() Idle>freehep-io-2.0.2/src/test/resources/ref/Encryption.out0000644012010301201030000000017210470537377023760 0ustar mascellanimascellanibd f9 b4 d 10 bf 31 70 4f ab 5b 1f H e l l o W o r l d ! - a d v a n c e d v e r s i o n ( b y A d o b e ) freehep-io-2.0.2/src/test/resources/ref/RoutedInputStream.txt0000644012010301201030000000072110470537377025274 0ustar mascellanimascellaniStartDThis is part of the main stream,StartAbut this is part of the A stream.EndAwhile this is again part of the main stream. Of course it could be more difficult: SStStaStarStartStartBis where stream B starts and this can be several lines long and ends when we see EndB and... StartC Lets see if this ends up again in the main stream EndCStartE, because it should not... EndE and the next one should be SClosed closed early EClosed and this is the end. EndDfreehep-io-2.0.2/src/test/resources/ref/ConditionalInputStream.ref20000644012010301201030000000100410470537377026307 0ustar mascellanimascellaniHere is a small file to test the ConditionalInputStream. It is all based on the statements: - @ifdef - @ifndef - @else - @endif which can be escaped like \ @ifdef So: FREEHEP is defined FREEHEP is defined but WIRED is NOT some other @cvs and @java signs WIRED is NOT defined. moreover, empty lines and spaces should be output for every character removed. This is line number 34. freehep-io-2.0.2/src/site/0000755012010301201030000000000011274277015016265 5ustar mascellanimascellanifreehep-io-2.0.2/src/site/site.xml0000644012010301201030000000313510501600630017736 0ustar mascellanimascellani FreeHEP I/O http://java.freehep.org/freehep-io FreeHEP http://java.freehep.org/images/sm-freehep.gif http://java.freehep.org/ freehep-io-2.0.2/src/site/apt/0000755012010301201030000000000011274277015017051 5ustar mascellanimascellanifreehep-io-2.0.2/src/site/apt/index.apt0000644012010301201030000001006210501606165020657 0ustar mascellanimascellani --- FreeHEP I/O --- --- Mark Donszelmann --- Introduction The FreeHEP IO package extends the Java IO package with a number of input and output streams. The FreeHEP IO package lives in org.freehep.util.io and is included in freehep-base.jar. The FreeHEP IO streams are in use by the FreeHEP {{{http://java.freehep.org/vectorgraphics}VectorGraphics}} package and the PostScript viewer. Of course all these classes are usable elsewhere. A special part of the streams are the "Tagged" Input- and OutputStreams which allow for tagged blocks to be read and written. [images/ClassDiagram.png"] I/O ClassDiagram Below follows a description of the different streams available: * General Streams [FinishableOutputStream] This interface allows you to call finish() on a stream, which will write any end-of-stream marker. [NoCloseInputStream] This class (which is buffered by itself) allows you to call a non-active close(). If you have a stream from which you suddenly need to read in a different encoding (ASCII85, ...), wrap the stream in a NoCloseInputStream, then wrap that one in the encoding, read until the end-of-stream marker, then close that stream and keep reading from the underlying stream. [BitIn- / OutputStream] Reads or writes in bit format of any length bit streams. [ByteOrderInput- / OutputStream] Reads or writes lo- of hi-endian byte streams. [ByteCountInput- / OutputStream] Reads or writes a stream while keeping track the number of bytes read or written. Also keeps track of sub-counts if necessary. [UniquePrintStream] Keeps track of the strings one is printing and prints them only on the first occasion. Allows you to filter error messages for instance. * Standard Encoding Streams [ASCII85In- / OutputStream] Reads or writes ASCII85 encoding, used in e-mail for instance. [ASCIIHexIn- / OutputStream] Reads or writes ASCIIHex encoding. [DCTIn- / OutputStream] Reads or writes Discrete Cosine Transform encoding, used in JPEG image for instance. [RunLengthIn- / OutputStream] Reads or writes Run Length encoding, used in PostScript sometimes. [EExecEn- / Decryption] Reads or writes EExec encoding, used in Type1 fonts. * Tagged Streams [TaggedInput- / OutputStream, Tag, UndefinedTag, TagSet, Action, Action.Unknown <> ActionSet] Reads or writes tags. Tags are blocks identified by some tag-id and a tag-length. A specific TagSet can be used to handle the tags as they are read or written. UndefinedTags can be skipped automatically. For writing the tag-length is automatically calculated. Total stream length can also be calculated. Actions are handled as a special set of "Tags". * Conditional Streams [ConditionalInputStream] Reads a stream and filters parts depending on properties set and statements in the stream. Works like the conditional compilation part of a C pre-processor. [RoutedInputStream and RouteListener] Routes a stream to a listener, who can keep reading from the stream, for a certain delimited part of the stream. [PromptInputStream and PromptListener] Reads a stream until the prompt and signals the listener. * Miscellaneous Classes [StandardFileFilter] Implements a filter with the default file filter scheme used in most Operating Systems. You can specify "*" for 0 or more "any" characters, and "?" for a single "any" character. freehep-io-2.0.2/src/site/ClassDiagram.ppt0000644012010301201030000006600010501600630021327 0ustar mascellanimascellaniࡱ> 3 4 !"#$%&'()*+,-./012Root EntrydO)p$@PowerPoint Document(Y/SummaryInformation(,DocumentSummaryInformation8_( / 0LDArialllԥ0:A 0@ .  @n?" dd@  @@`` x 6/6 0AA@3ʚ;ʚ;g4EdEd:A 0~ppp@ <4dddd0$ 0l 80___PPT10   ` 33` Sf3f` 33g` f` www3PP` ZXdbmo` \ғ3y`Ӣ` 3f3ff` 3f3FKf` hk]wwwfܹ` ff>>\`Y{ff` R>&- {p_/̴>?" dd@,|?" dd@   " @ ` n?" dd@   @@``PR    @ ` ` p>> f(    6A  `}  T Click to edit Master title style! !  0F  `  RClick to edit Master text styles Second level Third level Fourth level Fifth level!     S  08O ^ `  >*  0C ^   @*  0P ^ `  @*H  0޽h ? 3380___PPT10.P0 Default Design" r!j! )5:(   0 Z8c?"6@`NNN?NP  2 Z8c?"6@`NNN?NPP  4 Z8c?"6@`NNN?NP  B8c"`0  ^FilterOutputStream  BDː8c"`d Z DataOutput     B\8c"`  [BitOutputStream  B\8c"` $ tByteOrder OutputStream$    B\8c"`` $  tByteCount OutputStream$     BPY\8c"` $  ^TaggedOutputStream  Bl=\8c"` $ X OutputStream     BT\8c"`    \ TaggedOutput     B&8c"`0 ZBitInputStream  B)&8c"`\ sByteOrder InputStream$    B4&8c"`a \  sByteCount InputStream$    B>&8c"` \  ]TaggedInputStream  B&8c"`\ W InputStream     B\8c"`  Y DataInput     BR&8c"`  ZCGMInputStream  B&8c"`pg ZEMFInputStream  BH{\8c"`P\  ZSWFInputStream  B`f&8c"` 8  [CGMOutputStream  B@g\8c"`p g [EMFOutputStream  Bh\8c"`H [SWFOutputStream  ZĜHpÎ8c?d    ZG H@I 8c? dL  ! ZG|HpI|8c?,| " TG&*HI-8c?vv| $ TG&*HI-8c?| % TG&*HI-8c?| & TG&*HI-8c? vv | ' TG&*HI-8c? vv | ( TG&*HI-8c?vvY | ) TG&*HI-8c?vv| , TG&*HI-8c?  | - TG&*HI-8c?  | . TG&*HI-8c?X | / TG&*HI-8c? 1 ZK\8c?"0@NNN?N$ Cindividual packages 3 Zz&8c?"0@NNN?N` G  ]org.freehep.util.io 5 Z\8c?"0@NNN?NilP Qjava.ioH  0޽h ? !"$%& ' ( ) , -./ 3380___PPT10.r0g m/f ՜.+,0  $ , ]On-screen Show#Stanford Linear Accelerator CenternY/{ ArialDefault DesignSlide 1  Fonts UsedDesign Template Slide TitlesOh+'0, `hx  Slide 1duns 1duns 16nsMicrosoft PowerPointP@+@P@OG+;    Y!-- @ !Y!--'-- @ !!--'-- @ !@!--'-- @ !!--'-- @ !"d---- $dVVd--'@Arial-. "2 |FilterOutputStream      . "System--- @ !"x!---- $!CC!--'@Arial-. 2 : DataOutput    .--- @ !"---- $KK--'@Arial-. 2 BitOutputStream    .--- @ !:---- $.=.=--'@Arial-. 2  ByteOrderS   .-@Arial-. 2 $ OutputStream    .--- @ !:M---- $M==M--'@Arial-. 2 f ByteCounte   .-@Arial-. 2 ~ OutputStream    .--- @ !"---- $aa--'@Arial-. "2 TaggedOutputStream     .--- @ !"!---- $!C=C=!--'@Arial-. 2 : OutputStream    .--- @ !"e---- $e{{e--'@Arial-. 2 ~ TaggedOutput   .--- @ !"*---- $**--'@Arial-. 2 3BitInputStream   .--- @ !:7---- $77..--'@Arial-. 2 J ByteOrdert   .-@Arial-. 2 $A InputStreame   .--- @ !:M7---- $7M7M--'@Arial-. 2 fI ByteCounta   .-@Arial-. 2 ~A InputStreame   .--- @ !"---- $--'@Arial-. !2 TaggedInputStreamm    .--- @ !"!7---- $7!7CC!--'@Arial-. 2 :A InputStreame   .--- @ !"i! ---- $ ! CuCu!--'@Arial-. 2 : DataInputa   .--- @ !" ---- $  --'@Arial-. 2 )CGMInputStream   .--- @ !"]---- $]]##--'@Arial-. 2 gEMFInputStream     .--- @ !"---- $7L7L--'@Arial-. 2 .SWFInputStream     .--- @ !"---- $UU--'@Arial-. 2 CGMOutputStream    .--- @ !"---- $##--'@Arial-. 2 EMFOutputStream      .--- @ !" ---- $  77--'@Arial-. 2 .SWFOutputStream      .---8   %%,55,,<@?? B B<<??BB???BB???BB???BB???BB???BB???BB???BB???BB??z?qBqBz?z?k?bBbBk?k?[?RBRB[?[;O@DFO;O--'--k8   !**!!121133111133111331,28,--'--8?GG??NWWNN^gg^^mvvmm}}}  }}vmmvvg^^ggWNNWWODOO--'--8zzN|N|zuO{DOuO--'--8--'--8bNNbbODOO--'--8zz||zu{u--'--8zz||zu{u--'--8zLz9|9|LzLu:{/:u:--'--8zz||zu{u--'--8--'--8--'--8L99LL:/::--'--8--'@Arial-. $2 Ojindividual packages    .-@Arial-. $2 ~org.freehep.util.io     .-@Arial-. 2 java.io  .-Current User,_5/&dunsdunsfreehep-io-2.0.2/src/site/resources/0000755012010301201030000000000011274277015020277 5ustar mascellanimascellanifreehep-io-2.0.2/src/site/resources/images/0000755012010301201030000000000011274277015021544 5ustar mascellanimascellanifreehep-io-2.0.2/src/site/resources/images/ClassDiagram.png0000644012010301201030000002610010501600630024564 0ustar mascellanimascellaniPNG  IHDR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cbȸ+ɸ0K{~.m, WnTOzt9 +]X7ǔ˹ց.e/YtqhL\wk^ c:"LvЭ>[)aR 1!1.@at[9F9"[>՝2бZTx3C@UE(cZZKy VN{zK՝tȡ^<TpSoG&4#Q)XR.byK՝v 3Q"w]C%b؊ 2<MCXҗe1i=j"Qs9 ;'=užםgu4@h (@l3g@h 4'yw4vh @`a0 h @`v<-9ʯ6v-s>md@4 ֆ; s^Ƃb Ry Edp+&w,QKF^ԊYj%,LEAD u#[d,\h@˧r(RԮqp)*R;rFlOF0 #hRY+z]Bxf t,YF(%7QM 8P%F1 űڳ*ٺōY(b_1xaa!1eME3HI \zu0d.]îUSJ#nN-99y]n/1BIdJѳ@::BLuW5ﻥ ywH@h$dYa]+,JE5fE,4B2;ж4ƾJ^.Σ'[Eu0:-B( EfYrs BX@BٻĨڢLd ƪ0rӘ^UV ۩T\hع@-RJE7qiS1 KvA֢GW(Ol,xdnU7Vy#@07 '+0oV1@& 7ː@0 hKF+IENDB`freehep-io-2.0.2/src/main/0000755012010301201030000000000011274277015016245 5ustar mascellanimascellanifreehep-io-2.0.2/src/main/java/0000755012010301201030000000000011274277015017166 5ustar mascellanimascellanifreehep-io-2.0.2/src/main/java/org/0000755012010301201030000000000011274277015017755 5ustar mascellanimascellanifreehep-io-2.0.2/src/main/java/org/freehep/0000755012010301201030000000000011274277015021373 5ustar mascellanimascellanifreehep-io-2.0.2/src/main/java/org/freehep/util/0000755012010301201030000000000011274277015022350 5ustar mascellanimascellanifreehep-io-2.0.2/src/main/java/org/freehep/util/io/0000755012010301201030000000000011274277015022757 5ustar mascellanimascellanifreehep-io-2.0.2/src/main/java/org/freehep/util/io/Action.java0000644012010301201030000000533610466735775025064 0ustar mascellanimascellani// Copyright 2001, FreeHEP. package org.freehep.util.io; import java.io.IOException; /** * Generic Action, to be used with the TagIn/OutputStreams. An action can have * an ActionCode, a length as well as parameters. * * @author Mark Donszelmann * @author Charles Loomis * @version $Id: Action.java 8584 2006-08-10 23:06:37Z duns $ */ public abstract class Action { private int code; private String name; protected Action(int code) { this.code = code; name = getClass().getName(); int dot = name.lastIndexOf("."); name = (dot >= 0) ? name.substring(dot + 1) : name; } /** * Read an action from the input, with given actioncode and length * * @param actionCode decoded actionCode * @param input input to read from * @param length length to read * @return action corresponding to actionCode * @throws IOException if read fails */ public abstract Action read(int actionCode, TaggedInputStream input, int length) throws IOException; /** * Write an action to output * * @param actionCode actionCode to use for this action * @param output output to write to * @throws IOException if write fails */ public abstract void write(int actionCode, TaggedOutputStream output) throws IOException; /** * @return actionCode */ public int getCode() { return code; } /** * @return name of the action */ public String getName() { return name; } public String toString() { return "Action " + getName() + " (" + getCode() + ")"; } /** * Used for not recognized actions. */ public static class Unknown extends Action { private int[] data; /** * Create a special Action for Unknown Actions, with actioncode 0. */ public Unknown() { super(0x00); } /** * Create a special Action for Unknown Actions, with given action code. * * @param actionCode code to be used for Unknown Action. */ public Unknown(int actionCode) { super(actionCode); } public Action read(int actionCode, TaggedInputStream input, int length) throws IOException { Unknown action = new Unknown(actionCode); action.data = input.readUnsignedByte(length); return action; } public void write(int actionCode, TaggedOutputStream output) throws IOException { output.writeUnsignedByte(data); } public String toString() { return super.toString() + " UNKNOWN!, length " + data.length; } } } freehep-io-2.0.2/src/main/java/org/freehep/util/io/RoutedInputStream.java0000644012010301201030000003050110466735775027275 0ustar mascellanimascellani// Copyright 2002, FreeHEP. package org.freehep.util.io; import java.io.IOException; import java.io.InputStream; import java.util.HashMap; import java.util.Iterator; import java.util.Map; /** * The RoutedInputStream allows the user to add a listener for a certain * delimited portion of the main inputstream. This portion is marked by a start * and end marker. The end marker can be null, in which case the portion runs * from the start marker to the end of the main inputstream. The listener is * informed via a route (partial inputstream) when input is available. The new * routed inputstream (route) is supposed to be read to the end or closed, after * which the main inputstream should be read again. Closing a route will not * close the original stream, but will discard any bytes up to and including the * end marker. Returning from a route without reading until the end of the route * means that the remaining bytes are still available on the main stream. * Multiple routes can be added, as long as they have different start sequences. * Start sequences such as "StartA, StartB, StartEmpty" are allowed, but "Start, * StartOther" are not since they overlap. Start and End markers can be the * same. * * IMPORTANT: inherits from InputStream rather than FilterInputStream so that * the correct read(byte[], int, int) method is used. * * @author Mark Donszelmann * @version $Id: RoutedInputStream.java 8584 2006-08-10 23:06:37Z duns $ */ public class RoutedInputStream extends InputStream { private InputStream in; private Map routes, listeners; private byte[] buffer; private int sob, eob; private int index; private int state; private byte[] start; private static final int UNROUTED = 0; // the main stream is returned private static final int ROUTEFOUND = 1; // found a route, but need to // still return buffer private static final int ROUTEINFORM = 2; // buffer returned, need to // inform routelistener private static final int ROUTED = 3; // the main stream is now routed to // the route private static final int CLOSING = 4; // the underlying stream is closed, // but buffer need to be emptied private static final int CLOSED = 5; // the main stream is closed /** * Creates a RoutedInputStream from the underlying stream. * * @param input stream to read */ public RoutedInputStream(InputStream input) { super(); in = input; routes = new HashMap(); listeners = new HashMap(); // bufferlength has to be more than 1 buffer = new byte[20]; sob = -1; eob = 0; index = 0; state = UNROUTED; } /** * Returns the next byte on this stream, however if a start marker is found, * the associated route listener is called, which should take over reading * the stream. In this case this method will, after the route is finished * reading and closed, return the first byte after the end marker. This of * course unless that byte is part of the next start marker. */ public int read() throws IOException { int result; NEWSTATE: while (true) { switch (state) { default: case UNROUTED: // fill the buffer with one or more bytes int b = -1; while (sob != eob) { if (sob < 0) sob = 0; // read a byte from the underlying stream b = in.read(); if (b < 0) { // underlying stream closed state = CLOSING; continue NEWSTATE; } // try to find a start marker buffer[eob] = (byte) b; eob = (eob + 1) % buffer.length; // search for a route for (Iterator i = routes.keySet().iterator(); i.hasNext();) { start = (byte[]) i.next(); index = (eob + buffer.length - start.length) % buffer.length; if (equals(start, buffer, index)) { state = ROUTEFOUND; continue NEWSTATE; } } } // while // always return what drops from the buffer // the buffer is one byte longer than the longest start marker, // so even // if we find that marker we can still return the byte just in // front of it. result = buffer[sob]; sob = (sob + 1) % buffer.length; return result; case ROUTEFOUND: // found a start marker, we still need to return all bytes // before // the marker; i.e. from sob to index if (sob == index) { state = ROUTEINFORM; continue NEWSTATE; } result = buffer[sob]; sob = (sob + 1) % buffer.length; return result; case ROUTEINFORM: // we inform the routelistener to start reading state = ROUTED; Route route = new Route(start, (byte[]) routes.get(start)); // next call will generate callbacks to this read method in // state ROUTED. ((RouteListener) listeners.get(start)).routeFound(route); // route listener finished state = UNROUTED; if (sob == eob) { // we restart buffering if the buffer was empty sob = -1; eob = 0; continue NEWSTATE; } // FIXME: we need an UNROUTING here which just returns the // buffer, but does not refill it, in case the reads would // block... // we return a byte from the buffer and // let the next call take care of rebuffering, otherwise we may // block result = buffer[sob]; sob = (sob + 1) % buffer.length; return result; case ROUTED: // calls end up here when the Route is reading. We should // return the start marker (in buffer) followed by newly read // bytes. if (sob == eob) { result = in.read(); if (result < 0) { state = CLOSED; continue NEWSTATE; } } else { result = buffer[sob]; sob = (sob + 1) % buffer.length; } return result; case CLOSING: // the underlying stream is closed, no more markers can be found // thus the rest of the buffer is returned if (sob == eob) { state = CLOSED; continue NEWSTATE; } result = buffer[sob]; sob = (sob + 1) % buffer.length; return result; case CLOSED: // all streams are closed return -1; } // switch } // while } /** * Adds a route for given start and end string. The strings are converted * according to the default encoding to start and end markers (byte[]). * * @param start start marker * @param end end marker * @param listener listener to inform about the route */ public void addRoute(String start, String end, RouteListener listener) { addRoute(start.getBytes(), (end == null) ? null : end.getBytes(), listener); } /** * Adds a route for given start and end marker. * * If the end marker is null, the route is indefinite, and can be read until * the main stream ends. * * If the start and end marker are equal, the route can be read for exactly * their length. * * @param start start marker * @param end end marker * @param listener listener to inform about the route */ public void addRoute(byte[] start, byte[] end, RouteListener listener) { for (Iterator i = routes.keySet().iterator(); i.hasNext();) { String key = new String((byte[]) i.next()); String name = new String(start); if (key.startsWith(name) || name.startsWith(key)) { throw new IllegalArgumentException("Route '" + name + "' cannot be added since it overlaps with '" + key + "'."); } } routes.put(start, end); listeners.put(start, listener); // we make the buffer one longer than the longest start marker, so that // read() can always return a byte before a marker. if (start.length > buffer.length - 1) { byte[] tmp = new byte[start.length + 1]; System.arraycopy(buffer, 0, tmp, 0, buffer.length); buffer = tmp; } } /** * Checks if cmp is equal to buf (with start at index) for the length of * cmp. * * @param cmp buffer1 to compare * @param buf buffer2 to compare * @param index start index to start compare * @return true if cmp == buf for length of cmp. */ private static boolean equals(byte[] cmp, byte[] buf, int index) { for (int i = cmp.length - 1; i > 0; i--) { int j = (index + buf.length + i) % buf.length; if (buf[j] != cmp[i]) { return false; } } return buf[(index + buf.length) % buf.length] == cmp[0]; } /** * Route which can be read up to and including the end marker. * * When you close the route, all bytes including the end marker will be * read/discarded before returning. * * If you just discard the Route, the underlying stream will still return * you all or part of the bytes of this route. * * If the end marker is set to null, the stream can be read until the * underlying stream ends. */ public class Route extends InputStream { private byte[] start, end; private byte[] buffer; private int index; private boolean closed; /** * Creates a route with given start and end marker. * * @param start start marker * @param end end marker */ public Route(byte[] start, byte[] end) { this.start = start; this.end = end; if (end != null) buffer = new byte[end.length]; index = 0; closed = false; } /** * Returns bytes of this specific route, starting with the start marker, * followed by any bytes up to and including the end marker. * * If the end marker is null, the route is indefinite. */ public int read() throws IOException { if (closed) return -1; int b = RoutedInputStream.this.read(); if (b < 0) { closed = true; return b; } if (end == null) return b; buffer[index] = (byte) b; index = (index + 1) % buffer.length; closed = RoutedInputStream.equals(end, buffer, index); return b; } /** * Closes the stream, and discards any bytes up to and including the end * marker. */ public void close() throws IOException { while (read() >= 0) { } ; closed = true; } /** * Returns start marker. * * @return start marker */ public byte[] getStart() { return start; } /** * Returns end marker. * * @return end marker */ public byte[] getEnd() { return end; } } } freehep-io-2.0.2/src/main/java/org/freehep/util/io/XMLSequence.java0000644012010301201030000001212410466735775025771 0ustar mascellanimascellani// Copyright 2003, FreeHEP. package org.freehep.util.io; import java.io.IOException; import java.io.InputStream; import java.util.NoSuchElementException; /** * The XMLSequence allows parsing by an XML Parser of concatenated XML segments. * Each segment needs to start with " * * XMLSequence sequence = new XMLSequence(new FileInputStream("file.xml")); * * SAXParserFactory factory = SAXParserFactory.newInstance(); XMLReader * xmlReader = factory.newSAXParser().getXMLReader(); * * while (sequence.hasNext()) { InputStream input = sequence.next(); InputSource * source = new InputSource(input); xmlReader.parse(source); input.close(); } * sequence.close(); * * * * IMPORTANT: inherits from InputStream rather than FilterInputStream so that * the correct read(byte[], int, int) method is used. * * @author Mark Donszelmann * @version $Id: XMLSequence.java 8584 2006-08-10 23:06:37Z duns $ */ public class XMLSequence extends InputStream { // xml declaration (lowercase!) private int[] xml = new int[] { '<', '?', 'x', 'm', 'l' }; private int xmlIndex; // look ahead buffer private int buffer[] = new int[xml.length]; private int index; private boolean bufferEmpty; // underlying stream private InputStream in; private boolean closed; private boolean eof; /** * Create a XML Sequence. * * @param input stream to read from */ public XMLSequence(InputStream input) { super(); in = input; closed = false; eof = false; xmlIndex = 0; index = 0; bufferEmpty = true; } /** * Is another XML segment available. * @return true if another XML segment can be read */ public boolean hasNext() { if (closed) return false; try { return readUntilXMLDeclaration(); } catch (IOException e) { return false; } } /** * Returns the next XML segment. * @return stream to read next XML segment from. * @throws IOException if read fails */ public InputStream next() throws IOException { if (eof) throw new NoSuchElementException(getClass() + ": at EOF."); if (closed) throw new NoSuchElementException(getClass() + ": already closed."); if (!readUntilXMLDeclaration()) throw new NoSuchElementException(getClass() + ": No more sequences."); xmlIndex = 0; return new NoCloseInputStream(this); } public int read() throws IOException { if (xmlIndex == xml.length) return -1; if (closed) return -1; int a = -1; if (!eof) { // fill buffer (at start of stream) if (bufferEmpty) { index = 0; for (int i = 0; i < xml.length; i++) { int c = in.read(); buffer[i] = c; if (buffer[i] == xml[xmlIndex]) { // we are reading 0) { // we are reading <..., which is also fine. xmlIndex++; } else { xmlIndex = 0; } } bufferEmpty = false; if (xmlIndex == xml.length) return -1; } // read next character a = in.read(); if (a != -1) { // check if seq if (a == xml[xmlIndex]) { xmlIndex++; } else { xmlIndex = 0; } } else { // underlying end-of-file eof = true; } } // returned all... if (eof && (buffer[index] == -1)) return -1; // replace and return next character int b = buffer[index]; buffer[index] = a; index = (index + 1) % buffer.length; return b; } public void mark(int readLimit) { in.mark(readLimit); } public boolean markSupported() { return in.markSupported(); } public void reset() throws IOException { if (closed) throw new IOException(getClass() + ": already closed."); if (!in.markSupported()) throw new IOException(getClass() + ": does not support reset()."); in.reset(); xmlIndex = 0; index = 0; bufferEmpty = true; eof = false; } public void close() throws IOException { if (!closed) { in.close(); closed = true; } } private boolean readUntilXMLDeclaration() throws IOException { while (read() >= 0) ; return (xmlIndex == xml.length); } } freehep-io-2.0.2/src/main/java/org/freehep/util/io/PromptListener.java0000644012010301201030000000105410466735775026627 0ustar mascellanimascellani// Copyright 2002, FreeHEP. package org.freehep.util.io; import java.io.IOException; /** * Listener to inform that Prompt of the PromptInputStream has been found. * * @author Mark Donszelmann * @version $Id: PromptListener.java 8584 2006-08-10 23:06:37Z duns $ */ public interface PromptListener { /** * Prompt was found, and can now be read. * * @param route stream for reading prompt (and more) * @throws IOException if read fails */ public void promptFound(RoutedInputStream.Route route) throws IOException; } freehep-io-2.0.2/src/main/java/org/freehep/util/io/NoCloseReader.java0000644012010301201030000000201610466735775026324 0ustar mascellanimascellani// Copyright 2003, FreeHEP. package org.freehep.util.io; import java.io.BufferedReader; import java.io.IOException; import java.io.Reader; /** * The NoCloseReader ignores the close so that one can keep reading from the * underlying stream. * * @author Mark Donszelmann * @version $Id: NoCloseReader.java 8584 2006-08-10 23:06:37Z duns $ */ public class NoCloseReader extends BufferedReader { /** * Creates a No Close Reader. * * @param reader reader to read from */ public NoCloseReader(Reader reader) { super(reader); } /** * Creates a No Close Reader. * * @param reader reader to read from * @param size buffer size */ public NoCloseReader(Reader reader, int size) { super(reader, size); } public void close() throws IOException { } /** * Closes the reader (close is ignored). * * @throws IOException if the close fails */ public void realClose() throws IOException { super.close(); } } freehep-io-2.0.2/src/main/java/org/freehep/util/io/RunLengthOutputStream.java0000644012010301201030000000527510466735775030154 0ustar mascellanimascellani// Copyright 2001, FreeHEP. package org.freehep.util.io; import java.io.FilterOutputStream; import java.io.IOException; import java.io.OutputStream; /** * The RunLengthOutputStream encodes data as Run Length encoding. The exact * definition of Run Length encoding can be found in the PostScript Language * Reference (3rd ed.) chapter 3.13.3. * * @author Mark Donszelmann * @version $Id: RunLengthOutputStream.java 8584 2006-08-10 23:06:37Z duns $ */ public class RunLengthOutputStream extends FilterOutputStream implements RunLength, FinishableOutputStream { private boolean end; private int[] buffer = new int[LENGTH]; private int index; private int last; private int count; /** * Create a Run Length output stream * * @param out stream to write */ public RunLengthOutputStream(OutputStream out) { super(out); end = false; index = 0; last = -1; count = 1; } public void write(int a) throws IOException { a &= 0x00FF; if (last > 0) { if (a == last) { // counting writeBuffer(); count++; if (count >= LENGTH) { writeCount(); } } else { // buffering if (count > 1) { writeCount(); } else { buffer[index] = last; index++; if (index >= LENGTH) { writeBuffer(); } } } } last = a; } public void finish() throws IOException { if (!end) { end = true; writeCount(); writeBuffer(); // we may have one character left in "last" (FREEHEP-578) if (last >= 0) { super.write(0); super.write(last); } super.write(EOD); flush(); if (out instanceof FinishableOutputStream) { ((FinishableOutputStream) out).finish(); } } } public void close() throws IOException { finish(); super.close(); } private void writeBuffer() throws IOException { if (index > 0) { super.write(index - 1); for (int i = 0; i < index; i++) { super.write((byte) buffer[i]); } } index = 0; } private void writeCount() throws IOException { if (count > 1) { super.write(257 - count); super.write(last); last = -1; } count = 1; } } freehep-io-2.0.2/src/main/java/org/freehep/util/io/ByteCountInputStream.java0000644012010301201030000000634110466735775027754 0ustar mascellanimascellani// Copyright 2001, FreeHEP. package org.freehep.util.io; import java.io.IOException; import java.io.InputStream; /** * The input buffer can be limited to less than the number of bytes of the * underlying buffer. Only one real input stream exists, which is where the * reads take place. A buffer is limited by some length. If more is read, -1 is * returned. Multiple limits can be set by calling pushBuffer. If bytes are left * in the buffer when popBuffer is called, they are returned in an array. * Otherwise null is returned. * * @author Mark Donszelmann * @author Charles Loomis * @version $Id: ByteCountInputStream.java 8584 2006-08-10 23:06:37Z duns $ */ public class ByteCountInputStream extends ByteOrderInputStream { private int index; private int[] size; private long len; /** * Create a Byte Count input stream from given stream * * @param in stream to read from * @param littleEndian true if stream should be little endian * @param stackDepth maximum number of buffers used while reading */ public ByteCountInputStream(InputStream in, boolean littleEndian, int stackDepth) { super(in, littleEndian); size = new int[stackDepth]; index = -1; len = 0; } public int read() throws IOException { // original stream if (index == -1) { len++; return super.read(); } // end of buffer if (size[index] <= 0) return -1; // decrease counter size[index]--; len++; return super.read(); } /** * Push the current buffer to the stack * * @param len number of bytes that can be read from the current buffer */ public void pushBuffer(int len) { if (index >= size.length - 1) { System.err .println("ByteCountInputStream: trying to push more buffers than stackDepth: " + size.length); return; } if (index >= 0) { if (size[index] < len) { System.err .println("ByteCountInputStream: trying to set a length: " + len + ", longer than the underlying buffer: " + size[index]); return; } size[index] -= len; } index++; size[index] = len; } /** * Pops the buffer from the stack and returns leftover bytes in a byte array * * @return null if buffer was completely read. Otherwise rest of buffer is * read and returned. * @throws IOException if read fails */ public byte[] popBuffer() throws IOException { if (index >= 0) { int len = size[index]; if (len > 0) { return readByte(len); } else if (len < 0) { System.err.println("ByteCountInputStream: Internal Error"); } index--; } return null; } /** * @return number of bytes that can be read from the current buffer */ public long getLength() { return (index >= 0) ? size[index] : len; } } freehep-io-2.0.2/src/main/java/org/freehep/util/io/EEXECEncryption.java0000644012010301201030000000543010466735775026546 0ustar mascellanimascellani// Copyright 2001 freehep package org.freehep.util.io; //import java.util.Random; import java.io.IOException; import java.io.OutputStream; /** * Encrypts using the EEXEC form (Used by Type 1 fonts). * * @author Simon Fischer * @version $Id: EEXECEncryption.java 8584 2006-08-10 23:06:37Z duns $ */ public class EEXECEncryption extends OutputStream implements EEXECConstants { private int n, c1, c2, r; private OutputStream out; private boolean first = true; /** * Creates an EEXECEncryption from given stream. * * @param out stream to write */ public EEXECEncryption(OutputStream out) { this(out, EEXEC_R, N); } /** * Creates an EEXECEncryption from given stream. * * @param out stream to write * @param r */ public EEXECEncryption(OutputStream out, int r) { this(out, r, N); } /** * Creates an EEXECEncryption from given stream. * * @param out stream to write * @param r * @param n */ public EEXECEncryption(OutputStream out, int r, int n) { this.out = out; this.c1 = C1; this.c2 = C2; this.r = r; this.n = n; } private int encrypt(int plainByte) { int cipher = (plainByte ^ (r >>> 8)) % 256; r = ((cipher + r) * c1 + c2) % 65536; return cipher; } public void write(int b) throws IOException { if (first) { for (int i = 0; i < n; i++) out.write(encrypt(0)); first = false; } out.write(encrypt(b)); } public void flush() throws IOException { super.flush(); out.flush(); } public void close() throws IOException { flush(); super.close(); out.close(); } private static class IntOutputStream extends OutputStream { int[] chars; int i; private IntOutputStream(int size) { chars = new int[size]; i = 0; } public void write(int b) { chars[i++] = b; } // str += (char)b; } // public String getString() { return str; } private int[] getInts() { return chars; } } /** * Encrypt array of characters. * * @param chars int array to encrypt * @param r * @param n * @return encrypted array * @throws IOException if write fails (never happens) */ public static int[] encryptString(int[] chars, int r, int n) throws IOException { IntOutputStream resultStr = new IntOutputStream(chars.length + 4); EEXECEncryption eout = new EEXECEncryption(resultStr, r, n); for (int i = 0; i < chars.length; i++) eout.write(chars[i]); return resultStr.getInts(); } } freehep-io-2.0.2/src/main/java/org/freehep/util/io/EEXECDecryption.java0000644012010301201030000000504610466735775026537 0ustar mascellanimascellani// Copyright 2001 freehep package org.freehep.util.io; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; /** * Decrypts using the EEXEC form (Used by Type 1 fonts). * * @author Simon Fischer * @version $Id: EEXECDecryption.java 8584 2006-08-10 23:06:37Z duns $ */ public class EEXECDecryption extends InputStream implements EEXECConstants { private int n, c1, c2, r; private InputStream in; private boolean first = true; /** * Creates an EEXECDecryption from the given stream * * @param in stream to read from */ public EEXECDecryption(InputStream in) { this(in, EEXEC_R, N); } /** * Creates an EEXECDecryption from the given stream * * @param in stream to read from * @param r * @param n */ public EEXECDecryption(InputStream in, int r, int n) { this.in = in; this.r = r; this.n = n; this.c1 = C1; this.c2 = C2; } private int decrypt(int cipher) { int plain = (cipher ^ (r >>> 8)) % 256; r = ((cipher + r) * c1 + c2) % 65536; return plain; } public int read() throws IOException { if (first) { byte[] bytes = new byte[n]; boolean notHex = false; for (int i = 0; i < bytes.length; i++) { int c = in.read(); bytes[i] = (byte) c; if (!Character.isDigit((char) c) && !((c >= 'a') && (c <= 'f')) && !((c >= 'A') && (c <= 'F'))) notHex = true; } if (notHex) { for (int i = 0; i < bytes.length; i++) { decrypt(bytes[i] & 0x00ff); } } else { InputStream tempIn = new ASCIIHexInputStream( new ByteArrayInputStream(bytes), true); int asciiDecoded; int byteCount = 0; while ((asciiDecoded = tempIn.read()) >= 0) { decrypt(asciiDecoded); byteCount++; } in = new ASCIIHexInputStream(in, true); while (byteCount < n) { decrypt(in.read()); byteCount++; } } first = false; } int b = in.read(); if (b == -1) return -1; else return decrypt(b); } public void close() throws IOException { super.close(); in.close(); } } freehep-io-2.0.2/src/main/java/org/freehep/util/io/RunLengthInputStream.java0000644012010301201030000000400110466735775027735 0ustar mascellanimascellani// Copyright 2001-2005, FreeHEP. package org.freehep.util.io; import java.io.IOException; import java.io.InputStream; /** * The RunLengthStream decodes Run Length encoding. The exact definition of Run * Length encoding can be found in the PostScript Language Reference (3rd ed.) * chapter 3.13.3. * * IMPORTANT: inherits from InputStream rather than FilterInputStream so that * the correct read(byte[], int, int) method is used. * * @author Mark Donszelmann * @version $Id: RunLengthInputStream.java 8584 2006-08-10 23:06:37Z duns $ */ public class RunLengthInputStream extends InputStream implements RunLength { private int[] buffer = new int[LENGTH]; private int index; private int count; private InputStream in; /** * Create a Run Length input stream * * @param input stream to read from */ public RunLengthInputStream(InputStream input) { super(); in = input; index = 0; count = 0; } public int read() throws IOException { if ((index >= count) || (index > 128)) { if (!fillBuffer()) return -1; } int b = buffer[index]; index++; return b & 0x00FF; } private boolean fillBuffer() throws IOException { count = in.read(); if (end(count)) return false; if (count < 128) { // buffered count++; for (int i = 0; i < count; i++) { buffer[i] = in.read(); if (end(buffer[i])) return false; } } else { // counted count = 257 - count; int b = in.read(); if (end(b)) return false; for (int i = 0; i < count; i++) { buffer[i] = b; } } index = 0; return true; } private boolean end(int b) { if ((b < 0) || (b == EOD)) { return true; } return false; } } freehep-io-2.0.2/src/main/java/org/freehep/util/io/TaggedOutputStream.java0000644012010301201030000001027410540603130027400 0ustar mascellanimascellani// Copyright 2001, FreeHEP. package org.freehep.util.io; import java.io.IOException; import java.io.OutputStream; /** * Class to write Tagged blocks to a Stream. The tagged blocks (Tags) contain a * tagID and a Length, so that known and unknown tags (read with the * TaggedInputStream) can again be written. The stream also allows to write * Actions, which again come with a actionCode and a length. * * A concrete implementation of this stream should encode/write the TagHeader. * All Concrete tags should be inherited from the Tag class and implement their * write methods. * * @author Mark Donszelmann * @author Charles Loomis * @version $Id: TaggedOutputStream.java 10195 2006-12-15 20:32:24Z duns $ */ public abstract class TaggedOutputStream extends ByteCountOutputStream implements TaggedOutput { /** * Set of tags that can be used by this Stream */ protected TagSet tagSet; /** * Set of actions that can be used by this Stream */ protected ActionSet actionSet; /** * Create a Tagged Output stream. * * @param out stream to write * @param tagSet allowable tag set * @param actionSet allowable action set */ public TaggedOutputStream(OutputStream out, TagSet tagSet, ActionSet actionSet) { this(out, tagSet, actionSet, false); } /** * Create a Tagged Output stream. * * @param out stream to write * @param tagSet allowable tag set * @param actionSet allowable action set * @param littleEndian true if stream is little endian */ public TaggedOutputStream(OutputStream out, TagSet tagSet, ActionSet actionSet, boolean littleEndian) { super(out, littleEndian); this.tagSet = tagSet; this.actionSet = actionSet; } /** * Writes the TagHeader, which includes a TagID and a length. * * @param header TagHeader to write * @throws IOException if write fails */ protected abstract void writeTagHeader(TagHeader header) throws IOException; /** * Specifies tag alignment: 1 byte, 2 short, 4 int and 8 long. * * @return tag alignment */ protected int getTagAlignment() { return 1; } /* * Write a tag. */ public void writeTag(Tag tag) throws IOException { int tagID = tag.getTag(); if (!tagSet.exists(tagID)) throw new UndefinedTagException(tagID); pushBuffer(); tag.write(tagID, this); int align = getTagAlignment(); int pad = (align - (getBufferLength() % align)) % align; for (int i = 0; i < pad; i++) { write(0); } int len = popBuffer(); TagHeader header = createTagHeader(tag, len); writeTagHeader(header); append(); } /** * Returns newly created TagHeader. The default implementation * creates a tagHeader from tagID and length. This method is * called "after" the tag information is written, but the * tag header is inserted before the tag info into the stream. * Its called after since it needs the length of the tag info. */ protected TagHeader createTagHeader(Tag tag, long len) { return new TagHeader(tag.getTag(), len); } /** * Writes the ActionHeader, which includes an actionCode and a length. * * @param header ActionHeader to write * @throws IOException if write fails */ protected abstract void writeActionHeader(ActionHeader header) throws IOException; /** * Write action. * * @param action action to write * @throws IOException if write fails */ public void writeAction(Action action) throws IOException { // handle end of action stream if (action == null) { writeByte(0); return; } int actionCode = action.getCode(); if (!actionSet.exists(actionCode)) throw new UndefinedTagException(actionCode); pushBuffer(); action.write(actionCode, this); int len = popBuffer(); ActionHeader header = new ActionHeader(actionCode, len); writeActionHeader(header); append(); } } freehep-io-2.0.2/src/main/java/org/freehep/util/io/IncompleteActionException.java0000644012010301201030000000216310466735775030756 0ustar mascellanimascellani// Copyright 2001, FreeHEP. package org.freehep.util.io; import java.io.IOException; /** * Exception for the TaggedInputStream. Signals that the inputstream contains * more bytes than the stream has read for this action. * * @author Mark Donszelmann * @author Charles Loomis * @version $Id: IncompleteActionException.java 8584 2006-08-10 23:06:37Z duns $ */ public class IncompleteActionException extends IOException { /** * */ private static final long serialVersionUID = -6817511986951461967L; private Action action; private byte[] rest; /** * Creates an Incomplete Action Exception * * @param action incompleted action * @param rest unused bytes */ public IncompleteActionException(Action action, byte[] rest) { super("Action " + action + " contains " + rest.length + " unread bytes"); this.action = action; this.rest = rest; } /** * @return action */ public Action getAction() { return action; } /** * @return unused bytes */ public byte[] getBytes() { return rest; } } freehep-io-2.0.2/src/main/java/org/freehep/util/io/ActionSet.java0000644012010301201030000000324510466735775025535 0ustar mascellanimascellani// Copyright 2001, FreeHEP. package org.freehep.util.io; import java.util.HashMap; import java.util.Map; /** * Class to keep registered Actions, which should be used by the * TaggedIn/OutputStream. * * A set of recognized Actions can be added to this class. A concrete * implementation of this stream should install all allowed actions. * * @author Mark Donszelmann * @author Charles Loomis * @version $Id: ActionSet.java 8584 2006-08-10 23:06:37Z duns $ */ public class ActionSet { /** * This holds the individual actions. */ protected Map actions; protected Action defaultAction; /** * Creates an set for actions */ public ActionSet() { actions = new HashMap(); defaultAction = new Action.Unknown(); } /** * Adds an action to the set * * @param action to be added */ public void addAction(Action action) { actions.put(new Integer(action.getCode()), action); } /** * Looks up the corresponding action for an action code. * * @param actionCode code to be looked for * @return corresponding action, or Action.Unknown in case Action is not * found. */ public Action get(int actionCode) { Action action = (Action) actions.get(new Integer(actionCode)); if (action == null) action = defaultAction; return action; } /** * Looks if an Action for code is in this set. * * @param actionCode code to be looked for * @return true if action exists for code */ public boolean exists(int actionCode) { return (actions.get(new Integer(actionCode)) != null); } } freehep-io-2.0.2/src/main/java/org/freehep/util/io/ASCII85OutputStream.java0000644012010301201030000000657010547553231027233 0ustar mascellanimascellani// Copyright 2001-2007, FreeHEP. package org.freehep.util.io; import java.io.FilterOutputStream; import java.io.IOException; import java.io.OutputStream; /** * The ASCII85InputStream encodes binary data as ASCII base-85 encoding. The * exact definition of ASCII base-85 encoding can be found in the PostScript * Language Reference (3rd ed.) chapter 3.13.3. * * @author Mark Donszelmann * @version $Id: ASCII85OutputStream.java 10259 2007-01-05 22:52:09Z duns $ */ public class ASCII85OutputStream extends FilterOutputStream implements ASCII85, FinishableOutputStream { private boolean end; private int characters; private int b[] = new int[4]; private int bIndex; private int c[] = new int[5]; private String newline = "\n"; /** * Create an ASCII85 Output Stream from given stream * * @param out output stream to use */ public ASCII85OutputStream(OutputStream out) { super(out); characters = MAX_CHARS_PER_LINE; end = false; bIndex = 0; try { newline = System.getProperty("line.separator"); } catch (SecurityException e) { // ignored; } } public void write(int a) throws IOException { b[bIndex] = a & 0x00FF; bIndex++; if (bIndex >= b.length) { writeTuple(); bIndex = 0; } } public void finish() throws IOException { if (!end) { end = true; if (bIndex > 0) { writeTuple(); } writeEOD(); flush(); if (out instanceof FinishableOutputStream) { ((FinishableOutputStream) out).finish(); } } } public void close() throws IOException { finish(); super.close(); } private void writeTuple() throws IOException { // fill the rest for (int i = bIndex; i < b.length; i++) { b[i] = 0; } // convert long d = ((b[0] << 24) | (b[1] << 16) | (b[2] << 8) | b[3]) & 0x00000000FFFFFFFFL; c[0] = (int) (d / a85p4 + '!'); d = d % a85p4; c[1] = (int) (d / a85p3 + '!'); d = d % a85p3; c[2] = (int) (d / a85p2 + '!'); d = d % a85p2; c[3] = (int) (d / a85p1 + '!'); c[4] = (int) (d % a85p1 + '!'); // convert !!!!! to z if ((bIndex >= b.length) && (c[0] == '!') && (c[1] == '!') && (c[2] == '!') && (c[3] == '!') && (c[4] == '!')) { writeChar('z'); } else { for (int i = 0; i < bIndex + 1; i++) { writeChar(c[i]); } } } // Fix for IO-7 private void writeEOD() throws IOException { if (characters <= 1) { characters = MAX_CHARS_PER_LINE; writeNewLine(); } characters -= 2; super.write('~'); super.write('>'); } private void writeChar(int b) throws IOException { if (characters == 0) { characters = MAX_CHARS_PER_LINE; writeNewLine(); } characters--; super.write(b); } private void writeNewLine() throws IOException { // write a newline for (int i=0; i < newline.length(); i++) { super.write(newline.charAt(i)); } } } freehep-io-2.0.2/src/main/java/org/freehep/util/io/ActionHeader.java0000644012010301201030000000240110466735775026163 0ustar mascellanimascellani// Copyright 2001, FreeHEP. package org.freehep.util.io; /** * Keeps the actionCode and Length of a specific action. To be used in the * TaggedInputStream to return the actionCode and Length, and in the * TaggedOutputStream to write them. * * @author Mark Donszelmann * @author Charles Loomis * @version $Id: ActionHeader.java 8584 2006-08-10 23:06:37Z duns $ */ public class ActionHeader { int actionCode; long length; /** * Creates an action header * * @param actionCode code for action * @param length total length of the tag */ public ActionHeader(int actionCode, long length) { this.actionCode = actionCode; this.length = length; } /** * Sets the action code * * @param actionCode new action code */ public void setAction(int actionCode) { this.actionCode = actionCode; } /** * @return action code */ public int getAction() { return actionCode; } /** * Sets the length of this tag * * @param length new length */ public void setLength(long length) { this.length = length; } /** * @return length of this tag */ public long getLength() { return length; } } freehep-io-2.0.2/src/main/java/org/freehep/util/io/DCTInputStream.java0000644012010301201030000000214310466735775026446 0ustar mascellanimascellani// Copyright 2003, FreeHEP. package org.freehep.util.io; import java.awt.Image; import java.io.FilterInputStream; import java.io.IOException; import java.io.InputStream; import javax.imageio.ImageIO; /** * Reads images from a JPEG Stream, but only images. * * @author Mark Donszelmann * @version $Id: DCTInputStream.java 8584 2006-08-10 23:06:37Z duns $ */ /** * @author duns * */ public class DCTInputStream extends FilterInputStream { /** * Creates a DCT input stream from the given input stream * * @param input stream to read from */ public DCTInputStream(InputStream input) { super(input); } /** * Read is not supported, only readImage. * * @see java.io.FilterInputStream#read() */ public int read() throws IOException { throw new IOException(getClass() + ": read() not implemented, use readImage()."); } /** * @return image read * @throws IOException if read fails */ public Image readImage() throws IOException { return ImageIO.read(new NoCloseInputStream(this)); } } freehep-io-2.0.2/src/main/java/org/freehep/util/io/TaggedOutput.java0000644012010301201030000000102410466735775026251 0ustar mascellanimascellani// Copyright 2001, FreeHEP. package org.freehep.util.io; import java.io.IOException; /** * @author Mark Donszelmann * @version $Id: TaggedOutput.java 8584 2006-08-10 23:06:37Z duns $ */ public interface TaggedOutput { /** * Write a tag. * * @param tag tag to write * @throws IOException if write fails */ public void writeTag(Tag tag) throws IOException; /** * Close the stream * * @throws IOException if close fails */ public void close() throws IOException; } freehep-io-2.0.2/src/main/java/org/freehep/util/io/LineNumberWriter.java0000644012010301201030000001366710466735775027112 0ustar mascellanimascellani// Copyright 2003, FreeHEP. package org.freehep.util.io; import java.io.IOException; import java.io.Writer; import java.util.EventListener; import java.util.EventObject; import java.util.TooManyListenersException; /** * Counts line numbers, based on the first cr-lf, cr or lf it finds. Informs a * listener when the linenumber exceeds a threshold. * * Listeners can only be informed from the second line only. * * @author Mark Donszelmann * @version $Id: LineNumberWriter.java 8584 2006-08-10 23:06:37Z duns $ */ public class LineNumberWriter extends Writer { private final static int UNKNOWN = 0; private final static int CR = 1; private final static int CRLF = 2; private final static int LF = 3; private final static int LFCR = 4; private int lineSeparator = UNKNOWN; private Writer out; private int lineNo = 0; private LineNumberListener listener; private int lineNoLimit; private int previous = -1; /** * Creates a Line Number Writer * * @param out writer to write to */ public LineNumberWriter(Writer out) { this.out = out; } public void write(char cbuf[]) throws IOException { write(cbuf, 0, cbuf.length); } public void write(char cbuf[], int off, int len) throws IOException { for (int i = 0; i < len; i++) { write(cbuf[off + i]); } } public void write(String str) throws IOException { write(str, 0, str.length()); } public void write(String str, int off, int len) throws IOException { for (int i = 0; i < len; i++) { write(str.charAt(off + i)); } } public void write(int c) throws IOException { boolean newLine = false; synchronized (lock) { out.write(c); switch (lineSeparator) { default: case UNKNOWN: switch (previous) { case '\r': lineNo++; lineSeparator = (c == '\n') ? CRLF : CR; if (c == '\r') lineNo++; break; case '\n': lineNo++; lineSeparator = (c == '\r') ? LFCR : LF; if (c == '\n') lineNo++; break; default: break; } break; case CR: if (c == '\r') { lineNo++; newLine = true; } break; case CRLF: if ((previous == '\r') && (c == '\n')) { lineNo++; newLine = true; } break; case LF: if (c == '\n') { lineNo++; newLine = true; } break; case LFCR: if ((previous == '\n') && (c == '\r')) { lineNo++; newLine = true; } break; } previous = c; } if ((listener != null) && newLine && (lineNo >= lineNoLimit)) { listener.lineNumberReached(new LineNumberEvent(this, lineNo)); } } public void close() throws IOException { out.close(); } public void flush() throws IOException { out.flush(); } /** * Returns the line number that is currently being written. * * @return current line number */ public int getLineNumber() { return lineNo; } /** * Set the current line number * * @param lineNo new line number */ public void setLineNumber(int lineNo) { this.lineNo = lineNo; } /** * Add a LineNumberListener * * @param listener new listener * @param lineNoLimit line number for which to generate a LineNumberEvent * @throws TooManyListenersException if there is more than one listener */ public void addLineNumberListener(LineNumberListener listener, int lineNoLimit) throws TooManyListenersException { if (this.listener != null) throw new TooManyListenersException(); if (lineNoLimit < 2) throw new IllegalArgumentException( "LineNoLimit cannot be less than 2"); this.listener = listener; this.lineNoLimit = lineNoLimit; } /** * LineNumberListener interface can inform a listener about changes in the * line number, or when a linenumber limit has been reached. * * @author duns * @version $Id: LineNumberWriter.java 8584 2006-08-10 23:06:37Z duns $ */ public static interface LineNumberListener extends EventListener { /** * Called when the line number limit has been reached. * * @param event line number event */ public void lineNumberReached(LineNumberEvent event); } /** * Event to be used by the LineNumberListener interface. * * @author duns * @version $Id: LineNumberWriter.java 8584 2006-08-10 23:06:37Z duns $ */ public static class LineNumberEvent extends EventObject { /** * */ private static final long serialVersionUID = 2821724279014031198L; private int lineNo; /** * Create a LineNumberEvent * * @param source event source * @param lineNo current line number */ public LineNumberEvent(Object source, int lineNo) { super(source); this.lineNo = lineNo; } /** * @return current line number */ public int getLineNumber() { return lineNo; } public String toString() { return "LineNumberEvent: line=" + lineNo + "; " + getSource().toString(); } } } freehep-io-2.0.2/src/main/java/org/freehep/util/io/EncodingException.java0000644012010301201030000000106310466735775027245 0ustar mascellanimascellani// Copyright 2001, FreeHEP. package org.freehep.util.io; import java.io.IOException; /** * Encoding Exception for any of the encoding streams. * * @author Mark Donszelmann * @version $Id: EncodingException.java 8584 2006-08-10 23:06:37Z duns $ */ public class EncodingException extends IOException { /** * */ private static final long serialVersionUID = 8496816190751796701L; /** * Creates an Encoding Exception * * @param msg message */ public EncodingException(String msg) { super(msg); } } freehep-io-2.0.2/src/main/java/org/freehep/util/io/RouteListener.java0000644012010301201030000000160310466735775026444 0ustar mascellanimascellani// Copyright 2002, FreeHEP. package org.freehep.util.io; import java.io.IOException; /** * Listener to inform that a specific route of the RoutedInputStream has been * found. * * @author Mark Donszelmann * @version $Id: RouteListener.java 8584 2006-08-10 23:06:37Z duns $ */ public interface RouteListener { /** * Route was found, input is supplied. If you close the Route, all remaining * bytes will be read/discarded up to and including the end marker. If the * end marker is null, all bytes from the underling stream will be read. If * you just return, the underlying main stream will still return every byte * in this route. This way you can just be informed of the start of a route. * * @param input stream to read * @throws IOException if read fails */ public void routeFound(RoutedInputStream.Route input) throws IOException; } freehep-io-2.0.2/src/main/java/org/freehep/util/io/Base64OutputStream.java0000644012010301201030000000747110466735775027272 0ustar mascellanimascellani// Copyright 2003, FreeHEP. package org.freehep.util.io; import java.io.FilterOutputStream; import java.io.IOException; import java.io.OutputStream; /** * The Base64OutputStream encodes binary data according to RFC 2045. * * @author Mark Donszelmann * @version $Id: Base64OutputStream.java 8584 2006-08-10 23:06:37Z duns $ */ public class Base64OutputStream extends FilterOutputStream implements FinishableOutputStream { private int MAX_LINE_LENGTH = 74; private int position; private byte[] buffer; private int lineLength; private static final char intToBase64[] = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', // 0 - 7 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', // 8 - 15 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', // 16 - 23 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', // 24 - 31 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', // 32 - 39 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', // 40 - 47 'w', 'x', 'y', 'z', '0', '1', '2', '3', // 48 - 55 '4', '5', '6', '7', '8', '9', '+', '/' // 56 - 63 }; private String newline = "\n"; /** * Creates a Base64 output stream for given output * * @param out stream to write to */ public Base64OutputStream(OutputStream out) { super(out); buffer = new byte[3]; position = 0; lineLength = 0; try { newline = System.getProperty("line.separator"); } catch (SecurityException e) { // ignored; } } public void write(int a) throws IOException { buffer[position++] = (byte) a; if (position < buffer.length) return; // System.out.print(Integer.toHexString(buffer[0])+", // "+Integer.toHexString(buffer[1])+", // "+Integer.toHexString(buffer[2])+" "); writeTuple(); // writeNewLine(); lineLength += 4; if (lineLength >= MAX_LINE_LENGTH) { writeNewLine(); lineLength = 0; } position = 0; } public void finish() throws IOException { writeTuple(); flush(); if (out instanceof FinishableOutputStream) { ((FinishableOutputStream) out).finish(); } } public void close() throws IOException { finish(); super.close(); } private void writeTuple() throws IOException { int data = (position > 0 ? (buffer[0] << 16) & 0x00FF0000 : 0) | (position > 1 ? (buffer[1] << 8) & 0x0000FF00 : 0) | (position > 2 ? (buffer[2]) & 0x000000FF : 0); // System.out.println(Integer.toHexString(data)); switch (position) { case 3: // System.out.println("\n*** "+((data >> 18) & 0x3f) +", "+((data >> // 12) & 0x3f)+", "+ // ((data >> 6) & 0x3f) +", "+((data ) & 0x3f)); out.write(intToBase64[(data >> 18) & 0x3f]); out.write(intToBase64[(data >> 12) & 0x3f]); out.write(intToBase64[(data >> 6) & 0x3f]); out.write(intToBase64[(data) & 0x3f]); return; case 2: out.write(intToBase64[(data >> 18) & 0x3f]); out.write(intToBase64[(data >> 12) & 0x3f]); out.write(intToBase64[(data >> 6) & 0x3f]); out.write('='); return; case 1: out.write(intToBase64[(data >> 18) & 0x3f]); out.write(intToBase64[(data >> 12) & 0x3f]); out.write('='); out.write('='); return; default: return; } } private void writeNewLine() throws IOException { // write a newline for (int i=0; i < newline.length(); i++) { out.write(newline.charAt(i)); } } } freehep-io-2.0.2/src/main/java/org/freehep/util/io/ByteOrderInputStream.java0000644012010301201030000001724210466735775027741 0ustar mascellanimascellani// Copyright 2001, FreeHEP. package org.freehep.util.io; import java.io.DataInput; import java.io.DataInputStream; import java.io.EOFException; import java.io.IOException; import java.io.InputStream; /** * Class to read bytes and pairs of bytes in both little and big endian order. * * @author Mark Donszelmann * @author Charles Loomis * @version $Id: ByteOrderInputStream.java 8584 2006-08-10 23:06:37Z duns $ */ public class ByteOrderInputStream extends BitInputStream implements DataInput { protected boolean little; /** * Create a byte order (big-endian) input stream from given stream. * * @param in stream to read from */ public ByteOrderInputStream(InputStream in) { this(in, false); } /** * Create a byte order input stream from given stream. * * @param in stream to read from * @param littleEndian true if stream should be little endian. */ public ByteOrderInputStream(InputStream in, boolean littleEndian) { super(in); little = littleEndian; } public void readFully(byte b[]) throws IOException { readFully(b, 0, b.length); } public void readFully(byte b[], int off, int len) throws IOException { if (len < 0) throw new IndexOutOfBoundsException(); int n = 0; while (n < len) { int count = read(b, off + n, len - n); if (count < 0) throw new EOFException(); n += count; } } public int skipBytes(int n) throws IOException { int total = 0; int cur = 0; while ((total < n) && ((cur = (int) skip(n - total)) > 0)) { total += cur; } return total; } public boolean readBoolean() throws IOException { int b = readUnsignedByte(); return (b != 0); } public char readChar() throws IOException { int b1 = readUnsignedByte(); int b2 = readUnsignedByte(); return (little) ? (char) ((b1 << 8) + b2) : (char) ((b2 << 8) + b1); } /** * Read a signed byte. */ public byte readByte() throws IOException { byteAlign(); int b = read(); if (b < 0) throw new EOFException(); return (byte) b; } /** * Read n bytes and return in byte array. * * @param n number of bytes to read * @return byte array * @throws IOException if read fails */ public byte[] readByte(int n) throws IOException { byteAlign(); byte[] bytes = new byte[n]; for (int i = 0; i < n; i++) { int b = read(); if (b < 0) throw new EOFException(); bytes[i] = (byte) b; } return bytes; } /** * Read an unsigned byte. */ public int readUnsignedByte() throws IOException { byteAlign(); int ub = read(); if (ub < 0) throw new EOFException(); return ub; } /** * Read n unsigned bytes and return in int array. * * @param n number of bytes to read * @return int array * @throws IOException if read fails */ public int[] readUnsignedByte(int n) throws IOException { byteAlign(); int[] bytes = new int[n]; for (int i = 0; i < n; i++) { int ub = read(); if (ub < 0) throw new EOFException(); bytes[i] = ub; } return bytes; } /** * Read a signed short. */ public short readShort() throws IOException { int i1 = readUnsignedByte(); int i2 = readUnsignedByte(); return (little) ? (short) ((i2 << 8) + i1) : (short) ((i1 << 8) + i2); } /** * Read n shorts and return in short array * * @param n number of shorts to read * @return short array * @throws IOException if read fails */ public short[] readShort(int n) throws IOException { short[] shorts = new short[n]; for (int i = 0; i < n; i++) { shorts[i] = readShort(); } return shorts; } /** * Read an unsigned short. */ public int readUnsignedShort() throws IOException { byteAlign(); int i1 = readUnsignedByte(); int i2 = readUnsignedByte(); return (little) ? (i2 << 8) + i1 : (i1 << 8) + i2; } /** * Read n unsigned shorts and return in int array * * @param n number of shorts to read * @return int array * @throws IOException if read fails */ public int[] readUnsignedShort(int n) throws IOException { int[] shorts = new int[n]; for (int i = 0; i < n; i++) { shorts[i] = readUnsignedShort(); } return shorts; } /** * Read a signed integer. */ public int readInt() throws IOException { int i1 = readUnsignedByte(); int i2 = readUnsignedByte(); int i3 = readUnsignedByte(); int i4 = readUnsignedByte(); return (little) ? (i4 << 24) + (i3 << 16) + (i2 << 8) + i1 : (i1 << 24) + (i2 << 16) + (i3 << 8) + i4; } /** * Read n ints and return in int array. * * @param n number of ints to read * @return int array * @throws IOException if read fails */ public int[] readInt(int n) throws IOException { int[] ints = new int[n]; for (int i = 0; i < n; i++) { ints[i] = readInt(); } return ints; } /** * Read an unsigned integer. * * @return long * @throws IOException if read fails */ public long readUnsignedInt() throws IOException { long i1 = readUnsignedByte(); long i2 = readUnsignedByte(); long i3 = readUnsignedByte(); long i4 = readUnsignedByte(); return (little) ? (i4 << 24) + (i3 << 16) + (i2 << 8) + i1 : (i1 << 24) + (i2 << 16) + (i3 << 8) + i4; } /** * Read n unsigned ints and return in long array. * * @param n number of ints to read * @return long array * @throws IOException if read fails */ public long[] readUnsignedInt(int n) throws IOException { long[] ints = new long[n]; for (int i = 0; i < n; i++) { ints[i] = readUnsignedInt(); } return ints; } public long readLong() throws IOException { long i1 = readInt(); long i2 = readInt(); return (little) ? (i2 << 32) + (i1 & 0xFFFFFFFFL) : (i1 << 32) + (i2 & 0xFFFFFFFFL); } public float readFloat() throws IOException { return Float.intBitsToFloat(readInt()); } public double readDouble() throws IOException { return Double.longBitsToDouble(readLong()); } /** * @deprecated */ public String readLine() throws IOException { throw new IOException( "ByteOrderInputStream.readLine() is deprecated and not implemented."); } /** * Read a string (UTF). * * @return string * @throws IOException if read fails */ public String readString() throws IOException { return readUTF(); } public String readUTF() throws IOException { return DataInputStream.readUTF(this); } /** * Read an ascii-z (0 terminated c-string). * * @return string * @throws IOException if read fails */ public String readAsciiZString() throws IOException { StringBuffer buffer = new StringBuffer(); char c = (char) readUnsignedByte(); while (c != 0) { buffer.append(c); c = (char) readUnsignedByte(); } return buffer.toString(); } } freehep-io-2.0.2/src/main/java/org/freehep/util/io/TagSet.java0000644012010301201030000000341310466735775025030 0ustar mascellanimascellani// Copyright 2001, FreeHEP. package org.freehep.util.io; import java.util.HashMap; import java.util.Map; /** * Class to keep registered Tags, which should be used by the * TaggedIn/OutputStream. * * A set of recognized Tags can be added to this class. A concrete * implementation of this stream should install all allowed tags. * * @author Mark Donszelmann * @author Charles Loomis * @version $Id: TagSet.java 8584 2006-08-10 23:06:37Z duns $ */ public class TagSet { /** * This holds the individual tags. */ protected Map tags; /** * The default tag handler. */ protected Tag defaultTag; /** * Creates a Tag Set. */ public TagSet() { // Initialize the tag classes. defaultTag = new UndefinedTag(); tags = new HashMap(); } /** * Add a new tag to this set. If the tagID returned is the DEFAULT_TAG, then * the default handler is set to the given handler. * @param tag tag to be added to set */ public void addTag(Tag tag) { int id = tag.getTag(); if (id != Tag.DEFAULT_TAG) { tags.put(new Integer(id), tag); } else { defaultTag = tag; } } /** * Find tag for tagID. * @param tagID tagID to find * @return correspoding tag or UndefinedTag if tagID is not found. */ public Tag get(int tagID) { Tag tag = (Tag) tags.get(new Integer(tagID)); if (tag == null) tag = defaultTag; return tag; } /** * Finds out if Tag for TagID exists. * * @param tagID tagID to find * @return true if corresponding Tag for TagID exists */ public boolean exists(int tagID) { return (tags.get(new Integer(tagID)) != null); } } freehep-io-2.0.2/src/main/java/org/freehep/util/io/WriterOutputStream.java0000644012010301201030000000211610466735775027511 0ustar mascellanimascellani// Copyright 2003, FreeHEP. package org.freehep.util.io; import java.io.IOException; import java.io.OutputStream; import java.io.Writer; /** * The WriterOutputStream makes a Writer look like an OutputStream. * * @author Mark Donszelmann * @version $Id: WriterOutputStream.java 8584 2006-08-10 23:06:37Z duns $ */ public class WriterOutputStream extends OutputStream { private Writer writer; /** * Create an Output Stream from given Writer. * * @param writer writer to write to */ public WriterOutputStream(Writer writer) { this.writer = writer; } public void write(int b) throws IOException { writer.write(b & 0xFF); } public void write(byte[] b) throws IOException { write(b, 0, b.length); } public void write(byte[] b, int off, int len) throws IOException { for (int i = 0; i < len; i++) { writer.write(b[off + i]); } } public void close() throws IOException { writer.close(); } public void flush() throws IOException { writer.flush(); } } freehep-io-2.0.2/src/main/java/org/freehep/util/io/ASCII85InputStream.java0000644012010301201030000000766710466735775027061 0ustar mascellanimascellani// Copyright 2001, FreeHEP. package org.freehep.util.io; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; /** * The ASCII85InputStream decodes ASCII base-85 encoded data. The exact * definition of ASCII base-85 encoding can be found in the PostScript Language * Reference (3rd ed.) chapter 3.13.3. * * IMPORTANT: inherits from InputStream rather than FilterInputStream so that * the correct read(byte[], int, int) method is used. * * @author Mark Donszelmann * @version $Id: ASCII85InputStream.java 8584 2006-08-10 23:06:37Z duns $ */ public class ASCII85InputStream extends InputStream implements ASCII85 { private boolean endReached; private int b[] = new int[4]; private int bIndex; private int bLength; private int c[] = new int[5]; private int lineNo; private int prev; private InputStream in; /** * Create an ASCII85 Input Stream from given stream. * * @param input input to use */ public ASCII85InputStream(InputStream input) { super(); in = input; bIndex = 0; bLength = 0; endReached = false; prev = -1; lineNo = 1; } public int read() throws IOException { if (bIndex >= bLength) { if (endReached) return -1; bLength = readTuple(); if (bLength < 0) return -1; bIndex = 0; } int a = b[bIndex]; bIndex++; return a; } /** * @return current line number */ public int getLineNo() { return lineNo; } private int readTuple() throws IOException, EncodingException { int cIndex = 0; int ch = -1; while ((!endReached) && (cIndex < 5)) { prev = ch; ch = in.read(); switch (ch) { case -1: throw new EncodingException( "missing '~>' at end of ASCII85 stream"); case 'z': b[0] = b[1] = b[2] = b[3] = '!'; return 4; case '~': if (in.read() != '>') throw new EncodingException("Invalid ASCII85 EOD"); endReached = true; break; case '\r': lineNo++; break; case '\n': if (prev != '\r') { lineNo++; } break; case ' ': case '\t': case '\f': case 0: // ignored break; default: c[cIndex] = ch; cIndex++; break; } } if (cIndex > 0) { // fill the rest for (int i = 0; i < c.length; i++) { if (i >= cIndex) { c[i] = '!'; } else { c[i] -= '!'; } } // convert long d = ((c[0] * a85p4) + (c[1] * a85p3) + (c[2] * a85p2) + (c[3] * a85p1) + c[4]) & 0x00000000FFFFFFFFL; b[0] = (int) ((d >> 24) & 0x00FF); b[1] = (int) ((d >> 16) & 0x00FF); b[2] = (int) ((d >> 8) & 0x00FF); b[3] = (int) (d & 0x00FF); } return cIndex - 1; } /** * Print out ASCII85 of a file * * @param args filename * @throws Exception when file does not exist */ public static void main(String[] args) throws Exception { if (args.length < 1) { System.err.println("Usage: ASCII85InputStream filename"); System.exit(1); } ASCII85InputStream in = new ASCII85InputStream(new FileInputStream(args[0])); int b = in.read(); while (b != -1) { System.out.write(b); b = in.read(); } in.close(); System.out.flush(); } } freehep-io-2.0.2/src/main/java/org/freehep/util/io/UniquePrintStream.java0000644012010301201030000000232510466735775027301 0ustar mascellanimascellani// Copyright 2001, FreeHEP. package org.freehep.util.io; import java.io.OutputStream; import java.io.PrintStream; import java.util.Iterator; import java.util.SortedSet; import java.util.TreeSet; /** * The UniquePrintStream keeps Strings buffered in sorted order, but any * duplicates are removed. This stream can be used to print error messages * exactly once. When finish is called all messages are printed. * * It only acts on the println(String) method, any other method will print * directly. * * @author Mark Donszelmann * @version $Id: UniquePrintStream.java 8584 2006-08-10 23:06:37Z duns $ */ public class UniquePrintStream extends PrintStream implements FinishableOutputStream { private SortedSet msg = new TreeSet(); /** * Create a Unique Print Stream. * * @param out stream to write */ public UniquePrintStream(OutputStream out) { super(out); } public void println(String s) { synchronized (this) { msg.add(s); } } public void finish() { for (Iterator i = msg.iterator(); i.hasNext();) { String s = (String) i.next(); super.println(s); } msg = new TreeSet(); } } freehep-io-2.0.2/src/main/java/org/freehep/util/io/CountedByteOutputStream.java0000644012010301201030000000213310466735775030461 0ustar mascellanimascellani// Copyright 2001, FreeHEP. package org.freehep.util.io; import java.io.FilterOutputStream; import java.io.IOException; import java.io.OutputStream; /** * The CountedByteOutputStream counts the number of bytes written. * * @author Mark Donszelmann * @version $Id: CountedByteOutputStream.java 8584 2006-08-10 23:06:37Z duns $ */ public class CountedByteOutputStream extends FilterOutputStream { private int count; /** * Creates a Counted Bytes output stream from the given stream. * * @param out stream to write to */ public CountedByteOutputStream(OutputStream out) { super(out); count = 0; } public void write(int b) throws IOException { out.write(b); count++; } public void write(byte[] b) throws IOException { out.write(b); count += b.length; } public void write(byte[] b, int offset, int len) throws IOException { out.write(b, offset, len); count += len; } /** * @return number of bytes written. */ public int getCount() { return count; } } freehep-io-2.0.2/src/main/java/org/freehep/util/io/UndefinedTagException.java0000644012010301201030000000172410466735775030060 0ustar mascellanimascellani// Copyright 2001, FreeHEP. package org.freehep.util.io; import java.io.IOException; /** * Exception for the TaggedOutputStream. Signals that the user tries to write a * tag which is not defined at this version or below. * * @author Mark Donszelmann * @author Charles Loomis * @version $Id: UndefinedTagException.java 8584 2006-08-10 23:06:37Z duns $ */ public class UndefinedTagException extends IOException { /** * */ private static final long serialVersionUID = 7504997713135869344L; /** * Create an Undefined Tag Exception. */ public UndefinedTagException() { super(); } /** * Create an Undefined Tag Exception. * @param msg message */ public UndefinedTagException(String msg) { super(msg); } /** * Create an Undefined Tag Exception. * @param code undefined tagID */ public UndefinedTagException(int code) { super("Code: (" + code + ")"); } } freehep-io-2.0.2/src/main/java/org/freehep/util/io/FlateInputStream.java0000644012010301201030000000167710340422372027053 0ustar mascellanimascellani// Copyright 2001-2003, FreeHEP. package org.freehep.util.io; import java.awt.Image; import java.io.IOException; import java.io.InputStream; import java.util.zip.InflaterInputStream; /** * The FlateInputStream uses the Deflate mechanism to compress data. The exact * definition of Deflate encoding can be found in the PostScript Language * Reference (3rd ed.) chapter 3.13.3. * * @author Mark Donszelmann * @version $Id: FlateOutputStream.java,v 1.1 2001/06/05 10:32:52 duns Exp $ */ public class FlateInputStream extends InflaterInputStream { /** * Create a (De)Flate input stream. * * @param in stream to read from */ public FlateInputStream(InputStream in) { super(in); } /** * Reads an image FIXME NOT IMPLEMENTED * * @return null * @throws IOException */ public Image readImage() throws IOException { return null; } } freehep-io-2.0.2/src/main/java/org/freehep/util/io/NoCloseWriter.java0000644012010301201030000000203110466735775026373 0ustar mascellanimascellani// Copyright 2003, FreeHEP. package org.freehep.util.io; import java.io.BufferedWriter; import java.io.IOException; import java.io.Writer; /** * The NoCloseWriter ignores the close so that one can keep writing to the * underlying stream. * * @author Mark Donszelmann * @version $Id: NoCloseWriter.java 8584 2006-08-10 23:06:37Z duns $ */ public class NoCloseWriter extends BufferedWriter { /** * Creates a No Close Writer * * @param writer writer to write to */ public NoCloseWriter(Writer writer) { super(writer); } /** * Creates a No Close Writer * * @param writer writer to write to * @param size buffer size */ public NoCloseWriter(Writer writer, int size) { super(writer, size); } public void close() throws IOException { flush(); } /** * Closes the writer (close is ignored). * * @throws IOException if the close fails */ public void realClose() throws IOException { super.close(); } } freehep-io-2.0.2/src/main/java/org/freehep/util/io/IncompleteTagException.java0000644012010301201030000000207110466735775030252 0ustar mascellanimascellani// Copyright 2001, FreeHEP. package org.freehep.util.io; import java.io.IOException; /** * Exception for the TaggedInputStream. Signals that the inputstream contains * more bytes than the stream has read for this tag. * * @author Mark Donszelmann * @author Charles Loomis * @version $Id: IncompleteTagException.java 8584 2006-08-10 23:06:37Z duns $ */ public class IncompleteTagException extends IOException { /** * */ private static final long serialVersionUID = -7808675150856818588L; private Tag tag; private byte[] rest; /** * Creates an Incomplete Tag Exception * * @param tag incomplete tag * @param rest unused bytes */ public IncompleteTagException(Tag tag, byte[] rest) { super("Tag " + tag + " contains " + rest.length + " unread bytes"); this.tag = tag; this.rest = rest; } /** * @return tag */ public Tag getTag() { return tag; } /** * @return unused bytes */ public byte[] getBytes() { return rest; } } freehep-io-2.0.2/src/main/java/org/freehep/util/io/Base64InputStream.java0000644012010301201030000001073310466735775027064 0ustar mascellanimascellani// Copyright 2003, FreeHEP. package org.freehep.util.io; import java.io.IOException; import java.io.InputStream; /** * The Base64InputStream decodes binary data according to RFC 2045. * * IMPORTANT: inherits from InputStream rather than FilterInputStream so that * the correct read(byte[], int, int) method is used. * * @author Mark Donszelmann * @version $Id: Base64InputStream.java 8584 2006-08-10 23:06:37Z duns $ */ public class Base64InputStream extends InputStream { private int b[] = new int[3]; private int bIndex; private int bLength; private boolean endReached; private int lineNo; private InputStream in; private static final int ILLEGAL = -1; // private static final int WHITESPACE = -2; private static final int LINEFEED = -3; private static final int CARRIAGERETURN = -4; private static final int EQUALS = -5; private static final byte base64toInt[] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -2, -3, -1, -1, -4, -1, -1, // Tab, LineFeed, CarriageReturn -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63, // Space, Plus, Slash 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -5, -1, -1, // 0 - 9, = -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, // A-Z 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1, -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, // a-z 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1 }; /** * Creates a Base64 input stream for given input * * @param input to be read from */ public Base64InputStream(InputStream input) { super(); in = input; endReached = false; bIndex = 0; bLength = 0; lineNo = 1; } public int read() throws IOException { if (bIndex >= bLength) { if (endReached) return -1; bLength = readTuple(); if (bLength <= 0) return -1; bIndex = 0; } int a = b[bIndex]; bIndex++; return a; } /** * @return current line number */ public int getLineNo() { return lineNo; } private int readTuple() throws IOException, EncodingException { byte c[] = new byte[4]; int cIndex = 0; int encoding = 0; int prevEncoding = 0; int i = 0; if (endReached) return 0; while (i < c.length) { int ch = in.read(); if (ch < 0) { endReached = true; if (cIndex == 0) { // still a proper end. return 0; } else { throw new EncodingException( "Improperly padded Base64 Input."); } } prevEncoding = encoding; encoding = base64toInt[ch & 0x7f]; switch (encoding) { case ILLEGAL: if (ch < 0) throw new EncodingException( "Illegal character in Base64 encoding '" + ch + "'."); case EQUALS: // ignore, but keep reading padding i++; break; case CARRIAGERETURN: lineNo++; break; case LINEFEED: if (prevEncoding != CARRIAGERETURN) { lineNo++; } break; default: c[cIndex] = (byte) (encoding & 0xFF); cIndex++; i++; break; } } int data; switch (cIndex) { case 2: data = (c[0] << 18) | (c[1] << 12); b[0] = data >>> 16; return 1; case 3: data = (c[0] << 18) | (c[1] << 12) | (c[2] << 6); b[0] = data >>> 16; b[1] = data >>> 8; return 2; case 4: data = (c[0] << 18) | (c[1] << 12) | (c[2] << 6) | (c[3]); b[0] = data >>> 16; b[1] = data >>> 8; b[2] = data; return 3; default: throw new EncodingException("Base64InputStream: internal error."); } } } freehep-io-2.0.2/src/main/java/org/freehep/util/io/ASCIIHexOutputStream.java0000644012010301201030000000470110466735775027534 0ustar mascellanimascellani// Copyright 2001, FreeHEP. package org.freehep.util.io; import java.io.FilterOutputStream; import java.io.IOException; import java.io.OutputStream; /** * The ASCIIHexOutputStream encodes binary data as ASCII Hexadecimal. The exact * definition of ASCII Hex encoding can be found in the PostScript Language * Reference (3rd ed.) chapter 3.13.3. * * @author Mark Donszelmann * @version $Id: ASCIIHexOutputStream.java 8584 2006-08-10 23:06:37Z duns $ */ public class ASCIIHexOutputStream extends FilterOutputStream implements FinishableOutputStream { private final static int MAX_CHARS_PER_LINE = 80; private int characters; private boolean end; private String newline = "\n"; /** * Create an ASCIIHex Output Stream for given stream. * * @param out output stream to use */ public ASCIIHexOutputStream(OutputStream out) { super(out); characters = MAX_CHARS_PER_LINE; end = false; try { newline = System.getProperty("line.separator"); } catch (SecurityException e) { // ignored; } } public void write(int b) throws IOException { String s = Integer.toHexString(b & 0x00FF); switch (s.length()) { case 1: writeChar('0'); writeChar(s.charAt(0)); break; case 2: writeChar(s.charAt(0)); writeChar(s.charAt(1)); break; default: throw new IOException("ASCIIHexOutputStream: byte '" + b + "' was encoded in less than 1 or more than 2 chars"); } } public void finish() throws IOException { if (!end) { end = true; writeChar('>'); writeNewLine(); flush(); if (out instanceof FinishableOutputStream) { ((FinishableOutputStream) out).finish(); } } } public void close() throws IOException { finish(); super.close(); } private void writeChar(int b) throws IOException { if (characters == 0) { characters = MAX_CHARS_PER_LINE; writeNewLine(); } characters--; super.write(b); } private void writeNewLine() throws IOException { // write a newline for (int i=0; i < newline.length(); i++) { super.write(newline.charAt(i)); } } } freehep-io-2.0.2/src/main/java/org/freehep/util/io/CompressableOutputStream.java0000644012010301201030000000402610466735775030656 0ustar mascellanimascellani// Copyright 2003, FreeHEP. package org.freehep.util.io; import java.io.FilterOutputStream; import java.io.IOException; import java.io.OutputStream; import java.util.zip.DeflaterOutputStream; /** * Special stream that can be used to write a header in uncompressed format, and * the rest of the stream in compressed format. This stream is used by SWF, to * compress the tail of the stream. * * @author Mark Donszelmann * @version $Id: CompressableOutputStream.java 8584 2006-08-10 23:06:37Z duns $ */ public class CompressableOutputStream extends FilterOutputStream implements FinishableOutputStream { private boolean compress; private DeflaterOutputStream dos; /** * Creates a Compressable Output Stream from given stream. Initially the * stream does not compress. * * @param out stream to write to */ public CompressableOutputStream(OutputStream out) { super(out); compress = false; } public void write(int b) throws IOException { if (compress) { dos.write(b); } else { out.write(b); } } public void write(byte[] b, int off, int len) throws IOException { for (int i = 0; i < len; i++) { write(b[off + i]); } } public void finish() throws IOException { if (compress) { dos.finish(); } if (out instanceof FinishableOutputStream) { ((FinishableOutputStream) out).finish(); } } public void close() throws IOException { if (compress) { finish(); dos.close(); } else { out.close(); } } /** * Start compressing from the next byte onwards. Flushes what is currently * in the buffer to the underlying stream and start compression from here. * * @throws IOException if write fails */ public void startCompressing() throws IOException { out.flush(); compress = true; dos = new DeflaterOutputStream(out); } }freehep-io-2.0.2/src/main/java/org/freehep/util/io/DummyOutputStream.java0000644012010301201030000000107310466735775027331 0ustar mascellanimascellanipackage org.freehep.util.io; import java.io.IOException; import java.io.OutputStream; /** * Equivalent to writing to /dev/nul * * @author tonyj * @version $Id: DummyOutputStream.java 8584 2006-08-10 23:06:37Z duns $ */ public class DummyOutputStream extends OutputStream { /** * Creates a Dummy output steram. */ public DummyOutputStream() { } public void write(int b) throws IOException { } public void write(byte[] b) throws IOException { } public void write(byte[] b, int off, int len) throws IOException { } } freehep-io-2.0.2/src/main/java/org/freehep/util/io/ASCIIHexInputStream.java0000644012010301201030000000752010466735775027335 0ustar mascellanimascellani// Copyright 2001, FreeHEP. package org.freehep.util.io; import java.io.IOException; import java.io.InputStream; /** * The ASCIIHexOutputStream decodes ASCII Hexadecimal. The exact definition of * ASCII Hex encoding can be found in the PostScript Language Reference (3rd * ed.) chapter 3.13.3. * * IMPORTANT: inherits from InputStream rather than FilterInputStream so that * the correct read(byte[], int, int) method is used. * * @author Mark Donszelmann * @version $Id: ASCIIHexInputStream.java 8584 2006-08-10 23:06:37Z duns $ */ public class ASCIIHexInputStream extends InputStream { private boolean ignoreIllegalChars; private boolean endReached; private int prev; private int lineNo; private InputStream in; /** * Create an ASCIIHex Input Stream from given stream * * @param input input stream to use */ public ASCIIHexInputStream(InputStream input) { this(input, false); } /** * Create an ASCIIHex Input Stream from given stream and have it optionally * ignore illegal characters * * @param input input stream to use * @param ignore ignore illegal characters */ public ASCIIHexInputStream(InputStream input, boolean ignore) { super(); in = input; ignoreIllegalChars = ignore; endReached = false; prev = -1; lineNo = 1; } public int read() throws IOException { if (endReached) return -1; int b0 = readPart(); if (b0 == -1) return -1; int b1 = readPart(); if (b1 == -1) b1 = 0; int d = (b0 << 4 | b1) & 0x00FF; return d; } /** * @return current line number */ public int getLineNo() { return lineNo; } private int readPart() throws IOException, EncodingException { while (true) { int b = in.read(); switch (b) { case -1: endReached = true; if (!ignoreIllegalChars) { throw new EncodingException( "missing '>' at end of ASCII HEX stream"); } return -1; case '>': endReached = true; return -1; case '\r': lineNo++; prev = b; break; case '\n': if (prev != '\r') { lineNo++; } prev = b; break; case ' ': case '\t': case '\f': case 0: // skip whitespace prev = b; break; case '0': return 0; case '1': return 1; case '2': return 2; case '3': return 3; case '4': return 4; case '5': return 5; case '6': return 6; case '7': return 7; case '8': return 8; case '9': return 9; case 'A': case 'a': return 10; case 'B': case 'b': return 11; case 'C': case 'c': return 12; case 'D': case 'd': return 13; case 'E': case 'e': return 14; case 'F': case 'f': return 15; default: if (!ignoreIllegalChars) { throw new EncodingException("Illegal char " + b + " in HexStream"); } prev = b; break; } } } } freehep-io-2.0.2/src/main/java/org/freehep/util/io/StandardFileFilter.java0000644012010301201030000000507010466735775027350 0ustar mascellanimascellani// Copyright 2003, SLAC, Stanford, U.S.A package org.freehep.util.io; import java.io.File; import java.io.FileFilter; import java.util.regex.Matcher; import java.util.regex.Pattern; /** * Implements a standard file filter as is normally used in Unix and DOS. The * template characters are treated literally and are case sensitive with the * following exceptions: *
      *
    • * matches zero or more consecutive characters *
    • ? matches exactly one character *
    • \ causes the next character of the template to be treated literally. Use \\ * for \, \* for * and \? for *. *
    * * The template should specify slashes as a separator character (e.g. Unix * style). * * @author Mark Donszelmann * @version $Id: StandardFileFilter.java 8584 2006-08-10 23:06:37Z duns $ */ public class StandardFileFilter implements FileFilter { private Pattern pattern; /** * Create a standard file filter * * @param template pattern to be used for file filtering */ public StandardFileFilter(String template) { if (template.indexOf("/") < 0) template = "*/" + template; // convert pattern StringBuffer s = new StringBuffer(); for (int i = 0; i < template.length(); i++) { char ch = template.charAt(i); switch (ch) { case '?': s.append("."); break; case '*': s.append(".*"); break; case '\\': s.append("\\"); i++; s.append(template.charAt(i)); break; case '.': s.append("\\."); break; case '^': s.append("\\^"); break; case '+': s.append("\\+"); break; case '$': s.append("\\$"); break; case '{': s.append("\\{"); break; case '(': s.append("\\("); break; case '[': s.append("\\["); break; case '|': s.append("\\|"); break; default: s.append(ch); break; } } pattern = Pattern.compile(s.toString()); } public boolean accept(File pathname) { String name = pathname.getPath().replaceAll("\\" + File.separator, "/"); Matcher matcher = pattern.matcher(name); return matcher.matches(); } } freehep-io-2.0.2/src/main/java/org/freehep/util/io/FlateOutputStream.java0000644012010301201030000000166510466735775027300 0ustar mascellanimascellani// Copyright 2001-2005, FreeHEP. package org.freehep.util.io; import java.io.IOException; import java.io.OutputStream; import java.util.zip.DeflaterOutputStream; /** * The FlateOutputStream uses the Deflate mechanism to compress data. The exact * definition of Deflate encoding can be found in the PostScript Language * Reference (3rd ed.) chapter 3.13.3. * * @author Mark Donszelmann * @version $Id: FlateOutputStream.java 8584 2006-08-10 23:06:37Z duns $ */ public class FlateOutputStream extends DeflaterOutputStream implements FinishableOutputStream { /** * Creates a (In-)Flate output stream. * * @param out stream to write to */ public FlateOutputStream(OutputStream out) { super(out); } public void finish() throws IOException { super.finish(); if (out instanceof FinishableOutputStream) { ((FinishableOutputStream) out).finish(); } } } freehep-io-2.0.2/src/main/java/org/freehep/util/io/TaggedInputStream.java0000644012010301201030000001040110540603130027167 0ustar mascellanimascellani// Copyright 2001-2006, FreeHEP. package org.freehep.util.io; import java.io.IOException; import java.io.InputStream; /** * Class to read Tagged blocks from a Stream. The tagged blocks (Tags) contain a * tagID and a Length, so that known and unknown tags can be read and written * (using the TaggedOutputStream). The stream also allows to read Actions, which * again come with a actionCode and a length. * * A set of recognized Tags and Actions can be added to this stream. A concrete * implementation of this stream should decode/read the TagHeader. All Concrete * tags should be inherited from the Tag class and implement their read methods. * * @author Mark Donszelmann * @author Charles Loomis * @version $Id: TaggedInputStream.java 10195 2006-12-15 20:32:24Z duns $ */ public abstract class TaggedInputStream extends ByteCountInputStream { /** * Set of tags that can be used by this Stream */ protected TagSet tagSet; /** * Set of actions that can be used by this Stream */ protected ActionSet actionSet; /** * Currently read tagHeader, valid during readTag call. */ private TagHeader tagHeader; /** * Creates a Tagged Input Stream * * @param in stream to read from * @param tagSet available tag set * @param actionSet available action set */ public TaggedInputStream(InputStream in, TagSet tagSet, ActionSet actionSet) { this(in, tagSet, actionSet, false); } /** * Creates a Tagged Input Stream * * @param in stream to read from * @param tagSet available tag set * @param actionSet available action set * @param littleEndian true if stream is little endian */ public TaggedInputStream(InputStream in, TagSet tagSet, ActionSet actionSet, boolean littleEndian) { super(in, littleEndian, 8); this.tagSet = tagSet; this.actionSet = actionSet; } /** * Add tag to tagset * * @param tag new tag */ public void addTag(Tag tag) { tagSet.addTag(tag); } /** * Decodes and returns the TagHeader, which includes a TagID and a length. * * @return Decoded TagHeader * @throws IOException if read fails */ protected abstract TagHeader readTagHeader() throws IOException; /** * Read a tag. * @return read tag * @throws IOException if read fails */ public Tag readTag() throws IOException { tagHeader = readTagHeader(); if (tagHeader == null) return null; int size = (int) tagHeader.getLength(); // Look up the proper tag. Tag tag = tagSet.get(tagHeader.getTag()); // set max tag length and read tag pushBuffer(size); tag = tag.read(tagHeader.getTag(), this, size); byte[] rest = popBuffer(); // read non-read part of tag if (rest != null) { throw new IncompleteTagException(tag, rest); } return tag; } /** * Returns the currently valid TagHeader. Can be called durring the tag.read() method. */ public TagHeader getTagHeader() { return tagHeader; } /** * Add action to action set. * * @param action new action */ public void addAction(Action action) { actionSet.addAction(action); } /** * Decodes and returns the ActionHeader, which includes an actionCode and a * length. * * @return decoded ActionHeader * @throws IOException if read fails */ protected abstract ActionHeader readActionHeader() throws IOException; /** * Reads action. * * @return read action * @throws IOException if read fails */ public Action readAction() throws IOException { ActionHeader header = readActionHeader(); if (header == null) return null; int size = (int) header.getLength(); // Look up the proper action. Action action = actionSet.get(header.getAction()); pushBuffer(size); action = action.read(header.getAction(), this, size); byte[] rest = popBuffer(); if (rest != null) { throw new IncompleteActionException(action, rest); } return action; } } freehep-io-2.0.2/src/main/java/org/freehep/util/io/NoCloseOutputStream.java0000644012010301201030000000216010466735775027576 0ustar mascellanimascellani// Copyright 2001, FreeHEP. package org.freehep.util.io; import java.io.BufferedOutputStream; import java.io.IOException; import java.io.OutputStream; /** * The NoCloseOutputStream ignores the close so that one can keep writing to the * underlying stream. * * @author Mark Donszelmann * @version $Id: NoCloseOutputStream.java 8584 2006-08-10 23:06:37Z duns $ */ public class NoCloseOutputStream extends BufferedOutputStream { /** * Creates a No Close output stream. * * @param stream stream to write to */ public NoCloseOutputStream(OutputStream stream) { super(stream); } /** * Creates a No Close output stream. * * @param stream stream to write to * @param size buffer size */ public NoCloseOutputStream(OutputStream stream, int size) { super(stream, size); } public void close() throws IOException { flush(); } /** * Closes the stream (the close method is ignored). * * @throws IOException if the close fails */ public void realClose() throws IOException { super.close(); } } freehep-io-2.0.2/src/main/java/org/freehep/util/io/PromptInputStream.java0000644012010301201030000000263710466735775027325 0ustar mascellanimascellani// Copyright 2002, FreeHEP. package org.freehep.util.io; import java.io.IOException; import java.io.InputStream; /** * The PromptInputStream reads from an inputstream until it reads any prompt for * which a listener is added. The listener is informed that the prompt is found. * The route which contains the prompt is supplied as a parameter to the * listener. Returning from the prompt listener without reading the route to its * end will allow the main stream to read it. * * The implementation of this class is based on the RoutedInputStream. * * @author Mark Donszelmann * @version $Id: PromptInputStream.java 8584 2006-08-10 23:06:37Z duns $ */ public class PromptInputStream extends RoutedInputStream { /** * Craete a Prompt input stream. * * @param input stream to read */ public PromptInputStream(InputStream input) { super(input); } /** * Add a prompt listener for given prompt. * * @param prompt prompt to listen for * @param listener listener to be informed */ public void addPromptListener(String prompt, PromptListener listener) { final PromptListener promptListener = listener; addRoute(prompt, prompt, new RouteListener() { public void routeFound(RoutedInputStream.Route input) throws IOException { promptListener.promptFound(input); } }); } } freehep-io-2.0.2/src/main/java/org/freehep/util/io/ByteCountOutputStream.java0000644012010301201030000001411110466735775030147 0ustar mascellanimascellani// Copyright 2001, FreeHEP. package org.freehep.util.io; import java.io.IOException; import java.io.OutputStream; import java.util.LinkedList; import java.util.List; /** * Allows to write to some internal buffer and keep count of any set of stacked * buffers written. When a pushBuffer is called, a new buffer is created. When a * popBuffer is called, the number of bytes written to the popped buffer is * returned. From this moment on one is writing again to the underlying * buffer/outputstream. A header can be written and the header can be written. * By calling append(), the previous buffer will be appended to the underlying * one. This way one can write into a buffer, retrieve its length, create some * header bytes and insert those in front of the just written buffer. * * @author Mark Donszelmann * @author Ian Graham - added popBufferBytes() for use by CGMOutputStream * @version $Id: ByteCountOutputStream.java 8584 2006-08-10 23:06:37Z duns $ */ public class ByteCountOutputStream extends ByteOrderOutputStream { private int currentBuffer; private List bufferList; /** * Create a Byte Count output stream from given stream * * @param out stream to write to * @param littleEndian true if stream should be little endian */ public ByteCountOutputStream(OutputStream out, boolean littleEndian) { super(out, littleEndian); currentBuffer = -1; bufferList = new LinkedList(); } public void write(int b) throws IOException { // System.out.println(Integer.toHexString(b)+" "+index); // original stream if (currentBuffer == -1) { super.write(b); return; } Buffer buffer = (Buffer) bufferList.get(currentBuffer); buffer.add((byte) b); } /** * Pushes the buffer and strat writing to a new one. * * @throws IOException if the write fails */ public void pushBuffer() throws IOException { // call append just to make sure we did not leave anything in the // buffer... append(); bufferList.add(new Buffer()); currentBuffer++; } /** * returns the number of bytes written since the last pushBuffer call. It * also puts the write pointer at the start of the buffer, to be able to * "insert" a header. If no buffer was ever pushed, or the last one has been * popped -1 is returned. * * @return number of bytes written or -1 * @throws IOException if the write fails */ public int popBuffer() throws IOException { if (currentBuffer >= 0) { append(); int len = getBufferLength(); currentBuffer--; return len; } return -1; } /** * Similar to pop buffer, but returns the actual byte[] buffer and then * removes it from the bufferList so that subsequent appends will have no * action. When using this method, the caller is responsible for writing all * buffered data as desired. The byte[] array will usually be larger than * the actual content, so to determine the length of the actual data, you * must call getBufferLength() before invoking this method. * * @return byte array of bytes that need to be written * @throws IOException if write fails */ public byte[] popBufferBytes() throws IOException { int len = popBuffer(); if (len >= 0) { Buffer buffer = (Buffer) bufferList.remove(currentBuffer + 1); return buffer.getBytes(); } else { return new byte[0]; } } /** * @return valid number of bytes in the buffer */ public int getBufferLength() { return (currentBuffer >= 0) ? ((Buffer) bufferList.get(currentBuffer)) .getLength() : -1; } /** * @return total number of bytes written */ public int getLength() { int length = 0; for (int i = 0; i < bufferList.size(); i++) { length += ((Buffer) bufferList.get(i)).getLength(); } return (currentBuffer >= 0) ? length : -1; } /** * Inserts the bytes written as header and puts the write pointer at the end * of the stream. * * @throws IOException if write fails */ public void append() throws IOException { // append the top-level buffer super.byteAlign(); if (currentBuffer + 1 >= bufferList.size()) { // there is no buffer to append return; } Buffer append = (Buffer) bufferList.get(currentBuffer + 1); if (append.getLength() > 0) { if (currentBuffer >= 0) { ((Buffer) bufferList.get(currentBuffer)).add(append); } else { super.write(append.getBytes(), 0, append.getLength()); } } bufferList.remove(currentBuffer + 1); } /** * closes the stream, inserting any non-written header. */ public void close() throws IOException { append(); super.close(); } static class Buffer { byte[] buffer; int len; Buffer() { len = 0; buffer = new byte[256]; // 8192 } void add(byte b) { if (len + 1 > buffer.length) { byte newBuffer[] = new byte[buffer.length << 1]; System.arraycopy(buffer, 0, newBuffer, 0, len); buffer = newBuffer; } buffer[len] = b; len++; } void add(Buffer append) { int appendLength = append.getLength(); int needed = len + appendLength; if (needed > buffer.length) { byte[] newBuffer = new byte[needed]; System.arraycopy(buffer, 0, newBuffer, 0, len); buffer = newBuffer; } System.arraycopy(append.getBytes(), 0, buffer, len, appendLength); len += appendLength; } int getLength() { return len; } byte[] getBytes() { return buffer; } } } freehep-io-2.0.2/src/main/java/org/freehep/util/io/EEXECConstants.java0000644012010301201030000000126010466735775026365 0ustar mascellanimascellani// Copyright 2001 freehep package org.freehep.util.io; /** * Constants for the EEXEC encoding (used by Type1 Fonts). * * @author Simon Fischer * @version $Id: EEXECConstants.java 8584 2006-08-10 23:06:37Z duns $ */ public interface EEXECConstants { /** * Constant for EEXEC */ public static final char N = 4; /** * Constant for EEXEC */ public static final char C1 = 52845; /** * Constant for EEXEC */ public static final char C2 = 22719; /** * Constant for EEXEC */ public static final char EEXEC_R = 55665; /** * Constant for EEXEC */ public static final char CHARSTRING_R = 4330; } freehep-io-2.0.2/src/main/java/org/freehep/util/io/UndefinedTag.java0000644012010301201030000000252110466735775026175 0ustar mascellanimascellani// Copyright 2001, FreeHEP. package org.freehep.util.io; import java.io.IOException; /** * Tag to hold the data for an Undefined Tag for the TaggedIn/OutputStreams. The * data is read in and written as the number of bytes is known. * * @author Mark Donszelmann * @author Charles Loomis * @version $Id: UndefinedTag.java 8584 2006-08-10 23:06:37Z duns $ */ public class UndefinedTag extends Tag { private int[] bytes; /** * Create Undefined Tag with 0 length. */ public UndefinedTag() { this(DEFAULT_TAG, new int[0]); } /** * Create Undefined Tag. * * @param tagID undefined tagID * @param bytes bytes that follow the undefined tag */ public UndefinedTag(int tagID, int[] bytes) { super(tagID, 3); this.bytes = bytes; } public int getTagType() { return 0; } public Tag read(int tagID, TaggedInputStream input, int len) throws IOException { int[] bytes = input.readUnsignedByte(len); UndefinedTag tag = new UndefinedTag(tagID, bytes); return tag; } public void write(int tagID, TaggedOutputStream output) throws IOException { output.writeUnsignedByte(bytes); } public String toString() { return ("UNDEFINED TAG: " + getTag() + " length: " + bytes.length); } } freehep-io-2.0.2/src/main/java/org/freehep/util/io/BitOutputStream.java0000644012010301201030000001114410466735775026754 0ustar mascellanimascellani// Copyright 2001-2003, FreeHEP. package org.freehep.util.io; import java.io.IOException; import java.io.OutputStream; /** * Class to write bits to a Stream, allowing for byte synchronization. Signed, * Unsigned, Booleans and Floats can be written. * * @author Mark Donszelmann * @author Charles Loomis * @version $Id: BitOutputStream.java 8584 2006-08-10 23:06:37Z duns $ */ public class BitOutputStream extends CompressableOutputStream implements FinishableOutputStream { private int bits; private int bitPos; /** * Create a Bit output stream from given stream * * @param out stream to write to */ public BitOutputStream(OutputStream out) { super(out); bits = 0; bitPos = 0; } public void write(int b) throws IOException { // System.out.println(Integer.toHexString(b)); super.write(b); } public void finish() throws IOException { flushByte(); if (out instanceof FinishableOutputStream) { ((FinishableOutputStream) out).finish(); } } public void close() throws IOException { finish(); super.close(); } /** * A utility method to flush the next byte * * @throws IOException if write fails */ protected void flushByte() throws IOException { if (bitPos == 0) return; write(bits); bits = 0; bitPos = 0; } /** * A utility to force the next write to be byte-aligned. * * @throws IOException if write fails */ public void byteAlign() throws IOException { flushByte(); } /** * Write a bit to the output stream. A 1-bit is true; a 0-bit is false. * * @param bit value to write * @throws IOException if write fails */ public void writeBitFlag(boolean bit) throws IOException { writeUBits((bit) ? 1 : 0, 1); } /** * Write a signed value of n-bits to the output stream. * * @param value value to write * @param n number of bits to write * @throws IOException if write fails */ public void writeSBits(long value, int n) throws IOException { long tmp = value & 0x7FFFFFFF; if (value < 0) { tmp |= (1L << (n - 1)); } writeUBits(tmp, n); } /** * Write a float value of n-bits to the stream. * * @param value value to write * @param n number of bits to write * @throws IOException if write fails */ public void writeFBits(float value, int n) throws IOException { if (n == 0) return; long tmp = (long) (value * 0x10000); writeSBits(tmp, n); } /** * Write an unsigned value of n-bits to the output stream. * * @param value value to write * @param n number of bits to write * @throws IOException if write fails */ public void writeUBits(long value, int n) throws IOException { if (n == 0) return; if (bitPos == 0) bitPos = 8; int bitNum = n; while (bitNum > 0) { while ((bitPos > 0) && (bitNum > 0)) { long or = (value & (1L << (bitNum - 1))); int shift = bitPos - bitNum; if (shift < 0) { or >>= -shift; } else { or <<= shift; } bits |= or; bitNum--; bitPos--; } if (bitPos == 0) { write(bits); bits = 0; if (bitNum > 0) bitPos = 8; } } } /** * calculates the minumum number of bits necessary to write number. * * @param number number * @return minimum number of bits to store number */ public static int minBits(float number) { return minBits((int) number, true) + 16; } /** * @param number value to calculate bits for * @return number of bits needed to store value */ public static int minBits(long number) { return minBits(number, number < 0); } /** * @param number value to calculate bits for * @param signed true if the value if signed (< 0) * @return number of bits needed to store value */ public static int minBits(long number, boolean signed) { number = Math.abs(number); long x = 1; int i; for (i = 1; i <= 64; i++) { x <<= 1; if (x > number) break; } return i + ((signed) ? 1 : 0); } } freehep-io-2.0.2/src/main/java/org/freehep/util/io/RunLength.java0000644012010301201030000000062110466735775025545 0ustar mascellanimascellani// Copyright 2001, FreeHEP. package org.freehep.util.io; /** * Constants for the RunLength encoding. * * @author Mark Donszelmann * @version $Id: RunLength.java 8584 2006-08-10 23:06:37Z duns $ */ public interface RunLength { /** * Maximum run length */ public static final int LENGTH = 128; /** * End of data code */ public static final int EOD = 128; } freehep-io-2.0.2/src/main/java/org/freehep/util/io/package.html0000644012010301201030000000032110470537377025243 0ustar mascellanimascellani

    Set of Streams, Readers, Writers, Encoders and Decoders.

    @Status Stable.

    freehep-io-2.0.2/src/main/java/org/freehep/util/io/DecompressableInputStream.java0000644012010301201030000000260710466735775030771 0ustar mascellanimascellani// Copyright 2001, FreeHEP. package org.freehep.util.io; import java.io.IOException; import java.io.InputStream; import java.util.zip.InflaterInputStream; /** * Special stream that can be used to read uncompressed first and compressed * from a certain byte. * * IMPORTANT: inherits from InputStream rather than FilterInputStream so that * the correct read(byte[], int, int) method is used. * * @author Mark Donszelmann * @version $Id: DecompressableInputStream.java 8584 2006-08-10 23:06:37Z duns $ */ public class DecompressableInputStream extends InputStream { private boolean decompress; private InflaterInputStream iis; private InputStream in; /** * Creates a Decompressable input stream from given stream. * * @param input stream to read from. */ public DecompressableInputStream(InputStream input) { super(); in = input; decompress = false; } public int read() throws IOException { return (decompress) ? iis.read() : in.read(); } public long skip(long n) throws IOException { return (decompress) ? iis.skip(n) : in.skip(n); } /** * Start reading in compressed mode from the next byte. * * @throws IOException if read fails. */ public void startDecompressing() throws IOException { decompress = true; iis = new InflaterInputStream(in); } } freehep-io-2.0.2/src/main/java/org/freehep/util/io/Tag.java0000644012010301201030000000423610466735775024360 0ustar mascellanimascellani// Copyright 2001, FreeHEP. package org.freehep.util.io; import java.io.IOException; /** * Generic Tag to be used by TaggedIn/OutputStreams. The tag contains an ID, * name and a version. Concrete subclasses should implement the IO Read and * Write methods. * * @author Mark Donszelmann * @author Charles Loomis * @version $Id: Tag.java 8584 2006-08-10 23:06:37Z duns $ */ public abstract class Tag { private int tagID; private String name; private int version; /** * This is the tagID for the default tag handler. */ final public static int DEFAULT_TAG = -1; protected Tag(int tagID, int version) { this.tagID = tagID; this.version = version; this.name = null; } /** * Get the tag number. * * @return tagID */ public int getTag() { return tagID; } /** * Get the version number. * * @return version number */ public int getVersion() { return version; } /** * Get the tag name. * * @return tag name */ public String getName() { if (name == null) { name = getClass().getName(); int dot = name.lastIndexOf("."); name = (dot >= 0) ? name.substring(dot + 1) : name; } return name; } /** * This returns the type of block * * @return tag type */ public int getTagType() { return 0; } /** * This reads the information from the given input and returns a new Tag * * @param tagID id of the tag to read * @param input stream to read from * @param len length to read * @return read Tag * @throws IOException if read fails */ public abstract Tag read(int tagID, TaggedInputStream input, int len) throws IOException; /** * This writes the information to the given output * * @param tagID id of tag to write * @param output stream to write to * @throws IOException if write fails */ public abstract void write(int tagID, TaggedOutputStream output) throws IOException; public abstract String toString(); } freehep-io-2.0.2/src/main/java/org/freehep/util/io/FinishableOutputStream.java0000644012010301201030000000120110466735775030273 0ustar mascellanimascellani// Copyright 2001, FreeHEP. package org.freehep.util.io; import java.io.IOException; /** * The FinishableOutputStream allows a generic way of calling finish on an * output stream without closing it. * * @author Mark Donszelmann * @version $Id: FinishableOutputStream.java 8584 2006-08-10 23:06:37Z duns $ */ public interface FinishableOutputStream { /** * Finishes the current outputstream (compresses, flushes, caluclates CRC) * and writes whatever is left in the buffers, but does not close the * stream. * * @throws IOException if write fails */ public void finish() throws IOException; } freehep-io-2.0.2/src/main/java/org/freehep/util/io/TagHeader.java0000644012010301201030000000222110466735775025461 0ustar mascellanimascellani// Copyright 2001, FreeHEP. package org.freehep.util.io; /** * Keeps the tagID and Length of a specific tag. To be used in the InputStream * to return the tagID and Length, and in the OutputStream to write them. * * @author Mark Donszelmann * @author Charles Loomis * @version $Id: TagHeader.java 8584 2006-08-10 23:06:37Z duns $ */ public class TagHeader { int tagID; long length; /** * Creates a tag header * * @param tagID id of tag * @param length length of the tag, including the header */ public TagHeader(int tagID, long length) { this.tagID = tagID; this.length = length; } /** * Sets the tag id * * @param tagID new tag id */ public void setTag(int tagID) { this.tagID = tagID; } /** * @return tagID */ public int getTag() { return tagID; } /** * Sets the length of the tag * * @param length new length */ public void setLength(long length) { this.length = length; } /** * @return tag length */ public long getLength() { return length; } } freehep-io-2.0.2/src/main/java/org/freehep/util/io/BitInputStream.java0000644012010301201030000001033210466735775026551 0ustar mascellanimascellani// Copyright 2001, FreeHEP. package org.freehep.util.io; import java.io.EOFException; import java.io.IOException; import java.io.InputStream; /** * Class to read bits from a Stream, allowing for byte synchronization. Signed, * Unsigned, Booleans and Floats can be read. * * @author Mark Donszelmann * @author Charles Loomis * @version $Id: BitInputStream.java 8584 2006-08-10 23:06:37Z duns $ */ public class BitInputStream extends DecompressableInputStream { final protected static int MASK_SIZE = 8; final protected static int ZERO = 0; final protected static int ONES = ~0; final protected static int[] BIT_MASK = new int[MASK_SIZE]; final protected static int[] FIELD_MASK = new int[MASK_SIZE]; // Generate the needed masks for various bit fields and for // individual bits. static { int tempBit = 1; int tempField = 1; for (int i = 0; i < MASK_SIZE; i++) { // Set the masks. BIT_MASK[i] = tempBit; FIELD_MASK[i] = tempField; // Update the temporary values. tempBit <<= 1; tempField <<= 1; tempField++; } } /** * This is a prefetched byte used to construct signed and unsigned numbers * with an arbitrary number of significant bits. */ private int bits; /** * The number of valid bits remaining in the bits field. */ private int validBits; /** * Create a Bit input stream from viven input * * @param in stream to read from */ public BitInputStream(InputStream in) { super(in); bits = 0; validBits = 0; } /** * A utility method to fetch the next byte in preparation for constructing a * bit field. There is no protection for this method; ensure that it is only * called when a byte must be fetched. * * @throws IOException if read fails */ protected void fetchByte() throws IOException { bits = read(); if (bits < 0) throw new EOFException(); validBits = MASK_SIZE; } /** * A utility to force the next read to be byte-aligned. */ public void byteAlign() { validBits = 0; } /** * Read a bit from the input stream and interpret this as a boolean value. A * 1-bit is true; a 0-bit is false. * * @return true if read bit was 1 * @throws IOException if read fails */ public boolean readBitFlag() throws IOException { if (validBits == 0) fetchByte(); return ((bits & BIT_MASK[--validBits]) != 0); } /** * Read a signed value of n-bits from the input stream. * * @param n number of bits to read * @return value made up of read bits * @throws IOException if read fails */ public long readSBits(int n) throws IOException { if (n == 0) return 0; int value = (readBitFlag()) ? ONES : ZERO; value <<= (--n); return (value | readUBits(n)); } /** * Read a float value of n-bits from the stream. * * @param n number of bits to read * @return value made up of read bits * @throws IOException if read fails */ public float readFBits(int n) throws IOException { if (n == 0) return 0.0f; return ((float) readSBits(n)) / 0x1000; } /** * Read an unsigned value of n-bits from the input stream. * * @param n number of bits to read * @return value made up of read bits * @throws IOException if read fails */ public long readUBits(int n) throws IOException { long value = ZERO; while (n > 0) { // Take the needed bits or the number which are valid // whichever is less. if (validBits == 0) fetchByte(); int nbits = (n > validBits) ? validBits : n; // Take the bits and update the counters. int temp = ((bits >> (validBits - nbits)) & FIELD_MASK[nbits - 1]); validBits -= nbits; n -= nbits; // Shift the value up to accomodate new bits. value <<= nbits; value |= temp; } return value; } } freehep-io-2.0.2/src/main/java/org/freehep/util/io/ReaderInputStream.java0000644012010301201030000000374310466735775027245 0ustar mascellanimascellani// Copyright 2003, FreeHEP. package org.freehep.util.io; import java.io.IOException; import java.io.InputStream; import java.io.Reader; /** * The ReaderInputStream makes a Reader look like an InputStream so one can use * any of the filters. This is not without danger of loosing some data. * * IMPORTANT: inherits from InputStream rather than FilterInputStream so that * the correct read(byte[], int, int) method is used. * * @author Mark Donszelmann * @version $Id: ReaderInputStream.java 8584 2006-08-10 23:06:37Z duns $ */ public class ReaderInputStream extends InputStream { private Reader reader; /** * Creates an InputStream from given Reader. * * @param reader reader to read from. */ public ReaderInputStream(Reader reader) { this.reader = reader; } // Note: here we may loose Unicode data. public int read() throws IOException { return reader.read() & 0xFF; } // Note: here we may loose Unicode data. public int read(byte[] b) throws IOException { return read(b, 0, b.length); } // Note: here we may loose Unicode data. public int read(byte[] b, int off, int len) throws IOException { char c[] = new char[len]; int result = reader.read(c, 0, len); for (int i = 0; i < len; i++) { b[off + i] = (byte) (c[i] & 0xFF); } return result; } public int available() throws IOException { return 0; } public void close() throws IOException { reader.close(); } public void mark(int readAheadLimit) { // Note: IOException ignored try { reader.mark(readAheadLimit); } catch (IOException ioe) { // ignored } } public boolean markSupported() { return reader.markSupported(); } public void reset() throws IOException { reader.reset(); } public long skip(long n) throws IOException { return reader.skip(n); } } freehep-io-2.0.2/src/main/java/org/freehep/util/io/ASCII85.java0000644012010301201030000000116510466735775024650 0ustar mascellanimascellani// Copyright 2001, FreeHEP. package org.freehep.util.io; /** * Constants for the ASCII85 encoding. * * @author Mark Donszelmann * @version $Id: ASCII85.java 8584 2006-08-10 23:06:37Z duns $ */ public interface ASCII85 { /** * Maxmimum line length for ASCII85 */ public final static int MAX_CHARS_PER_LINE = 80; /** * 85^1 */ public static long a85p1 = 85; /** * 85^2 */ public static long a85p2 = a85p1 * a85p1; /** * 85^3 */ public static long a85p3 = a85p2 * a85p1; /** * 85^4 */ public static long a85p4 = a85p3 * a85p1; } freehep-io-2.0.2/src/main/java/org/freehep/util/io/ConditionalInputStream.java0000644012010301201030000001356210466735775030306 0ustar mascellanimascellani// Copyright 2001, FreeHEP. package org.freehep.util.io; import java.io.IOException; import java.io.InputStream; import java.util.Properties; /** * The ConditionalInputStream reads a stream and filters certain parts depending * of properties and statements in the input. *

    * The following statements, all start with the * * &at;-sign, are allowed: * *

      *
    • @ifdef property, reads everything up to the next * @statement if the property is defined. *
    • @ifndef property, reads everything up to the next * @statement if the property is not defined. *
    • @else, corresponding else statement *
    • @endif, corresponging endif statement *
    * * The * &at;-sign itself must be escaped by a backslash, if used in the text followed by * any of the keywords described above and no action should be taken. * *

    * IMPORTANT: inherits from InputStream rather than FilterInputStream so that * the correct read(byte[], int, int) method is used. * * @author Mark Donszelmann * @version $Id: ConditionalInputStream.java 8584 2006-08-10 23:06:37Z duns $ */ public class ConditionalInputStream extends InputStream { private int[] buffer = new int[4096]; private int index; private int len; private InputStream in; private Properties defines; private int nesting; private boolean[] ok = new boolean[50]; private boolean escape; /** * Creates a Conditional Input Stream from given stream. * * @param input stream to read from * @param defines set of properties to be used in ifdefs */ public ConditionalInputStream(InputStream input, Properties defines) { super(); in = input; this.defines = defines; nesting = 0; escape = false; index = 0; len = 0; } public int read() throws IOException { int b; int n; // read from buffer if possible if (index < len) { b = buffer[index]; index++; } else { b = in.read(); } // return if End Of Stream if (b < 0) return -1; // escape \@-signs if (b == '\\') { n = in.read(); if (n == '@') { b = ' '; escape = true; } buffer[0] = n; index = 0; len = 1; } // check on @ sign if (b == '@') { if (escape) { escape = false; } else { // read keyword (ifdef, ifndef, else, endif index = 0; StringBuffer s = new StringBuffer(); n = in.read(); while ((n >= 0) && !Character.isWhitespace((char) n)) { s.append((char) n); buffer[index] = n; n = in.read(); index++; } buffer[index] = n; index++; b = ' '; // check on keyword String keyword = s.toString(); if (keyword.equals("ifdef") || keyword.equals("ifndef")) { // skip whitespace and read property s = new StringBuffer(); n = in.read(); while ((n >= 0) && Character.isWhitespace((char) n)) { buffer[index] = n; n = in.read(); index++; } while ((n >= 0) && !Character.isWhitespace((char) n)) { s.append((char) n); buffer[index] = n; n = in.read(); index++; } buffer[index] = n; index++; // check on property String property = s.toString(); if (defines.getProperty(property) != null) { ok[nesting] = (nesting > 0 ? ok[nesting - 1] : true) && keyword.equals("ifdef"); } else { ok[nesting] = (nesting > 0 ? ok[nesting - 1] : true) && keyword.equals("ifndef"); } nesting++; replaceBufferWithWhitespace(index); } else if (keyword.equals("else")) { // FIXME one could have multiple elses without endifs... // calculate inclusion based on ifdef nesting if (nesting <= 0) throw new RuntimeException( "@else without corresponding @ifdef"); ok[nesting - 1] = (nesting > 1 ? ok[nesting - 2] : true) && !ok[nesting - 1]; replaceBufferWithWhitespace(index); } else if (keyword.equals("endif")) { // calculate inclusion based on ifdef nesting if (nesting <= 0) throw new RuntimeException( "@endif without corresponding @ifdef"); nesting--; replaceBufferWithWhitespace(index); } else { // not an known @ b = '@'; } len = index; index = 0; } } if ((nesting > 0) && !ok[nesting - 1]) { if (!Character.isWhitespace((char) b)) b = ' '; } return b & 0x00FF; } private void replaceBufferWithWhitespace(int size) { for (int i = 0; i < size; i++) { if (!Character.isWhitespace((char) buffer[i])) { buffer[i] = ' '; } } } } freehep-io-2.0.2/src/main/java/org/freehep/util/io/NoCloseInputStream.java0000644012010301201030000000212410466735775027375 0ustar mascellanimascellani// Copyright 2001, FreeHEP. package org.freehep.util.io; import java.io.BufferedInputStream; import java.io.IOException; import java.io.InputStream; /** * The NoCloseInputStream ignores the close so that one can keep reading from * the underlying stream. * * @author Mark Donszelmann * @version $Id: NoCloseInputStream.java 8584 2006-08-10 23:06:37Z duns $ */ public class NoCloseInputStream extends BufferedInputStream { /** * Creates a No Close Input Stream. * * @param stream stream to read from */ public NoCloseInputStream(InputStream stream) { super(stream); } /** * Creates a No Close Input Stream. * * @param stream stream to read from * @param size buffer size */ public NoCloseInputStream(InputStream stream, int size) { super(stream, size); } public void close() throws IOException { } /** * Close this stream (the normal close is ignored). * * @throws IOException if close fails */ public void realClose() throws IOException { super.close(); } } freehep-io-2.0.2/src/main/java/org/freehep/util/io/ByteOrderOutputStream.java0000644012010301201030000002252610466735775030143 0ustar mascellanimascellani// Copyright 2001-2005, FreeHEP. package org.freehep.util.io; import java.io.DataOutput; import java.io.IOException; import java.io.OutputStream; import java.io.UTFDataFormatException; /** * Class to write bytes and pairs of bytes in both little and big endian order. * * @author Mark Donszelmann * @author Charles Loomis * @version $Id: ByteOrderOutputStream.java 8584 2006-08-10 23:06:37Z duns $ */ public class ByteOrderOutputStream extends BitOutputStream implements DataOutput { protected boolean little; protected int written; /** * Create a (Big Endian) Byte Order output stream from given stream * * @param out stream to write to */ public ByteOrderOutputStream(OutputStream out) { this(out, false); } /** * Create a Byte Order output stream from the given stream * * @param out stream to write to * @param littleEndian true if stream should be little endian */ public ByteOrderOutputStream(OutputStream out, boolean littleEndian) { super(out); little = littleEndian; written = 0; } /** * @return number of written bytes * @throws IOException if write fails FIXME, should this throw an exception ? */ public int size() throws IOException { return written; } public synchronized void write(int b) throws IOException { super.write(b); written++; } public void writeBoolean(boolean b) throws IOException { if (b) { write(1); } else { write(0); } } public void writeChar(int c) throws IOException { if (little) { write(c & 0xFF); write((c >>> 8) & 0xFF); } else { write((c >>> 8) & 0xFF); write(c & 0xFF); } } /** * Write a signed byte. */ public void writeByte(int b) throws IOException { byteAlign(); write(b); } /** * Writes array of bytes * * @param bytes byte array to be written * @throws IOException if write fails */ public void writeByte(byte[] bytes) throws IOException { byteAlign(); for (int i = 0; i < bytes.length; i++) { write(bytes[i]); } } /** * Write an unsigned byte. * * @param ub byte to write * @throws IOException if write fails */ public void writeUnsignedByte(int ub) throws IOException { byteAlign(); write(ub); } /** * Write an array of unsigned bytes. * * @param bytes int array to write as bytes * @throws IOException if write fails */ public void writeUnsignedByte(int[] bytes) throws IOException { byteAlign(); for (int i = 0; i < bytes.length; i++) { write(bytes[i]); } } /** * Write a signed short. */ public void writeShort(int s) throws IOException { byteAlign(); if (little) { write(s & 0xFF); write((s >>> 8) & 0xFF); } else { write((s >>> 8) & 0xFF); write(s & 0xFF); } } /** * Write an array of shorts. * * @param shorts short array to write * @throws IOException if write fails */ public void writeShort(short[] shorts) throws IOException { for (int i = 0; i < shorts.length; i++) { writeShort(shorts[i]); } } /** * Write an unsigned short. * * @param s int to write as unsigned short * @throws IOException if write fails */ public void writeUnsignedShort(int s) throws IOException { byteAlign(); if (little) { write(s & 0xFF); write((s >>> 8) & 0xFF); } else { write((s >>> 8) & 0xFF); write(s & 0xFF); } } /** * Write an array of unsigned shorts. * * @param shorts int array to write as unsigned shorts * @throws IOException if write fails */ public void writeUnsignedShort(int[] shorts) throws IOException { for (int i = 0; i < shorts.length; i++) { writeUnsignedShort(shorts[i]); } } /** * Write a signed integer. */ public void writeInt(int i) throws IOException { if (little) { write(i & 0xFF); write((i >>> 8) & 0xFF); write((i >>> 16) & 0xFF); write((i >>> 24) & 0xFF); } else { write((i >>> 24) & 0xFF); write((i >>> 16) & 0xFF); write((i >>> 8) & 0xFF); write(i & 0xFF); } } /** * Write an array of ints * * @param ints int array to write * @throws IOException if write fails */ public void writeInt(int[] ints) throws IOException { for (int i = 0; i < ints.length; i++) { writeInt(ints[i]); } } /** * Write an unsigned integer. * * @param i long to write as unsigned int * @throws IOException if write fails */ public void writeUnsignedInt(long i) throws IOException { if (little) { write((int) (i & 0xFF)); write((int) ((i >>> 8) & 0xFF)); write((int) ((i >>> 16) & 0xFF)); write((int) ((i >>> 24) & 0xFF)); } else { write((int) ((i >>> 24) & 0xFF)); write((int) ((i >>> 16) & 0xFF)); write((int) ((i >>> 8) & 0xFF)); write((int) (i & 0xFF)); } } /** * Write an array of unsigned ints * * @param ints long array to write as unsigned ints * @throws IOException if write fails */ public void writeUnsignedInt(long[] ints) throws IOException { for (int i = 0; i < ints.length; i++) { writeUnsignedInt(ints[i]); } } public void writeLong(long l) throws IOException { if (little) { write((int) (l & 0xFF)); write((int) ((l >>> 8) & 0xFF)); write((int) ((l >>> 16) & 0xFF)); write((int) ((l >>> 24) & 0xFF)); write((int) ((l >>> 32) & 0xFF)); write((int) ((l >>> 40) & 0xFF)); write((int) ((l >>> 48) & 0xFF)); write((int) ((l >>> 56) & 0xFF)); } else { write((int) ((l >>> 56) & 0xFF)); write((int) ((l >>> 48) & 0xFF)); write((int) ((l >>> 40) & 0xFF)); write((int) ((l >>> 32) & 0xFF)); write((int) ((l >>> 24) & 0xFF)); write((int) ((l >>> 16) & 0xFF)); write((int) ((l >>> 8) & 0xFF)); write((int) (l & 0xFF)); } } public void writeFloat(float f) throws IOException { writeInt(Float.floatToIntBits(f)); } public void writeDouble(double d) throws IOException { writeLong(Double.doubleToLongBits(d)); } public void writeBytes(String s) throws IOException { for (int i = 0; i < s.length(); i++) { writeByte(s.charAt(i)); } } public void writeChars(String s) throws IOException { for (int i = 0; i < s.length(); i++) { writeChar(s.charAt(i)); } } /** * Write a string (UTF) * * @param s string to write * @throws IOException if write fails */ public void writeString(String s) throws IOException { writeUTF(s); } public void writeUTF(String s) throws IOException { writeUTF(s, this); } /** * Write an ascii-z (0 terminated c-string). * * @param s string to write * @throws IOException if write fails */ public void writeAsciiZString(String s) throws IOException { writeBytes(s); writeByte(0); } /** * Write a UTF string to the data output stream. This method should have * been in DataOutputStream, but is not visible. * * @param s string to write * @param dos stream to write to * @throws IOException if write fails */ // public static void writeUTF(String s, DataOutput dos) throws IOException { int strlen = s.length(); int utflen = 0; char[] charr = new char[strlen]; int c, count = 0; s.getChars(0, strlen, charr, 0); for (int i = 0; i < strlen; i++) { c = charr[i]; if ((c >= 0x0001) && (c <= 0x007F)) { utflen++; } else if (c > 0x07FF) { utflen += 3; } else { utflen += 2; } } if (utflen > 65535) throw new UTFDataFormatException(); byte[] bytearr = new byte[utflen + 2]; bytearr[count++] = (byte) ((utflen >>> 8) & 0xFF); bytearr[count++] = (byte) ((utflen >>> 0) & 0xFF); for (int i = 0; i < strlen; i++) { c = charr[i]; if ((c >= 0x0001) && (c <= 0x007F)) { bytearr[count++] = (byte) c; } else if (c > 0x07FF) { bytearr[count++] = (byte) (0xE0 | ((c >> 12) & 0x0F)); bytearr[count++] = (byte) (0x80 | ((c >> 6) & 0x3F)); bytearr[count++] = (byte) (0x80 | ((c >> 0) & 0x3F)); } else { bytearr[count++] = (byte) (0xC0 | ((c >> 6) & 0x1F)); bytearr[count++] = (byte) (0x80 | ((c >> 0) & 0x3F)); } } dos.write(bytearr); } } freehep-io-2.0.2/src/main/java/org/freehep/util/io/IndentPrintWriter.java0000644012010301201030000000601510466735775027275 0ustar mascellanimascellanipackage org.freehep.util.io; import java.io.PrintWriter; import java.io.Writer; /** * A PrintWriter that keeps track of an indentation level and indents the output * appropriately. * * @author Tony Johnson * @author Mark Donszelmann * @version $Id: IndentPrintWriter.java 8584 2006-08-10 23:06:37Z duns $ */ public class IndentPrintWriter extends PrintWriter { /** * Creates an Indent PrintWriter. * * @param w writer to write to * @param level starting indentation level */ public IndentPrintWriter(Writer w, int level) { super(w); setIndent(level); } /** * Creates an Indent PrintWriter with indentation level 0. * * @param w writer to write to */ public IndentPrintWriter(Writer w) { this(w, 0); } public void print(boolean s) { doIndent(); super.print(s); } public void print(char s) { doIndent(); super.print(s); } public void print(char[] s) { doIndent(); super.print(s); } public void print(double s) { doIndent(); super.print(s); } public void print(float s) { doIndent(); super.print(s); } public void print(int s) { doIndent(); super.print(s); } public void print(long s) { doIndent(); super.print(s); } public void print(Object s) { doIndent(); super.print(s); } public void print(String s) { doIndent(); super.print(s); } public void println() { indented = false; super.println(); } // all other println's are implemented by the superclass in terms of print's private void doIndent() { if (indented) return; indented = true; for (int i = 0; i < indent; i++) super.print(indentString); } /** * Increase the indentation */ public void indent() { indent++; } /** * Decrease the indentation */ public void outdent() { indent--; } /** * Return the current indent count * * @return current indentation level */ public int getIndent() { return indent; } /** * Set the current indent count * * @param level new level */ public void setIndent(int level) { indent = level; } /** * Return the current indentString * * @return indent string * * @see #setIndentString(String) */ public String getIndentString() { return indentString; } /** * Set the current indentString. Default is a single tab per indent level. * * @param indentString The characters to prefix each line with (repeated for * each indent level) */ public void setIndentString(String indentString) { this.indentString = indentString; } private int indent = 0; private boolean indented = false; private String indentString = " "; } freehep-io-2.0.2/src/main/resources/0000755012010301201030000000000011274277015020257 5ustar mascellanimascellanifreehep-io-2.0.2/pom.xml0000644012010301201030000000236710633617023016052 0ustar mascellanimascellani global org.freehep 6 4.0.0 org.freehep freehep-io 2.0.2 FreeHEP IO FreeHEP I/O Library freehep-maven Maven FreeHEP http://java.freehep.org/maven2 org.freehep freehep-util 2.0.1 test junit junit scm:svn:svn://svn.freehep.org/svn/freehep/tags/freehep-io-2.0.2 scm:svn:svn://svn.freehep.org/svn/freehep/tags/freehep-io-2.0.2