@Override public int read(byte[] buffer, int byteOffset, int byteCount) throws IOException { synchronized (sharedRaf) { final long length = endOffset - offset; if (byteCount > length) { byteCount = (int) length; } sharedRaf.seek(offset); int count = sharedRaf.read(buffer, byteOffset, byteCount); if (count > 0) { offset += count; return count; } else { return -1; } } } @Override public long skip(long byteCount) throws IOException {
/** * Given a zip File input it will return its size Only works for zip files whose uncompressed size is less than 4 GB, otherwise returns * the size module 2^32, per gzip specifications * * @param myFile The zip file as input * @return zip file size as a long * * @throws IOException */ public static long zipFileSize(File myFile) throws IOException { try (RandomAccessFile raf = new RandomAccessFile(myFile, "r")) { raf.seek(raf.length() - 4); long b4 = raf.read(); long b3 = raf.read(); long b2 = raf.read(); long b1 = raf.read(); return (b1 << 24) | (b2 << 16) + (b3 << 8) + b4; } }
RandomAccessFile in = new RandomAccessFile("filename", "r"); int version = in.readInt(); byte type = in.readByte(); int beginOfData = in.readInt(); byte[] tempId; in.read(tempId, 0, 16); String id = new String(tempId);
public static boolean isEncrypted(File file) throws IOException { byte[] actualMagic = new byte[MultiCipherOutputStream.STREAM_MAGIC.length]; RandomAccessFile rFile = new RandomAccessFile(file, "r"); rFile.read(actualMagic); rFile.close(); return Arrays.equals(actualMagic, MultiCipherOutputStream.STREAM_MAGIC); }
final byte[] sig) throws IOException { boolean found = false; long off = archive.length() - minDistanceFromEnd; final long stopSearching = Math.max(0L, archive.length() - maxDistanceFromEnd); if (off >= 0) { for (; off >= stopSearching; off--) { archive.seek(off); int curr = archive.read(); if (curr == -1) { break; curr = archive.read(); if (curr == sig[POS_1]) { curr = archive.read(); if (curr == sig[POS_2]) { curr = archive.read(); if (curr == sig[POS_3]) { found = true; archive.seek(off);
public Void invoke(File f, VirtualChannel channel) throws IOException { try (OutputStream os = p.getOut(); OutputStream out = new java.util.zip.GZIPOutputStream(os, 8192); RandomAccessFile raf = new RandomAccessFile(reading(f), "r")) { raf.seek(offset); byte[] buf = new byte[8192]; int len; while ((len = raf.read(buf)) >= 0) { out.write(buf, 0, len); } return null; } } });
StringBuffer sb = new StringBuffer(); try { endPos = raf.length(); lastPos = endPos; raf.seek(endPos - 1); raf.read(oneByte); if ((char) oneByte[0] != '\n') { numOfLines++; pos = lastPos - BUFFERSIZE; raf.seek(pos); raf.seek(pos); if ((endPos - pos) < BUFFERSIZE) { int remainer = (int) (endPos - pos); info = buildDisplayingHeader(sb.length(), raf.length()); } catch (FileNotFoundException e) { sb = null; try { if (raf != null) { raf.close();
public ByteGramProvider(File file) throws IOException { RandomAccessFile raf = new RandomAccessFile(file, "r"); this.order = raf.readInt(); this.ngramCount = raf.readInt(); final int byteAmount = order * ngramCount * 4; data = new byte[byteAmount]; int actual = raf.read(data); if (actual != byteAmount) { throw new IllegalStateException( "File suppose to have " + byteAmount + " bytes for " + ngramCount + " ngrams"); } raf.close(); }
public static boolean isGZipped(File file) { try (RandomAccessFile inputFile = new RandomAccessFile(file, "r")) { int magic = inputFile.read() & 0xff | ((inputFile.read() << 8) & 0xff00); return magic == GZIP_MAGIC; } catch (IOException e) { throw new PrestoException(LOCAL_FILE_READ_ERROR, "Error reading file: " + file.getName(), e); } }
/** * Given a zip File input it will return its size * Only works for zip files whose uncompressed size is less than 4 GB, * otherwise returns the size module 2^32, per gzip specifications * * @param myFile The zip file as input * @return zip file size as a long * @throws IOException */ public static long zipFileSize(File myFile) throws IOException { RandomAccessFile raf = new RandomAccessFile(myFile, "r"); raf.seek(raf.length() - 4); long b4 = raf.read(); long b3 = raf.read(); long b2 = raf.read(); long b1 = raf.read(); long val = (b1 << 24) | (b2 << 16) + (b3 << 8) + b4; raf.close(); return val; }
@RequestHandler(RequestCmd.OBJECT_DOWNLOAD_HEAP_DUMP) public Pack downloadHeapDump(Pack param, DataInputX in, DataOutputX out) { int buff = 2 * 1024 * 1024; File downloadFile = new File(folderName + "/" + ((MapPack) param).getText("fileName")); try { RandomAccessFile raf = new RandomAccessFile(downloadFile, "r"); byte[] buffer = new byte[buff]; int read = 0; long offset = downloadFile.length(); int unitsize; while (read < offset) { unitsize = (int) (((offset - read) >= buff) ? buff : (offset - read)); raf.read(buffer, 0, unitsize); out.writeByte(TcpFlag.HasNEXT); out.writeBlob(buffer, 0, unitsize); read += unitsize; } raf.close(); return null; } catch (Throwable e) { e.printStackTrace(); } return null; }
byte[] sig) throws IOException { boolean found = false; long off = archive.length() - minDistanceFromEnd; final long stopSearching = Math.max(0L, archive.length() - maxDistanceFromEnd); if (off >= 0) { for (; off >= stopSearching; off--) { archive.seek(off); int curr = archive.read(); if (curr == -1) { break; curr = archive.read(); if (curr == sig[POS_1]) { curr = archive.read(); if (curr == sig[POS_2]) { curr = archive.read(); if (curr == sig[POS_3]) { found = true; archive.seek(off);
public byte[] getDiskBound() throws IOException { if (diskBound == null && diskBoundLocation != -1) { diskBound = new byte[length]; try(RandomAccessFile file = new RandomAccessFile(tmpFile, "r")) { file.seek(diskBoundLocation); file.read(diskBound); } diskBoundLocation = -1; } return diskBound; }
byte[] delim = new byte[3]; file.seek(file.length() - 3); for (int i = 0; i < STRUCTURE_INFO_MAX_SIZE; i++) { int read = file.read(delim); if (read == 3 && (delim[0] & 0xFF) == 255 && (delim[1] & 0xFF) == 255 && (delim[2] & 0xFF) == 255) { break; file.seek(file.getFilePointer() - 4); file.seek(file.getFilePointer() - 6); } else { file.seek(file.length() - 3);
public int readAllInOnce(ByteBuffer byteBuffer) throws IOException { if (byteBuffer.remaining() > raf.length()) { throw new IOException("trying to readAllInOnce past end of stream"); } byte[] buf = new byte[byteBuffer.remaining()]; int read = raf.read(buf); byteBuffer.put(buf, 0, read); return read; }