本文整理汇总了Java中java.nio.file.Files.size方法的典型用法代码示例。如果您正苦于以下问题:Java Files.size方法的具体用法?Java Files.size怎么用?Java Files.size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.nio.file.Files
的用法示例。
在下文中一共展示了Files.size方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: PhotatoVideo
import java.nio.file.Files; //导入方法依赖的package包/类
public PhotatoVideo(Path rootFolder, Path path, Metadata metadata, PictureInfos thumbnailInfos, PictureInfos fullScreenInfos, long lastModificationTimestamp) {
super("video", rootFolder, path, metadata, thumbnailInfos, fullScreenInfos, lastModificationTimestamp);
if (this.filename.length() > 40 || this.filename.contains("_") || this.filename.toLowerCase().startsWith("vid")) {
this.name = path.getParent().getFileName().toString();
} else {
this.name = path.getParent().getFileName() + "/" + this.filename;
}
this.videoType = "video/" + FileHelper.getExtension(path.toString()).toLowerCase();
this.videoPath = Routes.rawVideosRootUrl + "/" + PathHelper.getPathString(rootFolder, path);
long tmpFilesize;
try {
tmpFilesize =Files.size(this.fsPath);
} catch (IOException ex) {
tmpFilesize=0;
}
this.filesize = tmpFilesize;
}
示例2: accept
import java.nio.file.Files; //导入方法依赖的package包/类
@Override
public boolean accept(Media candidate) {
Path file = scanSettings.getBaseInputDir().resolve(candidate.getSourcePath());
try {
long size = Files.size(file);
if (minSize > 0 && maxSize > 0) {
// file between max and min
return logAndReturn(size >= minSize && size <= maxSize, file, size);
} else if (minSize <= 0) {
// size smaller than max, min disabled
return logAndReturn(size <= maxSize, file, size);
} else {
// size greater than min, max disabled
return logAndReturn(size >= minSize, file, size);
}
} catch (IOException e) {
log.warn("Could not determine file size of {}: {}. Declined file.", file, e.toString());
return false;
}
}
示例3: calculateSize
import java.nio.file.Files; //导入方法依赖的package包/类
public String calculateSize(File f){
String s;long sizeInByte=0; Path path;
if(IsDrive(f)){
return Long.toString(f.getTotalSpace()/(1024*1024*1024))+"GB";
}
path = Paths.get(f.toURI());
//sizeInByte = f.getTotalSpace(); // terrible idea cz sob subfolder e 199GB, 99GB esob dekhay >_<
try {
sizeInByte = Files.size(path);//at least works ^_^
} catch (IOException e) {
e.printStackTrace();
}
if(sizeInByte<(1024)){s = Long.toString(sizeInByte)+"B"; return s; }
else if(sizeInByte>=(1024) && sizeInByte<(1024*1024)){ long sizeInKb = sizeInByte/1024; s = Long.toString(sizeInKb)+"KB"; return s; }
else if(sizeInByte>=(1024*1024) && sizeInByte<(1024*1024*1024)){ long sizeInMb = sizeInByte/(1024*1024); s = Long.toString(sizeInMb)+"MB"; return s; }
else if(sizeInByte>=(1024*1024*1024)){ long sizeInGb = sizeInByte/(1024*1024*1024); s = Long.toString(sizeInGb)+"GB"; return s; }
return null;
}
示例4: StateFile
import java.nio.file.Files; //导入方法依赖的package包/类
public StateFile(Path file) throws IOException {
this.fileCounts = new int[MAX_FILES];
this.randomWrite = new RandomAccessFile(file.toFile(), "rw");
if (Files.exists(file) && Files.size(file) == EXPECTED_SIZE) {
try (DataInputStream stream = new DataInputStream(new FileInputStream(file.toFile()))) {
readFile = stream.readShort();
writeFile = stream.readShort();
readPosition = stream.readInt();
writePosition = stream.readInt();
count = stream.readLong();
bytes = stream.readLong();
for (int i = 0; i < MAX_FILES; i++)
fileCounts[i] = stream.readInt();
unflushed = 0;
}
}
}
示例5: equals
import java.nio.file.Files; //导入方法依赖的package包/类
public boolean equals(Path path) {
try {
if (this.path != null) return Files.isSameFile(path, this.path);
if (!getSanitizedFileName(path).equals(fileName)) return false;
if (Files.size(path) != size) return false;
return Arrays.equals(sha256, hash(path));
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
示例6: streamBinaryData
import java.nio.file.Files; //导入方法依赖的package包/类
public static BinaryData streamBinaryData(Path p) {
try {
final long size = Files.size(p);
final InputStream dataStream = Files.newInputStream(p);
return new BinaryData(dataStream, size);
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}
示例7: getCharContent
import java.nio.file.Files; //导入方法依赖的package包/类
@Override
public final CharSequence getCharContent(final boolean ignoreEncodingErrors) throws IOException {
final long len = Files.size(resolvePath());
return FileObjects.getCharContent(
openInputStream(),
encoding,
null,
len,
ignoreEncodingErrors);
}
示例8: processedFileIsSmaller
import java.nio.file.Files; //导入方法依赖的package包/类
@Test
public void processedFileIsSmaller() throws Throwable {
long original = Files.size(getOriginalDexFile());
long generated = Files.size(getGeneratedDexFile());
final boolean ALWAYS_DUMP = false; // Used for debugging.
if (ALWAYS_DUMP || generated > original) {
dump(getOriginalDexFile(), "Original");
dump(getGeneratedDexFile(), "Generated");
}
assertTrue("Inlining failed to reduce size", original > generated);
}
示例9: getFileSize
import java.nio.file.Files; //导入方法依赖的package包/类
public long getFileSize() {
try {
return Files.size(path);
} catch (IOException e) {
e.printStackTrace();
}
return 0;
}
示例10: FileEntry
import java.nio.file.Files; //导入方法依赖的package包/类
FileEntry(Path path, String name) {
super(DirArchive.this, getPathName(path), name,
Archive.Entry.EntryType.CLASS_OR_RESOURCE);
this.path = path;
try {
size = Files.size(path);
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}
示例11: size
import java.nio.file.Files; //导入方法依赖的package包/类
public long size() {
try {
return Files.size(file);
} catch (IOException e) {
e.printStackTrace();
}
return -1;
}
示例12: scanMetadata
import java.nio.file.Files; //导入方法依赖的package包/类
private boolean scanMetadata(URI uri) {
var meta = read(uri.resolve("maven-metadata.xml")).orElseThrow(Error::new);
if (meta.contains("<versioning>")) {
var updated = substring(meta, "<lastUpdated>", "<");
if (updated.length() != 14) {
System.out.println(" [!] unexpected <lastUpdated> format: " + updated);
return true;
}
if (updated.compareTo("20170101000000") < 0) {
System.out.println(" [!] too old: " + updated);
return true;
}
var group = substring(meta, "<groupId>", "<");
var artifact = substring(meta, "<artifactId>", "<");
var version = substring(meta, "<release>", "<"); // TODO Consider 'latest'?
try {
// TODO load .pom and assume "jar" packaging
var jar = load(uri.resolve(version + "/" + artifact + "-" + version + ".jar"));
if (Files.exists(jar) && Files.size(jar) > 0) {
scanJar(jar, group, artifact, version);
}
Files.deleteIfExists(jar);
} catch (Exception e) {
throw new Error("Scanning maven-metadata.xml failed!", e);
}
return true;
}
return false;
}
示例13: getSize
import java.nio.file.Files; //导入方法依赖的package包/类
@Override
public long getSize() {
if(Files.exists(Paths.get(path))) {
try {
return Files.size(Paths.get(path));
}
catch(IOException e) {
log.warn(String.format("Failure getting size of %s. %s", path, e.getMessage()));
}
}
return -1;
}
示例14: gc
import java.nio.file.Files; //导入方法依赖的package包/类
private void gc() throws IOException {
Path file = makeDataPath(state.getReadFile());
boolean shouldFlush = false;
while (!Files.exists(file) && !state.sameFileReadWrite()) {
state.advanceReadFile(0);
file = makeDataPath(state.getReadFile());
shouldFlush = true;
}
long totalBytes = 0;
long totalCount = 0;
for (int i = 0; i < StateFile.MAX_FILES; i++) {
Path path = makeDataPath(i);
if (Files.exists(path)) {
if (!state.isInUse(i)) {
tryDeleteFile(i, false);
} else {
totalBytes += Files.size(path);
totalCount += state.getFileCount(i);
}
}
}
shouldFlush |= state.fixCounts(totalCount, totalBytes);
if (shouldFlush)
internalFlush();
}
示例15: ZipFileStoreAttributes
import java.nio.file.Files; //导入方法依赖的package包/类
public ZipFileStoreAttributes(ZipFileStore fileStore)
throws IOException
{
Path path = FileSystems.getDefault().getPath(fileStore.name());
this.size = Files.size(path);
this.fstore = Files.getFileStore(path);
}