本文整理匯總了Java中org.apache.commons.io.output.NullOutputStream類的典型用法代碼示例。如果您正苦於以下問題:Java NullOutputStream類的具體用法?Java NullOutputStream怎麽用?Java NullOutputStream使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
NullOutputStream類屬於org.apache.commons.io.output包,在下文中一共展示了NullOutputStream類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: fileTransferRequest
import org.apache.commons.io.output.NullOutputStream; //導入依賴的package包/類
@Override
public void fileTransferRequest(FileTransferRequest request) {
final IncomingFileTransfer transfer = request.accept();
Thread transferThread = new Thread(new Runnable() {
public void run() {
try {
OutputStream os = new NullOutputStream();
InputStream is = transfer.recieveFile();
log.debug("Reading from stream: " + is.available());
IOUtils.copy(is, os);
log.debug("Left in stream: " + is.available());
} catch (Exception e) {
log.error("Failed incoming file transfer", e);
}
}
});
transferThread.start();
}
示例2: testDownloadGzip
import org.apache.commons.io.output.NullOutputStream; //導入依賴的package包/類
@Test
public void testDownloadGzip() throws Exception {
final Host host = new Host(new SwiftProtocol(), "identity.api.rackspacecloud.com", new Credentials(
System.getProperties().getProperty("rackspace.key"), System.getProperties().getProperty("rackspace.secret")
));
final SwiftSession session = new SwiftSession(host);
session.open(new DisabledHostKeyCallback(), new DisabledLoginCallback());
session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());
final TransferStatus status = new TransferStatus();
status.setLength(182L);
final Path container = new Path(".ACCESS_LOGS", EnumSet.of(Path.Type.directory, Path.Type.volume));
container.attributes().setRegion("DFW");
final SwiftRegionService regionService = new SwiftRegionService(session);
final InputStream in = new SwiftReadFeature(session, regionService).read(new Path(container,
"/cdn.cyberduck.ch/2015/03/01/10/3b1d6998c430d58dace0c16e58aaf925.log.gz",
EnumSet.of(Path.Type.file)), status, new DisabledConnectionCallback());
assertNotNull(in);
new StreamCopier(status, status).transfer(in, new NullOutputStream());
assertEquals(182L, status.getOffset());
assertEquals(182L, status.getLength());
in.close();
session.close();
}
示例3: testDownloadGzip
import org.apache.commons.io.output.NullOutputStream; //導入依賴的package包/類
@Test
public void testDownloadGzip() throws Exception {
final Host host = new Host(new S3Protocol(), new S3Protocol().getDefaultHostname(), new Credentials(
System.getProperties().getProperty("s3.key"), System.getProperties().getProperty("s3.secret")
));
final S3Session session = new S3Session(host);
session.open(new DisabledHostKeyCallback(), new DisabledLoginCallback());
session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());
final int length = 1457;
final byte[] content = RandomUtils.nextBytes(length);
final Path container = new Path("test-us-east-1-cyberduck", EnumSet.of(Path.Type.directory, Path.Type.volume));
final Path file = new Path(container, UUID.randomUUID().toString(), EnumSet.of(Path.Type.file));
final TransferStatus status = new TransferStatus().length(content.length);
status.setChecksum(new SHA256ChecksumCompute().compute(new ByteArrayInputStream(content), status));
final OutputStream out = new S3WriteFeature(session).write(file, status, new DisabledConnectionCallback());
new StreamCopier(new TransferStatus(), new TransferStatus()).transfer(new ByteArrayInputStream(content), out);
out.close();
final InputStream in = new S3ReadFeature(session).read(file, status, new DisabledConnectionCallback());
assertNotNull(in);
new StreamCopier(status, status).transfer(in, new NullOutputStream());
assertEquals(content.length, status.getOffset());
assertEquals(content.length, status.getLength());
in.close();
new S3DefaultDeleteFeature(session).delete(Collections.singletonList(file), new DisabledLoginCallback(), new Delete.DisabledCallback());
session.close();
}
示例4: shouldRejectMissingEnv
import org.apache.commons.io.output.NullOutputStream; //導入依賴的package包/類
@Test
public void shouldRejectMissingEnv() {
Map<String, String> requiredEnv = new HashMap<>();
requiredEnv.put("FN_PATH", "/route");
requiredEnv.put("FN_METHOD", "GET");
requiredEnv.put("FN_APP_NAME", "app_name");
requiredEnv.put("FN_REQUEST_URL", "http://test.com/fn/tryInvoke");
for (String key : requiredEnv.keySet()) {
Map<String, String> newEnv = new HashMap<>(requiredEnv);
newEnv.remove(key);
DefaultEventCodec codec = new DefaultEventCodec(newEnv, asStream("input"), new NullOutputStream());
try{
codec.readEvent();
fail("Should have rejected missing env "+ key);
}catch(FunctionInputHandlingException e){
assertThat(e).hasMessageContaining("Required environment variable " + key+ " is not set - are you running a function outside of fn run?");
}
}
}
示例5: MediniQVTFamiliesToPersonsConfig
import org.apache.commons.io.output.NullOutputStream; //導入依賴的package包/類
public MediniQVTFamiliesToPersonsConfig() {
super(new FamiliesComparator(), new PersonsComparator());
logger = new OutputStreamLog(new PrintStream(new NullOutputStream()));
// logger = new OutputStreamLog(System.err);
processorImpl = new EMFQvtProcessorImpl(this.logger);
processorImpl.setProperty(QVTProcessorConsts.PROP_DEBUG, "true");
basePath = "./src/org/benchmarx/examples/familiestopersons/implementations/medini/base/";
// Tell the QVT engine, which transformation to execute
transformation = "families2personsconfig";
// Tell the QVT engine a directory to work in - e.g. to store the trace (meta)models
File tracesFile = new File(basePath + "traces/trace.trafo");
tracesFile.delete();
}
示例6: launch
import org.apache.commons.io.output.NullOutputStream; //導入依賴的package包/類
/**
* launch the transformation in the QVT execution engine
*
* @param direction : the desired execution direction
*/
public void launch(String direction) {
PrintStream ps = System.out;
PrintStream ps_err = System.err;
// Load the QVT relations
try {
System.setOut(new PrintStream(new NullOutputStream()));
System.setErr(new PrintStream(new NullOutputStream()));
qvtRuleSet = new FileReader(basePath + RULESET);
this.transform(qvtRuleSet, transformation, direction);
} catch (FileNotFoundException fileNotFoundException) {
fileNotFoundException.printStackTrace();
return;
} catch (Throwable throwable) {
throwable.printStackTrace();
} finally {
System.setOut(ps);
System.setErr(ps_err);
}
}
示例7: MediniQVTFamiliesToPersons
import org.apache.commons.io.output.NullOutputStream; //導入依賴的package包/類
public MediniQVTFamiliesToPersons() {
super(new FamiliesComparator(), new PersonsComparator());
logger = new OutputStreamLog(new PrintStream(new NullOutputStream()));
// logger = new OutputStreamLog(System.err);
processorImpl = new EMFQvtProcessorImpl(this.logger);
processorImpl.setProperty(QVTProcessorConsts.PROP_DEBUG, "true");
basePath = "./src/org/benchmarx/examples/familiestopersons/implementations/medini/base/";
// Tell the QVT engine, which transformation to execute
transformation = "families2persons";
// Tell the QVT engine a directory to work in - e.g. to store the trace (meta)models
File tracesFile = new File(basePath + "traces/trace.trafo");
tracesFile.delete();
}
示例8: launch
import org.apache.commons.io.output.NullOutputStream; //導入依賴的package包/類
/**
* launch the transformation in the QVT execution engine
*
* @param direction : the desired execution direction
*/
public void launch(String direction) {
PrintStream ps = System.out;
PrintStream ps_err = System.err;
// Load the QVT relations
try {
System.setOut(new PrintStream(new NullOutputStream()));
System.setErr(new PrintStream(new NullOutputStream()));
qvtRuleSet = new FileReader(basePath + RULESET);
this.transform(qvtRuleSet, transformation, direction);
} catch (FileNotFoundException fileNotFoundException) {
fileNotFoundException.printStackTrace();
return;
} catch (Throwable throwable) {
throwable.printStackTrace();
System.out.println(throwable.getMessage());
} finally {
System.setOut(ps);
System.setErr(ps_err);
}
}
示例9: writeObject
import org.apache.commons.io.output.NullOutputStream; //導入依賴的package包/類
/**
* Custom serialization method.
*
* @param oos the object output stream
* @throws IOException
*/
protected void writeObject(ObjectOutputStream oos) throws IOException {
// figure out size of the written network
CountingOutputStream cos = new CountingOutputStream(new NullOutputStream());
if (replaceMissingFilter != null) {
ModelSerializer.writeModel(model, cos, false);
}
modelSize = cos.getByteCount();
// default serialization
oos.defaultWriteObject();
// actually write the network
if (replaceMissingFilter != null) {
ModelSerializer.writeModel(model, oos, false);
}
}
示例10: testIdiomaticInvokationThrowsException
import org.apache.commons.io.output.NullOutputStream; //導入依賴的package包/類
/**
* Demonstrates idiomatic exception handling with try-with-resources
*
* @throws Exception if something exceptional happens
*/
@Test
public void testIdiomaticInvokationThrowsException() throws Exception {
final InputStream mockBody = mock(InputStream.class);
final IOException ioe = new IOException("Mocked IOE");
when(mockBody.read(any(byte[].class))).thenThrow(ioe);
final FcrepoClient client = mock(FcrepoClient.class);
final GetBuilder getBuilder = mock(GetBuilder.class);
when(client.get(any(URI.class))).thenReturn(getBuilder);
when(getBuilder.perform()).thenReturn(new FcrepoResponse(null, 200, null, mockBody));
try (FcrepoResponse res = client.get(URI.create("foo")).perform()) {
ByteStreams.copy(res.getBody(), NullOutputStream.NULL_OUTPUT_STREAM);
fail("Expected an IOException to be thrown.");
} catch (IOException e) {
assertSame(ioe, e);
}
verify(mockBody).close();
}
示例11: workflowBundle
import org.apache.commons.io.output.NullOutputStream; //導入依賴的package包/類
@Test
public void workflowBundle() throws Exception {
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
// To test that seeAlso URIs are stored
serializer.workflowDoc(new NullOutputStream(), workflowBundle.getMainWorkflow(), URI.create(HELLOWORLD_RDF));
serializer.profileDoc(new NullOutputStream(), workflowBundle.getProfiles().getByName("tavernaWorkbench"), URI.create(TAVERNAWORKBENCH_RDF));
serializer.profileDoc(new NullOutputStream(), workflowBundle.getProfiles().getByName("tavernaServer"), URI.create(TAVERNASERVER_RDF));
serializer.workflowBundleDoc(outStream, URI.create("workflowBundle.rdf"));
//System.out.write(outStream.toByteArray());
Document doc = parseXml(outStream);
Element root = doc.getRootElement();
checkRoot(root);
checkWorkflowBundleDocument(root);
}
示例12: prepareFileEntry
import org.apache.commons.io.output.NullOutputStream; //導入依賴的package包/類
public void prepareFileEntry(RmpFileEntry entry) throws IOException, InterruptedException {
EntryInfo info = new EntryInfo();
info.name = entry.getFileName();
info.extendsion = entry.getFileExtension();
long pos = rmpOutputFile.getFilePointer();
info.offset = pos;
CountingOutputStream cout = new CountingOutputStream(new NullOutputStream());
entry.writeFileContent(cout);
info.length = cout.getBytesWritten();
long newPos = pos + info.length;
if ((info.length % 2) != 0)
newPos++;
if (newPos > MAX_FILE_SIZE)
throwRmpTooLarge();
rmpOutputFile.seek(newPos);
entries.add(info);
log.debug("Prepared data of entry " + entry + " bytes=" + info.length);
}
示例13: execute
import org.apache.commons.io.output.NullOutputStream; //導入依賴的package包/類
/**
* Execute a Drush command.
*/
protected boolean execute(ArgumentListBuilder args, TaskListener out) throws IOException, InterruptedException {
ProcStarter starter = launcher.launch().pwd(workspace).cmds(args);
if (out == null) {
// Output stdout/stderr into listener.
starter.stdout(listener);
} else {
// Output stdout into out.
// Do not output stderr since this breaks the XML formatting on stdout.
starter.stdout(out).stderr(NullOutputStream.NULL_OUTPUT_STREAM);
}
starter.join();
return true;
}
示例14: getUnsafeResultElements
import org.apache.commons.io.output.NullOutputStream; //導入依賴的package包/類
/**
* Gets a map of unsafe result elements, ie. elements that cannot be saved
* because serialization fails.
*
* @return
*/
public Map<ComponentJob, AnalyzerResult> getUnsafeResultElements() {
if (_unsafeResultElements == null) {
_unsafeResultElements = new LinkedHashMap<>();
final Map<ComponentJob, AnalyzerResult> resultMap = _analysisResult.getResultMap();
for (final Entry<ComponentJob, AnalyzerResult> entry : resultMap.entrySet()) {
final AnalyzerResult analyzerResult = entry.getValue();
try {
SerializationUtils.serialize(analyzerResult, new NullOutputStream());
} catch (final SerializationException e) {
_unsafeResultElements.put(entry.getKey(), analyzerResult);
}
}
}
return _unsafeResultElements;
}
示例15: prettyPrint
import org.apache.commons.io.output.NullOutputStream; //導入依賴的package包/類
@Test
public void prettyPrint() throws Exception {
// given
final String version = versionService.version().getVersionId();
final List<Action> actions = getSimpleAction("uppercase", "column_name", "lastname");
final PreparationActions newContent = new PreparationActions(actions, version);
final Step step = new Step(Step.ROOT_STEP.id(), newContent.id(), version);
final Preparation preparation = new Preparation("#15325878", "1234", step.id(), version);
repository.add(newContent);
repository.add(step);
repository.add(preparation);
// when
PreparationUtils.prettyPrint(repository, preparation, new NullOutputStream());
// Basic walk through code, no assert.
}