private byte[] readFile(File file) throws IOException { RandomAccessFile raf = new RandomAccessFile(file, "r"); byte[] buffer = new byte[(int) raf.length()]; raf.readFully(buffer); raf.close(); return buffer; }
public static byte[] readBytes(File file, int fixedLength) throws IOException { if (!file.exists()) { throw new FileNotFoundException(MSG_NOT_FOUND + file); } if (!file.isFile()) { throw new IOException(MSG_NOT_A_FILE + file); } long len = file.length(); if (len >= Integer.MAX_VALUE) { throw new IOException("File is larger then max array size"); } if (fixedLength > -1 && fixedLength < len) { len = fixedLength; } byte[] bytes = new byte[(int) len]; RandomAccessFile randomAccessFile = new RandomAccessFile(file, "r"); randomAccessFile.readFully(bytes); randomAccessFile.close(); return bytes; }
try (RandomAccessFile raf = new RandomAccessFile(file, "r")) { long len = raf.length(); raf.seek(pos); raf.readFully(tail);
public static int readRange(File f, int pos, byte[] buf, int at, int len) { try { if (f == null || !f.exists()) return 0; long fsize = f.length(); if (pos > fsize) return 0; len = Math.min(len, buf.length - at); if (pos + len > fsize) { len = (int)(fsize - pos); } RandomAccessFile raf = new RandomAccessFile(f, "r"); raf.seek(pos); raf.readFully(buf, at, len); raf.close(); return len; } catch (IOException e) { return -1; } }
StringBuffer sb = new StringBuffer(); try { endPos = raf.length(); lastPos = endPos; raf.seek(endPos - 1); raf.read(oneByte); if ((char) oneByte[0] != '\n') { pos = lastPos - BUFFERSIZE; raf.seek(pos); buffer = new byte[remainer]; raf.readFully(buffer); raf.seek(pos); if ((endPos - pos) < BUFFERSIZE) { int remainer = (int) (endPos - pos); buffer = new byte[remainer]; raf.readFully(buffer); sb.append(new String(buffer)); info = buildDisplayingHeader(sb.length(), raf.length()); } catch (FileNotFoundException e) { sb = null;
@Signature public Memory readFully(Environment env, Memory... args){ if (!canRead) throwCannotRead(env); long len = 0; try { len = accessFile.length() - position; if (len <= 0) return Memory.FALSE; byte[] buff = new byte[(int)len]; accessFile.readFully(buff); position += len; return new BinaryMemory(buff); } catch (IOException e) { return Memory.FALSE; } }
static ByteBuffer readFileToByteBuffer(File file) throws IOException { RandomAccessFile randomAccessFile = null; try { randomAccessFile = new RandomAccessFile(file, "r"); byte[] bytes = new byte[(int) randomAccessFile.length()]; randomAccessFile.readFully(bytes); return ByteBuffer.wrap(bytes); } finally { if (randomAccessFile != null) randomAccessFile.close(); } }
void addPatchFile(String zipFileName) throws IOException { File file = new File(zipFileName); RandomAccessFile f = new RandomAccessFile(file, "r"); long fileLength = f.length(); f.seek(0); f.seek(searchStart); ByteBuffer bbuf = ByteBuffer.allocate((int) readAmount); byte[] buffer = bbuf.array(); f.readFully(buffer); bbuf.order(ByteOrder.LITTLE_ENDIAN);
return null; final RandomAccessFile raf = new RandomAccessFile(file, "r"); final byte[] a = new byte[mb]; try { raf.seek(0); raf.readFully(a, 0, mb); digest.update(a, 0, mb); raf.seek(fl - mb); raf.readFully(a, 0, mb); digest.update(a, 0, mb); digest.update(longToBytes(fl), 0, 8);
long scanOffset = raf.length() - ENDHDR; if (scanOffset < 0) { throw new ZipException("File too short to be a zip file: " + raf.length()); raf.seek(0); final int headerMagic = Integer.reverseBytes(raf.readInt()); if (headerMagic != LOCSIG) { raf.seek(scanOffset); if (Integer.reverseBytes(raf.readInt()) == ENDSIG) { break; raf.readFully(eocd); raf.readFully(commentBytes); comment = new String(commentBytes, 0, commentBytes.length, StandardCharsets.UTF_8);
RandomAccessFile fp = null; try { fp = new RandomAccessFile(libc, "r"); fp.readFully(data); int machine = (data[19] << 8) | data[18]; switch (machine) {
RandomAccessFile raf = new RandomAccessFile("d:\\host.pk8", "r"); byte[] buf = new byte[(int)raf.length()]; raf.readFully(buf); raf.close(); PKCS8EncodedKeySpec kspec = new PKCS8EncodedKeySpec(buf); KeyFactory kf = KeyFactory.getInstance("RSA"); PrivateKey privKey = kf.generatePrivate(kspec);
void addPatchFile(String zipFileName) throws IOException { File file = new File(zipFileName); RandomAccessFile f = new RandomAccessFile(file, "r"); long fileLength = f.length(); f.seek(0); f.seek(searchStart); ByteBuffer bbuf = ByteBuffer.allocate((int) readAmount); byte[] buffer = bbuf.array(); f.readFully(buffer); bbuf.order(ByteOrder.LITTLE_ENDIAN);
/** * Read len bytes from file beginning from offset. Since it's really a * ByteArrayInputStream, close() operation is optional */ private synchronized InputStream createInputStream(long offset, int len) throws IOException { fileAccess.seek(offset); byte[] b = new byte[len]; // TODO performance? fileAccess.readFully(b); return new ByteArrayInputStream(b); }
if(!indexFile.exists() || !dataFile.exists()) break; RandomAccessFile index = new RandomAccessFile(indexFile, "r"); RandomAccessFile data = new RandomAccessFile(dataFile, "r"); try { while(true) { index.readFully(keyMd5); position = index.readInt(); data.seek(position); int size = data.readInt(); byte[] value = new byte[size]; data.readFully(value); System.out.println(ByteUtils.toHexString(keyMd5) + "\t=>\t" + serializer.toObject(value).toString());
/** * Read file and returns byte array with contents. * * @param file {@link File} to read * @param count number of bytes to read * @return byte array from {@link File} contents. * @throws IOException if not a {@link File} or {@link File} does not exist or file size is * larger than {@link Integer#MAX_VALUE}. */ public static byte[] readBytes(final File file, final int count) throws IOException { checkExists(file); checkIsFile(file); long numToRead = file.length(); if (numToRead >= Integer.MAX_VALUE) { throw new IOException("File is larger then max array size"); } if (count > NEGATIVE_ONE && count < numToRead) { numToRead = count; } byte[] bytes = new byte[(int) numToRead]; RandomAccessFile randomAccessFile = new RandomAccessFile(file, "r"); randomAccessFile.readFully(bytes); randomAccessFile.close(); return bytes; }