/** * Determine heuristically whether a byte array represents binary (as * opposed to text) content. * * @param raw * the raw file content. * @return true if raw is likely to be a binary file, false otherwise */ public static boolean isBinary(byte[] raw) { return isBinary(raw, raw.length); }
private boolean fillBuffer() throws IOException { cnt = in.read(buf, 0, buf.length); if (cnt < 1) return false; if (detectBinary) { isBinary = RawText.isBinary(buf, cnt); detectBinary = false; } ptr = 0; return true; } }
/** * Determine heuristically whether the bytes contained in a stream * represents binary (as opposed to text) content. * * Note: Do not further use this stream after having called this method! The * stream may not be fully read and will be left at an unknown position * after consuming an unknown number of bytes. The caller is responsible for * closing the stream. * * @param raw * input stream containing the raw file content. * @return true if raw is likely to be a binary file, false otherwise * @throws java.io.IOException * if input stream could not be read */ public static boolean isBinary(InputStream raw) throws IOException { final byte[] buffer = new byte[FIRST_FEW_BYTES]; int cnt = 0; while (cnt < buffer.length) { final int n = raw.read(buffer, cnt, buffer.length - cnt); if (n == -1) break; cnt += n; } return isBinary(buffer, cnt); }
private void decideMode() throws IOException { if (detectBinary) { isBinary = RawText.isBinary(binbuf, binbufcnt); detectBinary = false; } int cachedLen = binbufcnt; binbufcnt = binbuf.length + 1; // full! write(binbuf, 0, cachedLen); }
private void decideMode() throws IOException { if (detectBinary) { isBinary = RawText.isBinary(binbuf, binbufcnt); detectBinary = false; } int cachedLen = binbufcnt; binbufcnt = binbuf.length + 1; // full! write(binbuf, 0, cachedLen); }
private boolean fillBuffer() throws IOException { cnt = in.read(buf, 0, buf.length); if (cnt < 1) return false; if (detectBinary) { isBinary = RawText.isBinary(buf, cnt); detectBinary = false; if (isBinary && abortIfBinary) throw new IsBinaryException(); } ptr = 0; return true; } }
void hash(byte[] raw, int ptr, int end) throws TableFullException { final boolean text = !RawText.isBinary(raw); hashedCnt = 0; while (ptr < end) { int hash = 5381; int blockHashedCnt = 0; int start = ptr; // Hash one line, or one block, whichever occurs first. do { int c = raw[ptr++] & 0xff; // Ignore CR in CRLF sequence if text if (text && c == '\r' && ptr < end && raw[ptr] == '\n') continue; blockHashedCnt++; if (c == '\n') break; hash = (hash << 5) + hash + c; } while (ptr < end && ptr - start < 64); hashedCnt += blockHashedCnt; add(hash, blockHashedCnt); } }
private static boolean isBinary(Entry entry) throws IOException { InputStream in = entry.openInputStream(); try { return RawText.isBinary(in); } finally { safeClose(in); } }
private void hashLargeObject(ObjectLoader obj) throws IOException, TableFullException { boolean text; try (ObjectStream in1 = obj.openStream()) { text = !RawText.isBinary(in1); } try (ObjectStream in2 = obj.openStream()) { hash(in2, in2.getSize(), text); } }
if (isBinary(data)) { throw new BinaryBlobException();
/** * Determine heuristically whether a byte array represents binary (as * opposed to text) content. * * @param raw * the raw file content. * @return true if raw is likely to be a binary file, false otherwise */ public static boolean isBinary(byte[] raw) { return isBinary(raw, raw.length); }
/** * Determine heuristically whether a byte array represents binary (as * opposed to text) content. * * @param raw * the raw file content. * @return true if raw is likely to be a binary file, false otherwise */ public static boolean isBinary(byte[] raw) { return isBinary(raw, raw.length); }
private boolean fillBuffer() throws IOException { cnt = in.read(buf, 0, buf.length); if (cnt < 1) return false; if (detectBinary) { isBinary = RawText.isBinary(buf, cnt); detectBinary = false; } ptr = 0; return true; } }
private boolean fillBuffer() throws IOException { cnt = in.read(buf, 0, buf.length); if (cnt < 1) return false; if (detectBinary) { isBinary = RawText.isBinary(buf, cnt); detectBinary = false; } ptr = 0; return true; } }
private void decideMode() throws IOException { if (detectBinary) { isBinary = RawText.isBinary(binbuf, binbufcnt); detectBinary = false; } int cachedLen = binbufcnt; binbufcnt = binbuf.length + 1; // full! write(binbuf, 0, cachedLen); }
private void decideMode() throws IOException { if (detectBinary) { isBinary = RawText.isBinary(binbuf, binbufcnt); detectBinary = false; } int cachedLen = binbufcnt; binbufcnt = binbuf.length + 1; // full! write(binbuf, 0, cachedLen); }
private void decideMode() throws IOException { if (detectBinary) { isBinary = RawText.isBinary(binbuf, binbufcnt); detectBinary = false; } int cachedLen = binbufcnt; binbufcnt = binbuf.length + 1; // full! write(binbuf, 0, cachedLen); }
private static boolean isBinary(Entry entry) throws IOException { InputStream in = entry.openInputStream(); try { return RawText.isBinary(in); } finally { safeClose(in); } }
private static boolean isBinary(Entry entry) throws IOException { InputStream in = entry.openInputStream(); try { return RawText.isBinary(in); } finally { safeClose(in); } }
private void hashLargeObject(ObjectLoader obj) throws IOException, TableFullException { boolean text; try (ObjectStream in1 = obj.openStream()) { text = !RawText.isBinary(in1); } try (ObjectStream in2 = obj.openStream()) { hash(in2, in2.getSize(), text); } }