下面列出了org.apache.commons.io.output.NullOutputStream#NULL_OUTPUT_STREAM 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* @return The stream to write to after the entry signal was received.
*/
public OutputStream getStream() {
if(null == stream) {
// Nothing to write
return NullOutputStream.NULL_OUTPUT_STREAM;
}
return stream;
}
/**
* @return The stream to write to after the entry signal was received.
*/
public OutputStream getStream() {
if(null == stream) {
// Nothing to write
return NullOutputStream.NULL_OUTPUT_STREAM;
}
return stream;
}
/**
* Test if the OfflineImageViewerPB can correctly parse a fsimage containing
* snapshots
*/
@Test
public void testOfflineImageViewer() throws Exception {
runTestSnapshot(1);
// retrieve the fsimage. Note that we already save namespace to fsimage at
// the end of each iteration of runTestSnapshot.
File originalFsimage = FSImageTestUtil.findLatestImageFile(
FSImageTestUtil.getFSImage(
cluster.getNameNode()).getStorage().getStorageDir(0));
assertNotNull("Didn't generate or can't find fsimage", originalFsimage);
PrintStream o = new PrintStream(NullOutputStream.NULL_OUTPUT_STREAM);
PBImageXmlWriter v = new PBImageXmlWriter(new Configuration(), o);
v.visit(new RandomAccessFile(originalFsimage, "r"));
}
@Test(expected = IOException.class)
public void testTruncatedFSImage() throws IOException {
File truncatedFile = folder.newFile();
PrintStream output = new PrintStream(NullOutputStream.NULL_OUTPUT_STREAM);
copyPartOfFile(originalFsimage, truncatedFile);
new FileDistributionCalculator(new Configuration(), 0, 0, output)
.visit(new RandomAccessFile(truncatedFile, "r"));
}
/**
* Test if the OfflineImageViewerPB can correctly parse a fsimage containing
* snapshots
*/
@Test
public void testOfflineImageViewer() throws Exception {
runTestSnapshot(1);
// retrieve the fsimage. Note that we already save namespace to fsimage at
// the end of each iteration of runTestSnapshot.
File originalFsimage = FSImageTestUtil.findLatestImageFile(
FSImageTestUtil.getFSImage(
cluster.getNameNode()).getStorage().getStorageDir(0));
assertNotNull("Didn't generate or can't find fsimage", originalFsimage);
PrintStream o = new PrintStream(NullOutputStream.NULL_OUTPUT_STREAM);
PBImageXmlWriter v = new PBImageXmlWriter(new Configuration(), o);
v.visit(new RandomAccessFile(originalFsimage, "r"));
}
@Test(expected = IOException.class)
public void testTruncatedFSImage() throws IOException {
File truncatedFile = folder.newFile();
PrintStream output = new PrintStream(NullOutputStream.NULL_OUTPUT_STREAM);
copyPartOfFile(originalFsimage, truncatedFile);
new FileDistributionCalculator(new Configuration(), 0, 0, output)
.visit(new RandomAccessFile(truncatedFile, "r"));
}
public HashOrderDependent(){
try{
digest = MessageDigest.getInstance("MD5");
} catch ( Exception ex ) {
throw new RuntimeException(ex);
}
digestOutputStream = new DigestOutputStream(NullOutputStream.NULL_OUTPUT_STREAM, digest);
dataOutputStream = new DataOutputStream(digestOutputStream);
}
/**
* @param settings Settings that define what to capture.
* @param processStream Stream to capture output.
* @param standardStream Stream to write debug output.
*/
public CapturedStreamOutput(OutputStreamSettings settings, InputStream processStream, PrintStream standardStream) {
this.processStream = processStream;
int bufferSize = settings.getBufferSize();
this.bufferStream = (bufferSize < 0) ? new ByteArrayOutputStream() : new ByteArrayOutputStream(bufferSize);
for (StreamLocation location : settings.getStreamLocations()) {
OutputStream outputStream;
switch (location) {
case Buffer:
if (bufferSize < 0) {
outputStream = this.bufferStream;
} else {
outputStream = new HardThresholdingOutputStream(bufferSize) {
@Override
protected OutputStream getStream() {
return bufferTruncated ? NullOutputStream.NULL_OUTPUT_STREAM : bufferStream;
}
@Override
protected void thresholdReached() {
bufferTruncated = true;
}
};
}
break;
case File:
try {
outputStream = new FileOutputStream(settings.getOutputFile(), settings.isAppendFile());
} catch (IOException e) {
throw new UserException.BadInput(e.getMessage());
}
break;
case Standard:
outputStream = standardStream;
break;
default:
throw new GATKException("Unexpected stream location: " + location);
}
this.outputStreams.put(location, outputStream);
}
}