org.apache.poi.util.IOUtils.peekFirstNBytes()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(3.1k)|赞(0)|评价(0)|浏览(963)

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

IOUtils.peekFirstNBytes介绍

[英]Peeks at the first N bytes of the stream. Returns those bytes, but with the stream unaffected. Requires a stream that supports mark/reset, or a PushbackInputStream. If the stream has >0 but <N bytes, remaining bytes will be zero.
[中]查看流的前N个字节。返回这些字节,但流不受影响。需要支持标记/重置的流或PushbackInputStream。如果流的字节数大于0但小于N,则剩余的字节数将为零。

代码示例

代码示例来源:origin: org.apache.poi/poi

/**
 * Peeks at the first 8 bytes of the stream. Returns those bytes, but
 *  with the stream unaffected. Requires a stream that supports mark/reset,
 *  or a PushbackInputStream. If the stream has &gt;0 but &lt;8 bytes, 
 *  remaining bytes will be zero.
 * @throws EmptyFileException if the stream is empty
 */
public static byte[] peekFirst8Bytes(InputStream stream) throws IOException, EmptyFileException {
  return peekFirstNBytes(stream, 8);
}

代码示例来源:origin: org.apache.poi/poi

/**
 * Checks whether an {@link InputStream} is in the Horrible
 * Property Set Format.
 *
 * @param stream The {@link InputStream} to check. In order to
 * perform the check, the method reads the first bytes from the
 * stream. After reading, the stream is reset to the position it
 * had before reading. The {@link InputStream} must support the
 * {@link InputStream#mark} method.
 * @return {@code true} if the stream is a property set
 * stream, else {@code false}.
 * @exception IOException if an I/O error occurs
 */
public static boolean isPropertySetStream(final InputStream stream)
throws IOException {
  /*
   * Read at most this many bytes.
   */
  final int BUFFER_SIZE = 50;
  /*
   * Read a couple of bytes from the stream.
   */
  try {
    final byte[] buffer = IOUtils.peekFirstNBytes(stream, BUFFER_SIZE);
    return isPropertySetStream(buffer, 0, buffer.length);
  } catch (EmptyFileException e) {
    return false;
  }
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.poi

/**
 * Peeks at the first 8 bytes of the stream. Returns those bytes, but
 *  with the stream unaffected. Requires a stream that supports mark/reset,
 *  or a PushbackInputStream. If the stream has &gt;0 but &lt;8 bytes, 
 *  remaining bytes will be zero.
 * @throws EmptyFileException if the stream is empty
 */
public static byte[] peekFirst8Bytes(InputStream stream) throws IOException, EmptyFileException {
  return peekFirstNBytes(stream, 8);
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.poi

/**
 * Checks whether an {@link InputStream} is in the Horrible
 * Property Set Format.
 *
 * @param stream The {@link InputStream} to check. In order to
 * perform the check, the method reads the first bytes from the
 * stream. After reading, the stream is reset to the position it
 * had before reading. The {@link InputStream} must support the
 * {@link InputStream#mark} method.
 * @return {@code true} if the stream is a property set
 * stream, else {@code false}.
 * @exception IOException if an I/O error occurs
 */
public static boolean isPropertySetStream(final InputStream stream)
throws IOException {
  /*
   * Read at most this many bytes.
   */
  final int BUFFER_SIZE = 50;
  /*
   * Read a couple of bytes from the stream.
   */
  try {
    final byte[] buffer = IOUtils.peekFirstNBytes(stream, BUFFER_SIZE);
    return isPropertySetStream(buffer, 0, buffer.length);
  } catch (EmptyFileException e) {
    return false;
  }
}

相关文章