public void open(File outputFile) throws IOException { outputFile.mkdirs(); if (outputFile.exists()) { outputFile.delete(); } outputFile.createNewFile(); outputRAF = new RandomAccessFile(outputFile, "rw"); outputRAF.setLength(mappedFileSizeBytes); outputRAF.seek(mappedFileSizeBytes - 1); outputRAF.writeByte(0); outputRAF.seek(0); outputChannel = outputRAF.getChannel(); fileBuffer = outputChannel.map(FileChannel.MapMode.READ_WRITE, 0, mappedFileSizeBytes); }
private void writeSector(int sectorNumber, byte[] data, int length) throws IOException { file.seek(sectorNumber * SECTOR_BYTES); file.writeInt(length + 1); // chunk length file.writeByte(VERSION_DEFLATE); // chunk version number file.write(data, 0, length); // chunk data }
@SuppressWarnings("unchecked") public void open(File inputFile) throws IOException { deserializer = (Deserializer<OUT>) (readAsByteArray ? new ByteArrayDeserializer() : new TupleDeserializer()); inputFile.getParentFile().mkdirs(); if (inputFile.exists()) { inputFile.delete(); } inputFile.createNewFile(); inputRAF = new RandomAccessFile(inputFile, "rw"); inputRAF.setLength(mappedFileSizeBytes); inputRAF.seek(mappedFileSizeBytes - 1); inputRAF.writeByte(0); inputRAF.seek(0); inputChannel = inputRAF.getChannel(); fileBuffer = inputChannel.map(FileChannel.MapMode.READ_WRITE, 0, mappedFileSizeBytes); }
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); }
@Override public Bytes writeByte(int offset, int b) { checkWrite(offset, BYTE); try { seekToOffset(offset); randomAccessFile.writeByte(b); } catch (IOException e) { throw new RuntimeException(e); } return this; }
byte temp = raf.readByte(); raf.seek(i); raf.writeByte(temp);
@Override public void writeByte(int i) throws IOException { try { getRaf().writeByte(i); } catch (IOException ioe) { handleException(); throw ioe; } }
public void testEqual() throws IOException { File asciiFile = getTestFile("ascii.txt"); File i18nFile = getTestFile("i18n.txt"); assertFalse(Files.equal(asciiFile, i18nFile)); assertTrue(Files.equal(asciiFile, asciiFile)); File temp = createTempFile(); Files.copy(asciiFile, temp); assertTrue(Files.equal(asciiFile, temp)); Files.copy(i18nFile, temp); assertTrue(Files.equal(i18nFile, temp)); Files.copy(asciiFile, temp); RandomAccessFile rf = new RandomAccessFile(temp, "rw"); rf.writeByte(0); rf.close(); assertEquals(asciiFile.length(), temp.length()); assertFalse(Files.equal(asciiFile, temp)); assertTrue(Files.asByteSource(asciiFile).contentEquals(Files.asByteSource(asciiFile))); // 0-length files have special treatment (/proc, etc.) assertTrue(Files.equal(asciiFile, new BadLengthFile(asciiFile, 0))); }
public void writeByte(int v) throws IOException { delegate.writeByte(v); } public void writeShort(int v) throws IOException { delegate.writeShort(v); }
public void add(final String key) throws IOException { if (this.keys.containsKey(key)) return; synchronized (this.raf) { if (this.keys.containsKey(key)) return; // check again for those threads who come late (after another has written this) this.keys.put(key, _obj); this.raf.seek(this.raf.length()); this.raf.write(key.getBytes(StandardCharsets.UTF_8)); this.raf.writeByte('\n'); } }
raf.writeBoolean((Boolean) value); } else if (binding == Byte.class || binding == byte.class) { raf.writeByte((Byte) value); } else if (binding == Short.class || binding == short.class) { raf.writeShort((Short) value);
public void write (int b) throws IOException { //IJ.log("stream: byte"); raFile.writeByte(b); //just for completeness, usually not used by image encoders } public void write (byte[] b) throws IOException {
public DBT_fpt(DBF iDBF, String name, boolean destroy) throws IOException, xBaseJException { super(iDBF, name, destroy, DBF.FOXPRO_WITH_MEMO); nextBlock = 8; file.writeInt(nextBlock); file.writeByte(0); file.writeByte(0); memoBlockSize = 64; file.writeShort(memoBlockSize); for (int i = 0; i < 504; i += 4) file.writeInt(0); }
@Override public synchronized void putByte(long offset, byte value) { if (CC.VOLUME_PRINT_STACK_AT_OFFSET != 0 && CC.VOLUME_PRINT_STACK_AT_OFFSET == offset) { new IOException("VOL STACK:").printStackTrace(); } try { raf.seek(offset); raf.writeByte(value); } catch (IOException e) { throw new DBException.VolumeIOError(e); } }
public void setNextBlock() throws IOException { if (file.length() == 0) { file.writeInt(DbaseUtils.x86(1)); nextBlock = 1; file.seek(511); file.writeByte(0); } else { nextBlock = DbaseUtils.x86(file.readInt()); } }
public DBT_iv(DBF iDBF, String name, boolean destroy) throws IOException, xBaseJException { super(iDBF, name, destroy, DBF.DBASEIV_WITH_MEMO); nextBlock = 1; file.writeInt(DbaseUtils.x86(nextBlock)); for (int i = 0; i < 16; i++) file.writeByte(0); memoBlockSize = 512; file.writeInt(DbaseUtils.x86(memoBlockSize)); }
@Override public Bytes writeByte(long offset, int b) { checkWrite(offset, BYTE); try { seekToOffset(offset); randomAccessFile.writeByte(b); } catch (IOException e) { throw new RuntimeException(e); } return this; }
@Override public Bytes writeByte(long offset, int b) { checkWrite(offset, BYTE); try { seekToOffset(offset); randomAccessFile.writeByte(b); } catch (IOException e) { throw new RuntimeException(e); } return this; }
@Override public void writeByte(int i) throws IOException { try { getRaf().writeByte(i); } catch (IOException ioe) { handleException(); throw ioe; } }
@Test(expected = FileReactiveAuditException.class) public void writeByte() throws IOException { ReactiveAudit.off.commit(); try (RandomAccessFile rw = newRandomAccessFile()) { TestTools.strict.commit(); rw.writeByte(0); } }