List of usage examples for org.apache.commons.io.input NullInputStream NullInputStream
public NullInputStream(long size)
From source file:net.krotscheck.util.ResourceUtil.java
/** * Read the resource found at the given path into a stream. * * @param resourcePath The path to the resource. * @return The resource as an input stream. If the resource was not found, * this will be the NullInputStream./*from w w w . ja v a 2 s . c o m*/ */ public static InputStream getResourceAsStream(final String resourcePath) { File resource = getFileForResource(resourcePath); if (!resource.exists() || resource.isDirectory()) { logger.error("Cannot read resource, does not exist" + " (or is a directory)."); return new NullInputStream(0); } try { return new FileInputStream(resource); } catch (IOException ioe) { logger.error(ioe.getMessage()); return new NullInputStream(0); } }
From source file:com.thoughtworks.go.agent.service.TokenRequester.java
private String responseBody(CloseableHttpResponse response) throws IOException { try (InputStream is = response.getEntity() == null ? new NullInputStream(0) : response.getEntity().getContent()) { return IOUtils.toString(is, StandardCharsets.UTF_8); }//from www . jav a 2s. c om }
From source file:ch.cyberduck.core.azure.AzureDirectoryFeature.java
@Override public Path mkdir(final Path folder, final String region, final TransferStatus status) throws BackgroundException { try {//from ww w .j ava 2 s . c om final BlobRequestOptions options = new BlobRequestOptions(); if (containerService.isContainer(folder)) { // Container name must be lower case. final CloudBlobContainer container = session.getClient() .getContainerReference(containerService.getContainer(folder).getName()); container.create(options, context); } else { if (Checksum.NONE == status.getChecksum()) { status.setChecksum(writer.checksum(folder).compute(new NullInputStream(0L), status)); } final EnumSet<AbstractPath.Type> type = EnumSet.copyOf(folder.getType()); type.add(Path.Type.placeholder); final Path placeholder = new Path(folder.getParent(), folder.getName(), type, new PathAttributes(folder.attributes())); new DefaultStreamCloser() .close(writer.write(placeholder, status, new DisabledConnectionCallback())); return placeholder; } } catch (URISyntaxException e) { throw new NotfoundException(e.getMessage(), e); } catch (StorageException e) { throw new AzureExceptionMappingService().map("Cannot create folder {0}", e, folder); } return folder; }
From source file:com.norconex.committer.AbstractMappedCommitterTest.java
/** * Test commit if there is enough document. * @throws IOException could not create temporary file *//*from w ww.j a v a 2 s . c o m*/ @Test public void testCommit() throws IOException { committer.setQueueSize(1); committer.add(defaultReference, new NullInputStream(0), metadata); assertTrue(committed); }
From source file:com.talis.storage.SubmittedItemTest.java
@Test public void getMetadataReturnsThatSuppliedInConstructor() { Multimap<String, String> meta = ArrayListMultimap.create(); meta.put("key-0", "value-0"); meta.put("key-0", "value-1"); meta.put("key-1", "value-3"); SubmittedItem submittedItem = new SubmittedItem(MediaType.TEXT_XML_TYPE, new NullInputStream(1024), meta); Multimap<String, String> fromItem = submittedItem.getMetadata(); assertTrue(Iterables.elementsEqual(meta.keySet(), fromItem.keySet())); for (String key : meta.keySet()) { assertTrue(Iterables.elementsEqual(meta.get(key), fromItem.get(key))); }/* www.j a va 2 s . com*/ }
From source file:ch.cyberduck.core.b2.B2DirectoryFeature.java
@Override public Path mkdir(final Path folder, final String region, final TransferStatus status) throws BackgroundException { try {// w w w. j a v a 2 s .co m if (containerService.isContainer(folder)) { final B2BucketResponse response = session.getClient().createBucket( containerService.getContainer(folder).getName(), null == region ? BucketType.valueOf(PreferencesFactory.get().getProperty("b2.bucket.acl.default")) : BucketType.valueOf(region)); switch (response.getBucketType()) { case allPublic: folder.attributes().setAcl( new Acl(new Acl.GroupUser(Acl.GroupUser.EVERYONE, false), new Acl.Role(Acl.Role.READ))); } return new Path(folder.getParent(), folder.getName(), folder.getType(), new PathAttributes(folder.attributes())); } else { if (Checksum.NONE == status.getChecksum()) { status.setChecksum(writer.checksum(folder).compute(new NullInputStream(0L), status)); } status.setMime(MimeTypeService.DEFAULT_CONTENT_TYPE); new DefaultStreamCloser().close(writer.write(folder, status, new DisabledConnectionCallback())); final EnumSet<AbstractPath.Type> type = EnumSet.copyOf(folder.getType()); type.add(Path.Type.placeholder); return new Path(folder.getParent(), folder.getName(), type, new PathAttributes(folder.attributes())); } } catch (B2ApiException e) { throw new B2ExceptionMappingService().map("Cannot create folder {0}", e, folder); } catch (IOException e) { throw new DefaultIOExceptionMappingService().map(e); } }
From source file:com.nesscomputing.tracking.MockedHttpServletRequest.java
@Override public ServletInputStream getInputStream() throws IOException { final InputStream stream = new NullInputStream(getContentLength()); return new ServletInputStream() { @Override/*from w w w . j a v a 2 s. co m*/ public int read() throws IOException { return stream.read(); } }; }
From source file:com.talis.storage.AbstractStoreTest.java
@Test public void storedItemHasExpectedMetadata() throws Exception { Multimap<String, String> meta = ArrayListMultimap.create(); meta.put("key-0", "value-0"); meta.put("key-0", "value-1"); meta.put("key-1", "value-3"); SubmittedItem submitted = new SubmittedItem(MediaType.TEXT_XML_TYPE, new NullInputStream(1024), meta); StoredItem stored = store.write(itemURI, submitted); Multimap<String, String> storedMeta = stored.getMetadata(); assertItemMetadataEquals(meta, stored.getMetadata()); }
From source file:ch.sourcepond.maven.plugin.jenkins.process.RedirectStreamFactoryImpl.java
@Override public InputStream newStdin(final Config pConfig) throws IOException { final Path stdinPath = pConfig.getStdinOrNull(); final InputStream stdin; if (stdinPath != null) { stdin = wrapperFactory.wrapIfNecessary(pConfig.getStdinXsltOrNull(), newInputStream(stdinPath), pConfig.getStdinXsltParamsOrNull()); } else {/*from w ww. ja va 2 s. c om*/ stdin = new NullInputStream(0); } return stdin; }
From source file:com.opentable.requestid.MockedHttpServletRequest.java
@Override public ServletInputStream getInputStream() throws IOException { @SuppressWarnings("resource") final InputStream stream = new NullInputStream(getContentLength()); return new ServletInputStream() { @Override// ww w .ja v a 2s . c om public int read() throws IOException { return stream.read(); } @Override public boolean isFinished() { throw new UnsupportedOperationException(); } @Override public boolean isReady() { return true; } @Override public void setReadListener(ReadListener readListener) { throw new UnsupportedOperationException(); } }; }