Search in sources :

Example 6 with ObjectStreamException

use of java.io.ObjectStreamException in project streamsx.topology by IBMStreams.

the class RegexGrep method main.

@SuppressWarnings("serial")
public static void main(String[] args) throws Exception {
    String contextType = args[0];
    String directory = args[1];
    final Pattern pattern = Pattern.compile(args[2]);
    // Define the topology
    Topology topology = new Topology("RegexGrep");
    // All streams with tuples that are Java String objects
    TStream<String> files = FileStreams.directoryWatcher(topology, directory);
    TStream<String> lines = FileStreams.textFileReader(files);
    /*
         * Functional filter using an anonymous class to define the
         * filtering logic, in this case execution of a regular
         * expression against each input String tuple (each line
         * of the files in the directory).
         */
    TStream<String> filtered = lines.filter(new Predicate<String>() {

        @Override
        public boolean test(String v1) {
            // regular expression pattern
            return matcher.reset(v1).matches();
        }

        // Recreate the matcher (which is not serializable)
        // when the object is deserialized using readResolve.
        transient Matcher matcher;

        /*
             * Since the constructor is no invoked after serialization
             * we use readResolve as a hook to execute initialization
             * code, in this case creating the matcher from the
             * pattern. 
             * The alternative would be to create it on its first use,
             * which would require an if statement in the test method.
             */
        private Object readResolve() throws ObjectStreamException {
            matcher = pattern.matcher("");
            return this;
        }
    });
    // For debugging just print out the tuples
    filtered.print();
    // Execute the topology, just like Grep.
    Future<?> future = StreamsContextFactory.getStreamsContext(contextType).submit(topology);
    Thread.sleep(30000);
    future.cancel(true);
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) Topology(com.ibm.streamsx.topology.Topology) ObjectStreamException(java.io.ObjectStreamException)

Example 7 with ObjectStreamException

use of java.io.ObjectStreamException in project j2objc by google.

the class CertificateCertificateRepTest method testReadResolve.

/**
 * Test for <code>readResolve()</code> method<br>
 */
public final void testReadResolve() {
    MyCertificate c1 = new MyCertificate("TEST_TYPE", testEncoding);
    MyCertificateRep rep = c1.new MyCertificateRep("TEST_TYPE", new byte[] { (byte) 1, (byte) 2, (byte) 3 });
    try {
        rep.readResolve();
        fail("ObjectStreamException expected");
    } catch (ObjectStreamException e) {
    // expected
    }
    MyCertificateRep rep1 = c1.new MyCertificateRep("X509", TestUtils.getX509Certificate_v3());
    try {
        Certificate obj = (Certificate) rep1.readResolve();
        assertEquals("0.3.5", obj.getPublicKey().getAlgorithm());
        assertEquals("X.509", obj.getPublicKey().getFormat());
        assertEquals("X.509", obj.getType());
    } catch (ObjectStreamException e) {
        fail("Unexpected ObjectStreamException " + e.getMessage());
    }
}
Also used : MyCertificate(org.apache.harmony.security.tests.support.cert.MyCertificate) MyCertificateRep(org.apache.harmony.security.tests.support.cert.MyCertificate.MyCertificateRep) ObjectStreamException(java.io.ObjectStreamException) Certificate(java.security.cert.Certificate) MyCertificate(org.apache.harmony.security.tests.support.cert.MyCertificate)

Example 8 with ObjectStreamException

use of java.io.ObjectStreamException in project j2objc by google.

the class CertPathCertPathRepTest method testReadResolve.

public final void testReadResolve() {
    MyCertPath cp = new MyCertPath(testEncoding);
    MyCertPathRep rep = cp.new MyCertPathRep("MyEncoding", testEncoding);
    try {
        Object obj = rep.readResolve();
        fail("ObjectStreamException was not thrown.");
    } catch (ObjectStreamException e) {
    // expected
    }
    rep = cp.new MyCertPathRep("MyEncoding", new byte[] { (byte) 1, (byte) 2, (byte) 3 });
    try {
        rep.readResolve();
        fail("ObjectStreamException expected");
    } catch (ObjectStreamException e) {
        // expected
        System.out.println(e);
    }
}
Also used : MyCertPath(org.apache.harmony.security.tests.support.cert.MyCertPath) MyCertPathRep(org.apache.harmony.security.tests.support.cert.MyCertPath.MyCertPathRep) ObjectStreamException(java.io.ObjectStreamException)

Example 9 with ObjectStreamException

use of java.io.ObjectStreamException in project robovm by robovm.

the class CertificateTest method testWriteReplace2.

/**
     * This test just calls <code>writeReplace()</code> method<br>
     */
public final void testWriteReplace2() {
    MyCertificate c1 = new MyFailingCertificate("TEST_TYPE", testEncoding);
    try {
        c1.writeReplace();
        fail();
    } catch (ObjectStreamException expected) {
    }
}
Also used : MyCertificate(org.apache.harmony.security.tests.support.cert.MyCertificate) ObjectStreamException(java.io.ObjectStreamException) MyFailingCertificate(org.apache.harmony.security.tests.support.cert.MyFailingCertificate)

Example 10 with ObjectStreamException

use of java.io.ObjectStreamException in project robovm by robovm.

the class CertPathCertPathRepTest method testReadResolve.

public final void testReadResolve() {
    MyCertPath cp = new MyCertPath(testEncoding);
    MyCertPathRep rep = cp.new MyCertPathRep("MyEncoding", testEncoding);
    try {
        Object obj = rep.readResolve();
        fail("ObjectStreamException was not thrown.");
    } catch (ObjectStreamException e) {
    //expected
    }
    rep = cp.new MyCertPathRep("MyEncoding", new byte[] { (byte) 1, (byte) 2, (byte) 3 });
    try {
        rep.readResolve();
        fail("ObjectStreamException expected");
    } catch (ObjectStreamException e) {
        // expected
        System.out.println(e);
    }
}
Also used : MyCertPath(org.apache.harmony.security.tests.support.cert.MyCertPath) MyCertPathRep(org.apache.harmony.security.tests.support.cert.MyCertPath.MyCertPathRep) ObjectStreamException(java.io.ObjectStreamException)

Aggregations

ObjectStreamException (java.io.ObjectStreamException)13 Topology (com.ibm.streamsx.topology.Topology)4 Matcher (java.util.regex.Matcher)4 InputStream (java.io.InputStream)2 Certificate (java.security.cert.Certificate)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Pattern (java.util.regex.Pattern)2 MyCertPath (org.apache.harmony.security.tests.support.cert.MyCertPath)2 MyCertificate (org.apache.harmony.security.tests.support.cert.MyCertificate)2 MyCertificateRep (org.apache.harmony.security.tests.support.cert.MyCertificate.MyCertificateRep)2 File (java.io.File)1 IOException (java.io.IOException)1 Serializable (java.io.Serializable)1 Annotation (java.lang.annotation.Annotation)1 ClassFileTransformer (java.lang.instrument.ClassFileTransformer)1 ManagementFactory (java.lang.management.ManagementFactory)1 AnnotatedElement (java.lang.reflect.AnnotatedElement)1 Constructor (java.lang.reflect.Constructor)1 Executable (java.lang.reflect.Executable)1