org.apache.commons.io.IOUtils.buffer()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(6.7k)|赞(0)|评价(0)|浏览(235)

本文整理了Java中org.apache.commons.io.IOUtils.buffer()方法的一些代码示例,展示了IOUtils.buffer()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。IOUtils.buffer()方法的具体详情如下:
包路径:org.apache.commons.io.IOUtils
类名称:IOUtils
方法名:buffer

IOUtils.buffer介绍

[英]Returns the given InputStream if it is already a BufferedInputStream, otherwise creates a BufferedInputStream from the given InputStream.
[中]如果给定InputStream已经是BufferedInputStream,则返回该InputStream,否则将从给定InputStream创建BufferedInputStream。

代码示例

代码示例来源:origin: commons-io/commons-io

@Test public void testAsBufferedInputStreamWithBufferSize() {
  final InputStream is = new InputStream() {
    @Override
    public int read() throws IOException {
      return 0;
    }
  };
  final BufferedInputStream bis = IOUtils.buffer(is, 2048);
  assertNotSame(is, bis);
  assertSame(bis, IOUtils.buffer(bis));
  assertSame(bis, IOUtils.buffer(bis, 1024));
}

代码示例来源:origin: commons-io/commons-io

@Test public void testAsBufferedOutputStreamWithBufferSize() {
  final OutputStream os = new OutputStream() {
    @Override
    public void write(final int b) throws IOException { }
  };
  final BufferedOutputStream bos = IOUtils.buffer(os, 2048);
  assertNotSame(os, bos);
  assertSame(bos, IOUtils.buffer(bos));
  assertSame(bos, IOUtils.buffer(bos, 1024));
}

代码示例来源:origin: commons-io/commons-io

@Test public void testAsBufferedInputStream() {
  final InputStream is = new InputStream() {
    @Override
    public int read() throws IOException {
      return 0;
    }
  };
  final BufferedInputStream bis = IOUtils.buffer(is);
  assertNotSame(is, bis);
  assertSame(bis, IOUtils.buffer(bis));
}

代码示例来源:origin: commons-io/commons-io

@Test public void testAsBufferedOutputStream() {
  final OutputStream is = new OutputStream() {
    @Override
    public void write(final int b) throws IOException { }
  };
  final BufferedOutputStream bis = IOUtils.buffer(is);
  assertNotSame(is, bis);
  assertSame(bis, IOUtils.buffer(bis));
}

代码示例来源:origin: commons-io/commons-io

@Test public void testAsBufferedReaderWithBufferSize() {
  final Reader r = new Reader() {
    @Override
    public int read(final char[] cbuf, final int off, final int len) throws IOException {
      return 0;
    }
    @Override
    public void close() throws IOException { }
  };
  final BufferedReader br = IOUtils.buffer(r, 2048);
  assertNotSame(r, br);
  assertSame(br, IOUtils.buffer(br));
  assertSame(br, IOUtils.buffer(br, 1024));
}

代码示例来源:origin: commons-io/commons-io

@Test
public void testAsBufferedWriterWithBufferSize() {
  final Writer w = new Writer() {
    @Override
    public void write(final int b) throws IOException { }
    @Override
    public void write(final char[] cbuf, final int off, final int len) throws IOException { }
    @Override
    public void flush() throws IOException { }
    @Override
    public void close() throws IOException { }
  };
  final BufferedWriter bw = IOUtils.buffer(w, 2024);
  assertNotSame(w, bw);
  assertSame(bw, IOUtils.buffer(bw));
  assertSame(bw, IOUtils.buffer(bw, 1024));
}

代码示例来源:origin: commons-io/commons-io

@Test public void testAsBufferedReader() {
  final Reader is = new Reader() {
    @Override
    public int read(final char[] cbuf, final int off, final int len) throws IOException {
      return 0;
    }
    @Override
    public void close() throws IOException { }
  };
  final BufferedReader bis = IOUtils.buffer(is);
  assertNotSame(is, bis);
  assertSame(bis, IOUtils.buffer(bis));
}

代码示例来源:origin: commons-io/commons-io

@Test public void testAsBufferedWriter() {
  final Writer is = new Writer() {
    @Override
    public void write(final int b) throws IOException { }
    @Override
    public void write(final char[] cbuf, final int off, final int len) throws IOException { }
    @Override
    public void flush() throws IOException { }
    @Override
    public void close() throws IOException { }
  };
  final BufferedWriter bis = IOUtils.buffer(is);
  assertNotSame(is, bis);
  assertSame(bis, IOUtils.buffer(bis));
}

代码示例来源:origin: commons-io/commons-io

@Test public void testAsBufferedNull() {
  try {
    IOUtils.buffer((InputStream) null);
    fail("Expected NullPointerException");
  } catch (final NullPointerException npe) {
    // expected
  }
  try {
    IOUtils.buffer((OutputStream) null);
    fail("Expected NullPointerException");
  } catch (final NullPointerException npe) {
    // expected
  }
  try {
    IOUtils.buffer((Reader) null);
    fail("Expected NullPointerException");
  } catch (final NullPointerException npe) {
    // expected
  }
  try {
    IOUtils.buffer((Writer) null);
    fail("Expected NullPointerException");
  } catch (final NullPointerException npe) {
    // expected
  }
}

代码示例来源:origin: sutra/okcoin-client

/**
 * {@inheritDoc}
 */
@Override
public T read(InputStream inputStream,
  @Nullable String mimeType, @Nullable Charset charset) throws IOException {
  if (log.isLoggable(Level.FINEST)) {
    inputStream = IOUtils.buffer(inputStream);
    inputStream.mark(Integer.MAX_VALUE);
    String s = IOUtils.toString(inputStream, charset != null ? charset : StandardCharsets.UTF_8);
    log.log(Level.FINEST, "JSON: {0}", s);
    inputStream.reset();
  }
  try {
    return objectMapper.readValue(inputStream, valueTypeRef);
  } catch (JsonMappingException jme) {
    if (jme.getCause() instanceof RuntimeException) {
      throw (RuntimeException) jme.getCause();
    } else {
      throw jme;
    }
  }
}

代码示例来源:origin: GluuFederation/oxAuth

public void saveCertificate(X509Certificate certificate) {
  try {
    Writer writer = IOUtils.buffer(new FileWriter(new File("/tmp/cert-" + certificate.getSerialNumber() + ".crt")));
    JcaPEMWriter pemWriter = new JcaPEMWriter(writer);
    try {
      pemWriter.writeObject(certificate);
      pemWriter.flush();
    } finally {
      IOUtils.closeQuietly(pemWriter);
    }
  } catch (IOException e) {
    throw new Fido2RPRuntimeException("Failed to write root certificate");
  }
}

代码示例来源:origin: org.codehaus.izpack/izpack-installer

/**
 * Unpacks a pack packFile.
 *
 * @param packFile            the pack packFile meta-data
 * @param packInputStream the pack input stream
 * @param target          the target
 * @throws IOException        for any I/O error
 * @throws InstallerException for any installer exception
 */
@Override
public void unpack(PackFile packFile, InputStream packInputStream, File target)
    throws IOException, InstallerException
{
  InputStream in = IOUtils.buffer(packInputStream);
  JarOutputStream jarOut = null;
  try
  {
    jarOut = new JarOutputStream(getTarget(packFile, target));
    Pack200.Unpacker unpacker = createPack200Unpacker(packFile);
    unpacker.unpack(in, jarOut);
  }
  finally
  {
    IOUtils.closeQuietly(jarOut);
    IOUtils.closeQuietly(in);
  }
  postCopy(packFile);
}

代码示例来源:origin: org.codehaus.izpack/izpack-installer

fo = IOUtils.buffer(FileUtils.openOutputStream(tmpfile));
final long bytesUnpacked = IOUtils.copyLarge(packInputStream, fo, 0, file.size());
fo.flush();
InputStream in = IOUtils.buffer(FileUtils.openInputStream(tmpfile));

代码示例来源:origin: webanno/webanno

try (BufferedInputStream bis = IOUtils.buffer(uploadedFile.getInputStream())) {
  byte[] buf = new byte[5];
  bis.mark(buf.length + 1);

代码示例来源:origin: de.tudarmstadt.ukp.clarin.webanno/webanno-ui-project

try (BufferedInputStream bis = IOUtils.buffer(uploadedFile.getInputStream())) {
  byte[] buf = new byte[5];
  bis.mark(buf.length + 1);

代码示例来源:origin: org.codehaus.izpack/izpack-compiler

InputStream originalInputStream = IOUtils.buffer(FileUtils.openInputStream(archive));
  uncompressedInputStream = IOUtils.buffer(new CompressorStreamFactory().createCompressorInputStream(originalInputStream));

代码示例来源:origin: org.codehaus.izpack/izpack-compiler

OutputStream bufferedStream = IOUtils.buffer(proxyOutputStream);
OutputStream bufferedStream = IOUtils.buffer(proxyOutputStream);

相关文章