本文整理匯總了Java中com.neverwinterdp.util.IOUtil類的典型用法代碼示例。如果您正苦於以下問題:Java IOUtil類的具體用法?Java IOUtil怎麽用?Java IOUtil使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
IOUtil類屬於com.neverwinterdp.util包,在下文中一共展示了IOUtil類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testSerializable
import com.neverwinterdp.util.IOUtil; //導入依賴的package包/類
@Test
public void testSerializable() throws Exception {
QDigest qdigest = new QDigest(COMPRESSION_FACTOR);
Random rand = new Random() ;
for(int i = 0; i < 10000; i++) {
qdigest.offer(rand.nextInt((i + 1))) ;
}
qdigest.optimize() ;
byte[] data = IOUtil.serialize(qdigest) ;
QDigest qdigestClone = (QDigest) IOUtil.deserialize(data) ;
System.out.println("Serialization Size: " + data.length) ;
byte[] customSerializedData = QDigest.serialize(qdigest) ;
System.out.println("Custom Serialization Size: " + customSerializedData.length) ;
QDigest customqDigestClone = QDigest.deserialize(customSerializedData) ;
assertEquals(qdigest.toString(), customqDigestClone.toString()) ;
}
示例2: testPerformance
import com.neverwinterdp.util.IOUtil; //導入依賴的package包/類
@Test
public void testPerformance() throws Exception {
MetricRegistry mRegistry = new MetricRegistry() ;
WirePayload payload = createWirePayload() ;
System.out.println("ProtoBuf Size: " + payload.toByteArray().length);
System.out.println("Serializable Size: " + IOUtil.serialize(payload).length);
for(int i = 0; i < 1000000; i++) {
Timer.Context protoBufSerCtx = mRegistry.timer("protobuf", "serialize").time() ;
byte[] protobufData = payload.toByteArray() ;
protoBufSerCtx .close();
Timer.Context protobufDeserCtx = mRegistry.timer("protobuf", "deserialize").time() ;
WirePayload deserPayload = WirePayload.parseFrom(protobufData) ;
protobufDeserCtx.close();
Timer.Context javaSerCtx = mRegistry.timer("java", "serialize").time() ;
byte[] javaData = IOUtil.serialize(payload) ;
javaSerCtx .close();
Timer.Context javaDeserCtx = mRegistry.timer("java", "deserialize").time() ;
deserPayload = (WirePayload)IOUtil.deserialize(javaData) ;
javaDeserCtx.close();
}
new MetricPrinter().print(mRegistry) ;
}
示例3: require
import com.neverwinterdp.util.IOUtil; //導入依賴的package包/類
public void require(String scriptFile) {
if(loadedFiles.contains(scriptFile)) return ;
try {
String script = null ;
if(scriptFile.startsWith("classpath:") || scriptFile.startsWith("file:")) {
System.err.println("Script File: " + scriptFile) ;
script = IOUtil.getStreamContentAsString(IOUtil.loadRes(scriptFile), "UTF-8") ;
} else {
script = IOUtil.getFileContentAsString(libDir + "/" + scriptFile, "UTF-8") ;
}
loadedFiles.add(scriptFile) ;
engine.put(ScriptEngine.FILENAME, scriptFile);
engine.eval(script);
} catch(Exception ex) {
ex.printStackTrace() ;
throw new RuntimeException(ex) ;
}
}
示例4: testHdfsDataflow
import com.neverwinterdp.util.IOUtil; //導入依賴的package包/類
@Test
public void testHdfsDataflow() throws Exception {
ScribenginShell shell = new ScribenginShell(clusterBuilder.getVMClusterBuilder().getVMClient());
FileSystem fs = getFileSystem();
try {
HelloHDFSDataflowBuilder hdfDataflowBuilder =
new HelloHDFSDataflowBuilder(clusterBuilder.getScribenginClient(), fs, getDataDir());
hdfDataflowBuilder.createSource(15, 3, 5);
ScribenginClient scribenginClient = clusterBuilder.getScribenginClient();
String dataflowJson = IOUtil.getFileContentAsString("src/dataflows/hdfs/dataflow.json") ;
ScribenginWaitingEventListener eventListener =
scribenginClient.submit("build/release/dataflows/hdfs", dataflowJson);
eventListener.waitForEvents(60000);
} catch(Exception ex) {
ex.printStackTrace();
} finally {
Thread.sleep(3000);
shell.execute("vm info");
shell.execute("registry dump --path /");
HDFSUtil.dump(fs, getDataDir() + "/sink");
HDFSUtil.dump(fs, getDataDir() + "/invalid-sink");
}
}
示例5: execute
import com.neverwinterdp.util.IOUtil; //導入依賴的package包/類
@Override
public void execute(Shell shell, CommandInput cmdInput) throws Exception {
ScribenginShell scribenginShell = (ScribenginShell) shell;
ScribenginClient scribenginClient= scribenginShell.getScribenginClient();
try {
String dataflowJson = IOUtil.getFileContentAsString(descriptor) ;
System.out.println("Dataflow JSON:");
System.out.println(dataflowJson);
ScribenginWaitingEventListener eventListener = scribenginClient.submit(dataflowPath, dataflowJson);
System.out.println("Submited.................");
eventListener.waitForEvents(60000);
System.out.println("Finish wait for event..........");
} catch(Exception ex) {
ex.printStackTrace();
} finally {
Thread.sleep(3000);
shell.execute("vm info");
shell.execute("registry dump --path /");
}
}
示例6: toAck
import com.neverwinterdp.util.IOUtil; //導入依賴的package包/類
protected Ack toAck(HttpContent content) {
ByteBuf byteBuf = content.content() ;
byte[] data = new byte[byteBuf.readableBytes()] ;
byteBuf.readBytes(data) ;
//byteBuf.release() ;
Ack ack = null;
try {
ack = (Ack)IOUtil.deserialize(data);
} catch (Exception e) {
e.printStackTrace();
ack = new Ack() ;
ack.setStatus(Ack.Status.ERROR);
ack.setMessage(e.getMessage());
}
return ack ;
}
示例7: testUpdate
import com.neverwinterdp.util.IOUtil; //導入依賴的package包/類
@Test
public void testUpdate() throws Exception {
long start = System.currentTimeMillis() ;
Timer timer = new Timer() ;
com.codahale.metrics.Timer codahaleTimer = new com.codahale.metrics.Timer() ;
Random rand = new Random() ;
int LOOP = 1000;
for(int i = 0; i < LOOP; i++) {
long duration = rand.nextInt(100) ;
if(i > LOOP/5) duration = rand.nextInt(20) ;
Thread.sleep(duration);
timer.update(duration, TimeUnit.MICROSECONDS);
codahaleTimer.update(duration, TimeUnit.MICROSECONDS);
}
byte[] data = IOUtil.serialize(timer) ;
Timer serialization = (Timer)IOUtil.deserialize(data) ;
String json = JSONSerializer.INSTANCE.toString(timer) ;
//Timer jsonSerialization = JSONSerializer.INSTANCE.fromString(json, Timer.class) ;
TimerPrinter printer = new TimerPrinter() ;
printer.print("NeverwinterDP", timer);
printer.print("Serialization", serialization);
//printer.print("JSON Serialization", jsonSerialization);
printer.print("Codahale", codahaleTimer);
printer.flush();
System.out.println("In " + (System.currentTimeMillis() - start) + "ms");
System.out.println("Timer java serialization size: " + data.length);
System.out.println("Timer json serialization size: " + json.getBytes().length);
System.out.println(json);
}
示例8: testBasic
import com.neverwinterdp.util.IOUtil; //導入依賴的package包/類
@Test
public void testBasic() throws Exception {
Random rand = new Random() ;
MetricRegistry registry = new MetricRegistry("basic") ;
registry.getPluginManager().add(new MetricPluginDummy());
Timer timer1 = registry.getTimer("timer") ;
assertNotNull(timer1) ;
Timer timer2 = registry.getTimer("timer") ;
assertEquals(timer1, timer2) ;
for(int i = 0; i < 10000; i++) {
timer1.update(rand.nextInt(i + 1), TimeUnit.NANOSECONDS);
}
Counter counter1 = registry.getCounter("counter") ;
for(int i = 0; i < 100; i++) {
counter1.incr() ;
}
Counter counter2 = registry.getCounter("counter") ;
assertNotNull(counter1) ;
assertEquals(counter1, counter2) ;
byte[] data = IOUtil.serialize(registry) ;
MetricRegistry registryClone = (MetricRegistry)IOUtil.deserialize(data) ;
Assert.assertEquals(0, registryClone.getPluginManager().size());
System.out.println("MetricRegistry serialization size: " + data.length);
System.out.println("Timer serialization size: " + IOUtil.serialize(timer1).length);
System.out.println("QDigest serialization size: " + IOUtil.serialize(timer1.getHistogram().getQDigest()).length);
MetricPrinter mPrinter = new MetricPrinter() ;
mPrinter.print(registry);
}
示例9: testPOJO
import com.neverwinterdp.util.IOUtil; //導入依賴的package包/類
@Test
public void testPOJO() throws Exception {
String template = IOUtil.getFileContentAsString("src/test/resources/mustache/hello.mtpl") ;
MustacheFactory mf = new DefaultMustacheFactory();
Mustache mustache = mf.compile(new StringReader(template), "hello");
mustache.execute(new PrintWriter(System.out), new MustacheTemplateUnitTest()).flush();
}
示例10: toBytes
import com.neverwinterdp.util.IOUtil; //導入依賴的package包/類
public byte[] toBytes(T object) {
try {
return IOUtil.serialize(object);
} catch (IOException e) {
throw new RuntimeException(e) ;
}
}
示例11: fromBytes
import com.neverwinterdp.util.IOUtil; //導入依賴的package包/類
public T fromBytes(byte[] data) {
try {
return (T) IOUtil.deserialize(data);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例12: runScript
import com.neverwinterdp.util.IOUtil; //導入依賴的package包/類
public void runScript(String scriptFile) {
try {
String script = IOUtil.getFileContentAsString(scriptFile, "UTF-8") ;
engine.put(ScriptEngine.FILENAME, scriptFile);
engine.eval(script);
} catch(Exception ex) {
ex.printStackTrace() ;
throw new RuntimeException(ex) ;
}
}
示例13: testS3ObjectWriter
import com.neverwinterdp.util.IOUtil; //導入依賴的package包/類
@Test
public void testS3ObjectWriter() throws IOException, InterruptedException {
String KEY = "test-s3-object-writer" ;
S3ObjectWriter writer = new S3ObjectWriter(s3Client, BUCKET_NAME, KEY, new ObjectMetadata());
for(int i = 0; i < 10; i++) {
writer.write(("This is the test " + i + "\n").getBytes());
Thread.sleep(1000);
}
writer.waitAndClose(10000);;
S3Object object = s3Client.getObject(BUCKET_NAME, KEY);
String content = IOUtil.getStreamContentAsString(object.getObjectContent(), "UTF-8") ;
System.out.println(content);
Assert.assertEquals(10, content.split("\n").length);
}
示例14: testCreateReadWrite
import com.neverwinterdp.util.IOUtil; //導入依賴的package包/類
@Test
public void testCreateReadWrite() throws Exception {
String TEXT = "hello" ;
Path testPath = new Path("./build/hdfs/test.txt");
FSDataOutputStream os = fs.create(testPath) ;
os.write(TEXT.getBytes());
os.close();
FSDataInputStream is = fs.open(testPath);
String text = IOUtil.getStreamContentAsString(is, "UTF-8");
Assert.assertEquals(TEXT, text);
}
示例15: toBinData
import com.neverwinterdp.util.IOUtil; //導入依賴的package包/類
@Override
protected byte[] toBinData(Message message) {
try {
return IOUtil.serialize(message) ;
} catch (IOException e) {
throw new RuntimeException(e) ;
}
}