public FadvisedChunkedFile(RandomAccessFile file, long position, long count, int chunkSize, boolean manageOsCache, int readaheadLength, ReadaheadPool readaheadPool, String identifier) throws IOException { super(file, position, count, chunkSize); this.manageOsCache = manageOsCache; this.readaheadLength = readaheadLength; this.readaheadPool = readaheadPool; this.fd = file.getFD(); this.identifier = identifier; }
public synchronized FileDescriptor getFD() throws IOException { return this.raf.getFD(); }
@Override public Bytes flush() { try { randomAccessFile.getFD().sync(); } catch (IOException e) { throw new RuntimeException(e); } return this; }
/** * Test Method to be used only for testing purposes. Gets the underlying File object for the Oplog * . Oplog class uses this File object to obtain the RandomAccessFile object. Before returning the * File object , the dat present in the buffers of the RandomAccessFile object is flushed. * Otherwise, for windows the actual file length does not match with the File size obtained from * the File object */ File getOplogFile() throws SyncFailedException, IOException { synchronized (this.crf) { if (!this.crf.RAFClosed) { this.crf.raf.getFD().sync(); } return this.crf.f; } }
@Override public void force(boolean metaData) throws IOException { String m = SysProperties.SYNC_METHOD; if ("".equals(m)) { // do nothing } else if ("sync".equals(m)) { file.getFD().sync(); } else if ("force".equals(m)) { file.getChannel().force(true); } else if ("forceFalse".equals(m)) { file.getChannel().force(false); } else { file.getFD().sync(); } }
public void close() { try { fileHandle.getFD().sync(); fileHandle.close(); } catch (IOException e) { LOG.error("Could not close file handle to file " + fileHandle.toString(), e); } } }
@Implementation protected FileDescriptor getFileDescriptor() { try { return file.getFD(); } catch (IOException e) { throw new RuntimeException(e); } }
@Implementation(maxSdk = P) protected static FileDescriptor openFileDescriptor(String file, int mode) throws IOException { RandomAccessFile randomAccessFile = new RandomAccessFile(file, mode == ParcelFileDescriptor.MODE_READ_ONLY ? "r" : "rw"); return randomAccessFile.getFD(); } }
@Override public void force(boolean metaData) throws IOException { mapped.force(); file.getFD().sync(); }
public FadvisedFileRegion(RandomAccessFile file, long position, long count, boolean manageOsCache, int readaheadLength, ReadaheadPool readaheadPool, String identifier, int shuffleBufferSize, boolean shuffleTransferToAllowed, boolean canEvictAfterTransfer) throws IOException { super(file.getChannel(), position, count); this.manageOsCache = manageOsCache; this.readaheadLength = readaheadLength; this.readaheadPool = readaheadPool; this.fd = file.getFD(); this.identifier = identifier; this.fileChannel = file.getChannel(); this.count = count; this.position = position; this.shuffleBufferSize = shuffleBufferSize; this.shuffleTransferToAllowed = shuffleTransferToAllowed; // To indicate whether the pages should be thrown away or not. this.canEvictAfterTransfer = canEvictAfterTransfer; }
@Override public void force(boolean metaData) throws IOException { mapped.force(); file.getFD().sync(); }
@Implementation protected int getFd() { try { return ReflectionHelpers.getField(file.getFD(), "fd"); } catch (IOException e) { throw new RuntimeException(e); } }
public synchronized void writeToConfigXmlFile(String content) { FileChannel channel = null; FileOutputStream outputStream = null; FileLock lock = null; try { RandomAccessFile randomAccessFile = new RandomAccessFile(fileLocation(), "rw"); channel = randomAccessFile.getChannel(); lock = channel.lock(); randomAccessFile.seek(0); randomAccessFile.setLength(0); outputStream = new FileOutputStream(randomAccessFile.getFD()); IOUtils.write(content, outputStream, UTF_8); } catch (Exception e) { throw new RuntimeException(e); } finally { if (channel != null && lock != null) { try { lock.release(); channel.close(); IOUtils.closeQuietly(outputStream); } catch (IOException e) { LOGGER.error("Error occured when releasing file lock and closing file.", e); } } } }
/** * Get size of image * * @param imagePath * @return size */ public static Point getSize(final String imagePath) { final Options options = new Options(); options.inJustDecodeBounds = true; RandomAccessFile file = null; try { file = new RandomAccessFile(imagePath, "r"); BitmapFactory.decodeFileDescriptor(file.getFD(), null, options); return new Point(options.outWidth, options.outHeight); } catch (IOException e) { Log.d(TAG, e.getMessage(), e); return null; } finally { if (file != null) { try { file.close(); } catch (IOException e) { Log.d(TAG, e.getMessage(), e); } } } }
@Implementation protected static FileDescriptor nCreate(String name, int size) throws ErrnoException { maybeThrow(fakeCreateException); TempDirectory tempDirectory = RuntimeEnvironment.getTempDirectory(); try { // Give each instance its own private file. File sharedMemoryFile = Files.createTempFile( tempDirectory.createIfNotExists("SharedMemory"), "shmem-" + name, ".tmp") .toFile(); RandomAccessFile randomAccessFile = new RandomAccessFile(sharedMemoryFile, "rw"); randomAccessFile.setLength(0); randomAccessFile.setLength(size); filesByFd.put(randomAccessFile.getFD(), sharedMemoryFile); return randomAccessFile.getFD(); } catch (IOException e) { throw new RuntimeException("Unable to create file descriptior", e); } }
@Implementation protected FileDescriptor open(String path, int flags, int mode) throws ErrnoException { try { RandomAccessFile randomAccessFile = new RandomAccessFile(path, modeToString(mode)); return randomAccessFile.getFD(); } catch (IOException e) { Log.e("ShadowLinux", "open failed for " + path, e); throw new ErrnoException("open", OsConstants.EIO); } }
public int fill(Inflater inflater, int nativeEndBufSize) throws IOException { synchronized (sharedRaf) { int len = Math.min((int) (endOffset - offset), nativeEndBufSize); int cnt = inflater.setFileInput(sharedRaf.getFD(), offset, nativeEndBufSize); // setFileInput read from the file, so we need to get the OS and RAFStream back // in sync... skip(cnt); return len; } } }
public FileDescriptor getFD() throws IOException { try { return getRaf().getFD(); } catch (IOException ioe) { handleException(); throw ioe; } }