本文整理汇总了Java中org.apache.commons.io.input.ClosedInputStream类的典型用法代码示例。如果您正苦于以下问题:Java ClosedInputStream类的具体用法?Java ClosedInputStream怎么用?Java ClosedInputStream使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ClosedInputStream类属于org.apache.commons.io.input包,在下文中一共展示了ClosedInputStream类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getResourceInputStream
import org.apache.commons.io.input.ClosedInputStream; //导入依赖的package包/类
@Override
protected InputStream getResourceInputStream(final Resource resource, final String entityId) throws IOException {
if (resource instanceof UrlResource && resource.getURL().toExternalForm().toLowerCase().endsWith("/entities/")) {
final String encodedId = EncodingUtils.urlEncode(entityId);
final URL url = new URL(resource.getURL().toExternalForm().concat(encodedId));
LOGGER.debug("Locating metadata input stream for [{}] via [{}]", encodedId, url);
final HttpURLConnection httpcon = (HttpURLConnection) url.openConnection();
httpcon.setDoOutput(true);
httpcon.addRequestProperty("Accept", "*/*");
httpcon.setRequestMethod("GET");
httpcon.connect();
return httpcon.getInputStream();
}
return ClosedInputStream.CLOSED_INPUT_STREAM;
}
示例2: testPumpInClosed
import org.apache.commons.io.input.ClosedInputStream; //导入依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void testPumpInClosed() {
final InputStream in = new ClosedInputStream();
final EventListener<String> nl = context.mock(EventListener.class, "nl");
final EventListener<Integer> pl = context.mock(EventListener.class, "pl");
final EventListener<IOException> el =
context.mock(EventListener.class, "el");
context.checking(new Expectations() {
{
never(nl).receive(with(any(Object.class)),
with(any(String.class)));
never(pl).receive(with(any(Object.class)),
with(any(Integer.class)));
never(el).receive(with(any(Object.class)),
with(any(IOException.class)));
}
});
final TileProgressPump p = new TileProgressPump(nl, pl, el);
p.setInputStream(in);
p.run();
}
示例3: testPumpInClosed
import org.apache.commons.io.input.ClosedInputStream; //导入依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void testPumpInClosed() {
final InputStream in = new ClosedInputStream();
final ByteArrayOutputStream out = new ByteArrayOutputStream();
final EventListener<IOException> el = context.mock(EventListener.class);
context.checking(new Expectations() {
{
never(el).receive(with(any(Object.class)),
with(any(IOException.class)));
}
});
final InputOutputStreamPump p = new InputOutputStreamPump(in, out, el);
p.run();
assertArrayEquals(new byte[0], out.toByteArray());
}
示例4: testPumpBothClosed
import org.apache.commons.io.input.ClosedInputStream; //导入依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void testPumpBothClosed() {
final InputStream in = new ClosedInputStream();
final OutputStream out = new ClosedOutputStream();
final EventListener<IOException> el = context.mock(EventListener.class);
context.checking(new Expectations() {
{
never(el).receive(with(any(Object.class)),
with(any(IOException.class)));
}
});
final InputOutputStreamPump p = new InputOutputStreamPump(in, out, el);
p.run();
}
示例5: toBufferedInputStream
import org.apache.commons.io.input.ClosedInputStream; //导入依赖的package包/类
/**
* Gets the current contents of this byte stream as a Input Stream. The
* returned stream is backed by buffers of <code>this</code> stream,
* avoiding memory allocation and copy, thus saving space and time.<br>
*
* @return the current contents of this output stream.
* @see java.io.ByteArrayOutputStream#toByteArray()
* @see #reset()
* @since Commons IO 2.0
*/
private InputStream toBufferedInputStream() {
int remaining = count;
if (remaining == 0) {
return new ClosedInputStream();
}
List<ByteArrayInputStream> list = new ArrayList<ByteArrayInputStream>(buffers.size());
for (byte[] buf : buffers) {
int c = Math.min(buf.length, remaining);
list.add(new ByteArrayInputStream(buf, 0, c));
remaining -= c;
if (remaining == 0) {
break;
}
}
return new SequenceInputStream(Collections.enumeration(list));
}
示例6: toBufferedInputStream
import org.apache.commons.io.input.ClosedInputStream; //导入依赖的package包/类
/**
* Gets the current contents of this byte stream as a Input Stream. The
* returned stream is backed by buffers of <code>this</code> stream,
* avoiding memory allocation and copy, thus saving space and time.<br>
*
* @return the current contents of this output stream.
* @see java.io.ByteArrayOutputStream#toByteArray()
* @see #reset()
* @since 2.0
*/
private InputStream toBufferedInputStream() {
int remaining = count;
if (remaining == 0) {
return new ClosedInputStream();
}
List<ByteArrayInputStream> list = new ArrayList<ByteArrayInputStream>(buffers.size());
for (byte[] buf : buffers) {
int c = Math.min(buf.length, remaining);
list.add(new ByteArrayInputStream(buf, 0, c));
remaining -= c;
if (remaining == 0) {
break;
}
}
return new SequenceInputStream(Collections.enumeration(list));
}
示例7: toInputStream
import org.apache.commons.io.input.ClosedInputStream; //导入依赖的package包/类
/**
* Gets the current contents of this byte stream as a Input Stream. The
* returned stream is backed by buffers of <code>this</code> stream,
* avoiding memory allocation and copy, thus saving space and time.<br>
*
* @return the current contents of this output stream.
* @see java.io.ByteArrayOutputStream#toByteArray()
* @see #reset()
* @since 2.5
*/
public synchronized InputStream toInputStream() {
int remaining = count;
if (remaining == 0) {
return new ClosedInputStream();
}
final List<ByteArrayInputStream> list = new ArrayList<ByteArrayInputStream>(buffers.size());
for (final byte[] buf : buffers) {
final int c = Math.min(buf.length, remaining);
list.add(new ByteArrayInputStream(buf, 0, c));
remaining -= c;
if (remaining == 0) {
break;
}
}
reuseBuffers = false;
return new SequenceInputStream(Collections.enumeration(list));
}
示例8: testSetInputStreamRunning
import org.apache.commons.io.input.ClosedInputStream; //导入依赖的package包/类
@Test(expected=UnsupportedOperationException.class)
public void testSetInputStreamRunning() {
final TileProgressPump p = new TPP();
p.run();
final InputStream in = new ClosedInputStream();
p.setInputStream(in);
}
示例9: testSetInputStreamRunning
import org.apache.commons.io.input.ClosedInputStream; //导入依赖的package包/类
@Test(expected=UnsupportedOperationException.class)
public void testSetInputStreamRunning() {
final InputOutputStreamPump p = new IOSP();
p.run();
final InputStream in = new ClosedInputStream();
p.setInputStream(in);
}
示例10: testCloseQuietlyImageInputStreamClosed
import org.apache.commons.io.input.ClosedInputStream; //导入依赖的package包/类
@Test
public void testCloseQuietlyImageInputStreamClosed() throws IOException {
final ImageInputStream in =
new MemoryCacheImageInputStream(new ClosedInputStream());
in.close();
IOUtils.closeQuietly(in);
}
示例11: close
import org.apache.commons.io.input.ClosedInputStream; //导入依赖的package包/类
@Override
public void close() throws IOException {
if (delegate != null) {
delegate.close();
}
//forget the reference to original inputstream to potentially free some memory
delegate = ClosedInputStream.CLOSED_INPUT_STREAM;
}
示例12: testSetInputStreamNotRunning
import org.apache.commons.io.input.ClosedInputStream; //导入依赖的package包/类
@Test
public void testSetInputStreamNotRunning() {
final TileProgressPump p = new TPP();
final InputStream in = new ClosedInputStream();
p.setInputStream(in);
}
示例13: testSetInputStreamNotRunning
import org.apache.commons.io.input.ClosedInputStream; //导入依赖的package包/类
@Test
public void testSetInputStreamNotRunning() {
final InputOutputStreamPump p = new InputOutputStreamPump();
final InputStream in = new ClosedInputStream();
p.setInputStream(in);
}
示例14: resolveEntity
import org.apache.commons.io.input.ClosedInputStream; //导入依赖的package包/类
@Override
public InputSource resolveEntity(String publicId, String systemId) {
return new InputSource(ClosedInputStream.CLOSED_INPUT_STREAM);
}
示例15: isClosed
import org.apache.commons.io.input.ClosedInputStream; //导入依赖的package包/类
public boolean isClosed() {
return delegate == ClosedInputStream.CLOSED_INPUT_STREAM;
}