本文整理匯總了Java中com.ociweb.pronghorn.pipe.stream.StreamingReadVisitorToJSON類的典型用法代碼示例。如果您正苦於以下問題:Java StreamingReadVisitorToJSON類的具體用法?Java StreamingReadVisitorToJSON怎麽用?Java StreamingReadVisitorToJSON使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
StreamingReadVisitorToJSON類屬於com.ociweb.pronghorn.pipe.stream包,在下文中一共展示了StreamingReadVisitorToJSON類的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: sequenceFragmentWriteRead
import com.ociweb.pronghorn.pipe.stream.StreamingReadVisitorToJSON; //導入依賴的package包/類
@Test
public void sequenceFragmentWriteRead() {
Pipe<MessageSchemaDynamic> ring = new Pipe<MessageSchemaDynamic>(
new PipeConfig<MessageSchemaDynamic>(new MessageSchemaDynamic(FROM),
1<<primaryRingSizeInBits, 1<<byteRingSizeInBits ));
ring.initBuffers();
int testSize = 5;
//in this method we write two sequence members but only record the count after writing the members
populateRingBufferWithSequence(ring, testSize);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
StreamingReadVisitor visitor = new StreamingReadVisitorToJSON(ps);
StreamingVisitorReader reader = new StreamingVisitorReader(ring, visitor);// new StreamingReadVisitorDebugDelegate(visitor) );
//ring is fully populated so we should not need to call this run again
while (Pipe.contentRemaining(ring)>0) {
reader.run();
}
ps.close();
String results = new String(baos.toByteArray());
//spot check the produced JSON
assertTrue(results, results.indexOf("\"TruckId\":10")>0);
assertTrue(results, results.indexOf("{\"AThing\":7}")>0);
assertTrue(results, results.indexOf("{\"JustOneMoreQuestion\":42}")>0);
}
示例2: generatorTest
import com.ociweb.pronghorn.pipe.stream.StreamingReadVisitorToJSON; //導入依賴的package包/類
@Test
public void generatorTest() {
final int seed = 2;
final long aLongValue = 2945688134060370505l;//hard coded value that comes from this seed 2
final int aNegIntValue = -29;//hard coded value that comes from this seed 2
Pipe<MessageSchemaDynamic> ring = new Pipe<MessageSchemaDynamic>(new PipeConfig<MessageSchemaDynamic>( new MessageSchemaDynamic(FROM), 50, 30));
ring.initBuffers();
StreamingWriteVisitorGenerator swvg = new StreamingWriteVisitorGenerator(FROM, new Random(seed), 30, 30);
StreamingVisitorWriter svw = new StreamingVisitorWriter(ring, swvg);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
// PrintStream ps = System.out;
StreamingReadVisitor visitor = new StreamingReadVisitorToJSON(ps);
StreamingVisitorReader reader = new StreamingVisitorReader(ring, visitor);//, new StreamingReadVisitorDebugDelegate(visitor) );
svw.startup();
reader.startup();
do {
svw.run();
} while (!svw.isAtBreakPoint());
reader.run();
svw.shutdown();
reader.shutdown();
byte[] byteArray = baos.toByteArray();
assertTrue("No JSON was produced", byteArray.length>0);
String results = new String(byteArray);
//spot check the produced JSON
assertTrue(results, results.indexOf("\"Trucks\":")>0);
assertTrue(results, results.indexOf("{\"Squad\":")>0);
assertTrue(results, results.indexOf(Long.toString(aLongValue))>0);
assertTrue(results, results.indexOf(Integer.toString(aNegIntValue))>0);
}