/** * 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 >0 but <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); }
/** * 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; } }
/** * 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 >0 but <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); }
/** * 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; } }