@Override public boolean markSupported() { abortIfNeeded(); return super.markSupported(); } }
private static Reader getUTF8Reader(InputStream f) throws IOException { BufferedInputStream bis = new BufferedInputStream(f); assert bis.markSupported(); bis.mark(3); boolean reset = true; byte[] t = new byte[3]; bis.read(t); if (t[0] == ((byte) 0xef) && t[1] == ((byte) 0xbb) && t[2] == ((byte) 0xbf)) { reset = false; } if (reset) { bis.reset(); } return new InputStreamReader(bis, "UTF-8"); }
if ("jar".equals(archiveExt) && in.markSupported()) { in.mark(7); final byte[] b = new byte[7];
public static FileType detectFileType(@NotNull final BufferedInputStream inputStream) throws IOException if (!inputStream.markSupported()) throw new IOException("Stream must support mark/reset");
assert buffInStream.markSupported(); buffInStream.mark(10000);
assert buffInStream.markSupported(); buffInStream.mark(10000);
@Override public boolean markSupported() { abortIfNeeded(); return super.markSupported(); } }
/** * Examines the a file's first bytes and estimates the file's type. * <p> * Requires a {@link BufferedInputStream} in order to mark and reset the stream to the position * at which it was provided to this method once completed. * <p> * Requires the stream to contain at least eight bytes. * * @param inputStream a buffered input stream of the file to examine. * @return the file type. * @throws IOException if an IO error occurred or the input stream ended unexpectedly. */ public static FileType detectFileType(final BufferedInputStream inputStream) throws IOException { if (!inputStream.markSupported()) { throw new IOException("Stream must support mark/reset"); } int maxByteCount = root.getMaxDepth(); inputStream.mark(maxByteCount); byte[] bytes = new byte[maxByteCount]; int bytesRead = inputStream.read(bytes); if (bytesRead == -1) { throw new IOException("Stream ended before file's magic number could be determined."); } inputStream.reset(); //noinspection ConstantConditions return root.find(bytes); }
@Test public void basicReadAndWriteObjectTest() throws Exception { DataObject thingy = new DataObject(); thingy.type = 'a'; thingy.time = new Date().getTime(); thingy.strCount = "1"; byte [] bytes = marshallThingy(thingy); ByteArrayInputStream bais = new ByteArrayInputStream(bytes); BufferedInputStream bis = new BufferedInputStream(bais); ObjectInputStream stream = new ObjectInputStream(bis); DataObject unmaThingy = new DataObject(); unmaThingy.type = stream.readChar(); unmaThingy.time = stream.readLong(); assertTrue( "Mark/reset is not supported", bis.markSupported() ); bis.mark(8); int [] intBytes = new int [4]; intBytes[0] = bis.read(); intBytes[1] = bis.read(); intBytes[2] = bis.read(); intBytes[3] = bis.read(); if ((intBytes[0] | intBytes[1] | intBytes[2] | intBytes[3] ) < 0) { bis.reset(); } unmaThingy.strCount = stream.readUTF(); assertTrue( thingy.equals(unmaThingy) ); }
@Override public boolean markSupported() { return is.markSupported(); }
@Override public boolean markSupported() { return inputBuffer.markSupported(); }
@Override public boolean markSupported() { return result.markSupported(); }
public boolean markSupported() { return in.markSupported(); }
@Override public boolean markSupported() { abortIfNeeded(); return super.markSupported(); } }
@Override public boolean markSupported() { abortIfNeeded(); return super.markSupported(); } }
@Override public boolean markSupported() { abortIfNeeded(); return super.markSupported(); } }
@Override public boolean markSupported() { abortIfNeeded(); return super.markSupported(); } }
@Override public boolean markSupported() { requireCurrent(); return current.markSupported(); }
@Override public boolean markSupported() { log("markSupported()"); return super.markSupported(); }
@Override public boolean markSupported() { abortIfNeeded(); return super.markSupported(); } }