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);
static void modify(File file) throws IOException { long size = file.length(); if (size == 0) { recreateZeroSizeFile(file); return; } RandomAccessFile accessFile = new RandomAccessFile(file, "rwd"); accessFile.seek(size - 1); byte lastByte = accessFile.readByte(); accessFile.seek(size - 1); accessFile.write(lastByte); accessFile.close(); }
RandomAccessFile f = new RandomAccessFile(fileName, "rw"); long length = f.length() - 1; do { length -= 1; f.seek(length); byte b = f.readByte(); } while(b != 10); f.setLength(length+1); f.close();
public void markRecordAsNoop(long offset) throws IOException { // First ensure that the offset actually is an OP_RECORD. There is a // small possibility that it still is OP_RECORD, // but is not actually the beginning of a record. Is there anything we // can do about it? fileHandle.seek(offset); byte byteRead = fileHandle.readByte(); Preconditions.checkState(byteRead == OP_RECORD || byteRead == OP_NOOP, "Expected to read a record but the byte read indicates EOF"); fileHandle.seek(offset); LOG.info("Marking event as " + OP_NOOP + " at " + offset + " for file " + file.toString()); fileHandle.writeByte(OP_NOOP); }
int readByte = fileHandler.readByte();
int readByte = fileHandler.readByte();
byte c = raf.readByte(); if(c == '\n'){
@Override public int readByte(int offset) { checkRead(offset, BYTE); try { seekToOffset(offset); return randomAccessFile.readByte(); } catch (IOException e) { throw new RuntimeException(e); } }
for (long i = raf.length() - 1; i > b.length + skip - 1; i--) { raf.seek(i - b.length); byte temp = raf.readByte(); raf.seek(i); raf.writeByte(temp);
/** * Checks whether a file is terminated with exactly one trailing newline. * * @param inputFile the file to check for a trailing newline * @return true if file is terminated with exactly one newline * @throws IOException if the file cannot be read */ public static boolean singleNewlineTerminated(File inputFile) throws IOException { RandomAccessFile randomAccessFile = new RandomAccessFile(inputFile, READ_ONLY_MODE); // Zero terminating newlines if (inputFile.length() < 1) { return true; } randomAccessFile.seek(inputFile.length() - 1); if (Byte.compare(randomAccessFile.readByte(), NEWLINE_DELIMITER) != 0) { return false; } // File contains a single newline character and nothing else if (inputFile.length() < 2) { return true; } // More than one terminating newline randomAccessFile.seek(inputFile.length() - 2); return (Byte.compare(randomAccessFile.readByte(), NEWLINE_DELIMITER) != 0); }
byte readByte = fileHandler.readByte();
@Override public byte readByte() throws IOException { try { return getRaf().readByte(); } catch (IOException ioe) { handleException(); throw ioe; } }
Preconditions.checkState(offset >= 0); while (offset < fileHandle.length()) { byte operation = fileHandle.readByte(); if (operation == OP_RECORD) { break;
byte version = file.readByte(); if (version == VERSION_GZIP) { byte[] data = new byte[length - 1];
byte pr_dmodel = pstatus.readByte();
try { fileHandle.seek(offset); byte operation = fileHandle.readByte(); if (operation == OP_NOOP) { throw new NoopRecordException("No op record found. Corrupt record " +
public byte readByte() throws IOException { return delegate.readByte(); } public char readChar() throws IOException { return delegate.readChar(); }