/** * Writes a big-endian 64-bit double to this file, starting at the current file * pointer. The bytes are those returned by * {@link Double#doubleToLongBits(double)}, meaning a canonical NaN is used. * * @param val * the double to write to this file. * @throws IOException * if an I/O error occurs while writing to this file. * @see #readDouble() */ public final void writeDouble(double val) throws IOException { writeLong(Double.doubleToLongBits(val)); }
public long set(long cnt) { this.counts = cnt; try { raf.seek(0); raf.writeLong(counts); } catch (Exception e) { e.printStackTrace(); } return this.counts; }
/** * Writes some internal data into the beginning of the specified file. */ protected void writeHeader(RandomAccessFile file, long length, int segmentSize) throws IOException { file.seek(0); file.writeUTF("GH"); file.writeLong(length); file.writeInt(segmentSize); for (int i = 0; i < header.length; i++) { file.writeInt(header[i]); } }
@Override void markCheckpoint(long currentPosition, long logWriteOrderID) throws IOException { RandomAccessFile writeFileHandle = getFileHandle(); writeFileHandle.seek(OFFSET_CHECKPOINT); writeFileHandle.writeLong(currentPosition); writeFileHandle.writeLong(logWriteOrderID); writeFileHandle.getChannel().force(true); LOGGER.info("Noted checkpoint for file: " + getFile() + ", id: " + getLogFileID() + ", checkpoint position: " + currentPosition + ", logWriteOrderID: " + logWriteOrderID); } }
Writer(File file, int logFileID, long maxFileSize, long usableSpaceRefreshInterval) throws IOException { super(file, logFileID, maxFileSize, null, usableSpaceRefreshInterval, true, 0); RandomAccessFile writeFileHandle = getFileHandle(); writeFileHandle.writeInt(getVersion()); writeFileHandle.writeInt(logFileID); // checkpoint marker writeFileHandle.writeLong(0L); // timestamp placeholder writeFileHandle.writeLong(0L); getFileChannel().force(true); }
@Override public Bytes writeLong(int offset, long l) { checkWrite(offset, LONG); try { seekToOffset(offset); randomAccessFile.writeLong(l); } catch (IOException e) { throw new RuntimeException(e); } return this; }
@Private static RandomAccessFile initializeFromFile(File file, boolean forceLegacy) throws IOException { if (!file.exists()) { // Use a temp file so we don't leave a partially-initialized file. File tempFile = new File(file.getPath() + ".tmp"); RandomAccessFile raf = open(tempFile); try { raf.setLength(INITIAL_LENGTH); raf.seek(0); if (forceLegacy) { raf.writeInt(INITIAL_LENGTH); } else { raf.writeInt(VERSIONED_HEADER); raf.writeLong(INITIAL_LENGTH); } } finally { raf.close(); } // A rename is atomic. if (!tempFile.renameTo(file)) { throw new IOException("Rename failed!"); } } return open(file); }
@Override public void writeLong(long l) throws IOException { try { getRaf().writeLong(l); } catch (IOException ioe) { handleException(); throw ioe; } }
private synchronized void writeChunkMetaData(int lastChunkId, TreeSet<Long> removedPages) { try { chunkMetaData.setLength(0); chunkMetaData.seek(0); chunkMetaData.writeInt(lastChunkId); chunkMetaData.writeInt(removedPages.size()); for (long pos : removedPages) { chunkMetaData.writeLong(pos); } chunkMetaData.writeInt(hashCodeToHostIdMap.size()); for (String hostId : hashCodeToHostIdMap.values()) { chunkMetaData.writeUTF(hostId); } // chunkMetaData.setLength(4 + 4 + removedPages.size() * 8); chunkMetaData.getFD().sync(); } catch (IOException e) { throw panic(DataUtils.newIllegalStateException(DataUtils.ERROR_WRITING_FAILED, "Failed to writeChunkMetaData", e)); } }
randomAccessLockFile.writeLong(System.currentTimeMillis()); randomAccessLockFile.getChannel().force(true); lastModified = file.lastModified();
allocate(checkpointFile, totalBytes); checkpointFileHandle.seek(INDEX_VERSION * Serialization.SIZE_OF_LONG); checkpointFileHandle.writeLong(getVersion()); checkpointFileHandle.getChannel().force(true); LOG.info("Preallocated " + checkpointFile + " to " + checkpointFileHandle.length()
@Test public void testSizeLessThanHeaderThrows() throws IOException { RandomAccessFile emptyFile = new RandomAccessFile(file, "rwd"); emptyFile.setLength(INITIAL_LENGTH); if (forceLegacy) { emptyFile.writeInt(headerLength - 1); } else { emptyFile.writeInt(0x80000001); emptyFile.writeLong(headerLength - 1); } emptyFile.getChannel().force(true); emptyFile.close(); try { newQueueFile(); fail(); } catch (IOException ex) { assertThat(ex.getMessage()).isIn( Arrays.asList("File is corrupt; length stored in header (15) is invalid.", "File is corrupt; length stored in header (31) is invalid.")); } }
try { checkpointFileHandle.seek(INDEX_VERSION * Serialization.SIZE_OF_LONG); checkpointFileHandle.writeLong(Serialization.VERSION_3); checkpointFileHandle.getChannel().force(true); } finally {
public void writeLong(long v) throws IOException { delegate.writeLong(v); } public void writeFloat(float v) throws IOException { delegate.writeFloat(v); }
randomAccessFile.writeLong(fileSize);
raf.writeInt((Integer) value); } else if (binding == Long.class || binding == long.class) { raf.writeLong((Long) value); } else if (binding == Float.class || binding == float.class) { raf.writeFloat((Float) value); || binding == java.sql.Timestamp.class || binding == java.util.Date.class) { raf.writeLong(((Date) value).getTime()); } else if (Geometry.class.isAssignableFrom(binding)) { WKBWriter writer = new WKBWriter();