/** * This implementation returns the underlying file's length. */ @Override public long contentLength() throws IOException { return Files.size(this.path); }
/** * This implementation returns the underlying file's length. */ @Override public long contentLength() throws IOException { return Files.size(this.path); }
/** * Provide the standard Groovy <code>size()</code> method for <code>Path</code>. * * @param self a {@code Path} object * @return the file's size (length) * @since 2.3.0 */ public static long size(Path self) throws IOException { return Files.size(self); }
@Override public long size() { try { return Files.size(file); } catch (IOException ex) { return 0; } }
@Override public Long getContentLength() { try { return Files.size(file); } catch (IOException e) { throw new RuntimeException(e); } }
@Override public int getNumBytes() { try { return (int) Files.size(path); } catch (IOException e) { e.printStackTrace(); return -1; } }
@Override public long getFileSize( File fileName ) { try { return Files.size( path( fileName ) ); } catch ( IOException e ) { return 0; } }
/** * This implementation returns the underlying File/Path length. */ @Override public long contentLength() throws IOException { if (this.file != null) { long length = this.file.length(); if (length == 0L && !this.file.exists()) { throw new FileNotFoundException(getDescription() + " cannot be resolved in the file system for checking its content length"); } return length; } else { try { return Files.size(this.filePath); } catch (NoSuchFileException ex) { throw new FileNotFoundException(ex.getMessage()); } } }
public long getFileSize() throws IOException { if (isInMemory()) { return content.length; } else { return Files.size(file); } }
private byte[] readFlowFromDisk() throws IOException { final Path flowPath = nifiProperties.getFlowConfigurationFile().toPath(); if (!Files.exists(flowPath) || Files.size(flowPath) == 0) { return new byte[0]; } final ByteArrayOutputStream baos = new ByteArrayOutputStream(); try (final InputStream in = Files.newInputStream(flowPath, StandardOpenOption.READ); final InputStream gzipIn = new GZIPInputStream(in)) { FileUtils.copy(gzipIn, baos); } return baos.toByteArray(); }
@Override public void addToArchive( Path archiveDestination, DiagnosticsReporterProgress progress ) throws IOException { // Heap dump has to target an actual file, we cannot stream directly to the archive progress.info( "dumping..." ); Path tempFile = Files.createTempFile("neo4j-heapdump", ".hprof"); Files.deleteIfExists( tempFile ); heapDump( tempFile.toAbsolutePath().toString() ); // Track progress of archiving process progress.info( "archiving..." ); long size = Files.size( tempFile ); InputStream in = Files.newInputStream( tempFile ); try ( ProgressAwareInputStream inStream = new ProgressAwareInputStream( in, size, progress::percentChanged ) ) { Files.copy( inStream, archiveDestination ); } Files.delete( tempFile ); }
static void putTarEntry(TarArchiveOutputStream tarOutputStream, TarArchiveEntry tarEntry, Path file) throws IOException { tarEntry.setSize(Files.size(file)); tarOutputStream.putArchiveEntry(tarEntry); try (InputStream input = new BufferedInputStream(Files.newInputStream(file))) { ByteStreams.copy(input, tarOutputStream); tarOutputStream.closeArchiveEntry(); } }
public static void main(String[] args) throws Exception { final ParameterTool params = ParameterTool.fromArgs(args); final Path inputFile = Paths.get(params.getRequired("inputFile")); final Path inputDir = Paths.get(params.getRequired("inputDir")); final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(); env.setParallelism(1); env.registerCachedFile(inputFile.toString(), "test_data", false); env.registerCachedFile(inputDir.toString(), "test_dir", false); final Path containedFile; try (Stream<Path> files = Files.list(inputDir)) { containedFile = files.findAny().orElseThrow(() -> new RuntimeException("Input directory must not be empty.")); } env.fromElements(1) .map(new TestMapFunction( inputFile.toAbsolutePath().toString(), Files.size(inputFile), inputDir.toAbsolutePath().toString(), containedFile.getFileName().toString())) .writeAsText(params.getRequired("output"), FileSystem.WriteMode.OVERWRITE); env.execute("Distributed Cache Via Blob Test Program"); }
@Implementation protected final AssetFileDescriptor openFd(String fileName) throws IOException { Path path = findAssetFile(fileName); if (path.getFileSystem().provider().getScheme().equals("jar")) { path = getFileFromZip(path); } ParcelFileDescriptor parcelFileDescriptor = ParcelFileDescriptor.open(path.toFile(), ParcelFileDescriptor.MODE_READ_ONLY); return new AssetFileDescriptor(parcelFileDescriptor, 0, Files.size(path)); }
public static Asset newFileAsset(FileTypedResource fileTypedResource) throws IOException { _FileAsset fileAsset = new _FileAsset(); Path path = fileTypedResource.getPath(); fileAsset.mFileName = Fs.externalize(path); fileAsset.mLength = Files.size(path); fileAsset.mBuf = Fs.getBytes(path); return fileAsset; }
@Test public void testSize() throws Exception { Path path = Paths.get(URI.create("gs://bucket/wat")); Files.write(path, SINGULARITY.getBytes(UTF_8)); assertThat(Files.size(path)).isEqualTo(SINGULARITY.getBytes(UTF_8).length); }
@Override public long size(final ContentClaim claim) throws IOException { if (claim == null) { return 0L; } // see javadocs for claim.getLength() as to why we do this. if (claim.getLength() < 0) { return Files.size(getPath(claim, true)) - claim.getOffset(); } return claim.getLength(); }
public static void assertNonEmpty(Path p) throws IOException { assertTrue("File should exist: " + p, Files.exists(p)); assertTrue("File should not be empty: " + p, Files.size(p) > 0); }
@Test public void testReadWriteFile() throws Exception { Path path = temporaryFolder.newFile().toPath(); Sink sink = new FileChannelSink(FileChannel.open(path, w), Timeout.NONE); sink.write(new Buffer().writeUtf8(quote), 317); sink.close(); assertTrue(Files.exists(path)); assertEquals(quote.length(), Files.size(path)); Buffer buffer = new Buffer(); Source source = new FileChannelSource(FileChannel.open(path, r), Timeout.NONE); source.read(buffer, 44); assertThat(buffer.readUtf8()) .isEqualTo("John, the kind of control you're attempting "); source.read(buffer, 31); assertThat(buffer.readUtf8()) .isEqualTo("simply is... it's not possible."); }
@Test public void readWritePath() throws Exception { Path path = temporaryFolder.newFile().toPath(); BufferedSink sink = Okio.buffer(Okio.sink(path)); sink.writeUtf8("Hello, java.nio file!"); sink.close(); assertTrue(Files.exists(path)); assertEquals(21, Files.size(path)); BufferedSource source = Okio.buffer(Okio.source(path)); assertEquals("Hello, java.nio file!", source.readUtf8()); source.close(); }