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);
}
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());
}
}
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);
}
}
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) {
}
}
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);
}
}
Aggregations