static void checkBasicAttributes(BasicFileAttributes attrs1, BasicFileAttributes attrs2) { // check file type assertTrue(attrs1.isRegularFile() == attrs2.isRegularFile()); assertTrue(attrs1.isDirectory() == attrs2.isDirectory()); assertTrue(attrs1.isSymbolicLink() == attrs2.isSymbolicLink()); assertTrue(attrs1.isOther() == attrs2.isOther()); // check last modified time long time1 = attrs1.lastModifiedTime().toMillis(); long time2 = attrs2.lastModifiedTime().toMillis(); assertTrue(time1 == time2); // check size if (attrs1.isRegularFile()) assertTrue(attrs1.size() == attrs2.size()); }
public static void main(String args[]) { try { aServer asr = new aServer(); // file channel. FileInputStream is = new FileInputStream(""); is.read(); FileChannel cha = is.getChannel(); ByteBuffer bf = ByteBuffer.allocate(1024); bf.flip(); cha.read(bf); // Path Paths Path pth = Paths.get("", ""); // Files some static operation. Files.newByteChannel(pth); Files.copy(pth, pth); // file attribute, other different class for dos and posix system. BasicFileAttributes bas = Files.readAttributes(pth, BasicFileAttributes.class); bas.size(); } catch (Exception e) { System.err.println(e); } System.out.println("hello "); }
@Override public FileVisitResult visitFile(Path file, BasicFileAttributes attr) { if (attr.isSymbolicLink()) { System.out.format("Symbolic link: %s ", file); } else if (attr.isRegularFile()) { System.out.format("Regular file: %s ", file); } else { System.out.format("Other: %s ", file); } System.out.println("(" + attr.size() + "bytes)"); return CONTINUE; }
static void checkBasicAttributes(BasicFileAttributes attrs1, BasicFileAttributes attrs2) { // check file type assertTrue(attrs1.isRegularFile() == attrs2.isRegularFile()); assertTrue(attrs1.isDirectory() == attrs2.isDirectory()); assertTrue(attrs1.isSymbolicLink() == attrs2.isSymbolicLink()); assertTrue(attrs1.isOther() == attrs2.isOther()); // check last modified time if not a symbolic link if (!attrs1.isSymbolicLink()) { long time1 = attrs1.lastModifiedTime().to(TimeUnit.SECONDS); long time2 = attrs2.lastModifiedTime().to(TimeUnit.SECONDS); if (time1 != time2) { System.err.format("File time for %s is %s\n", attrs1.fileKey(), attrs1.lastModifiedTime()); System.err.format("File time for %s is %s\n", attrs2.fileKey(), attrs2.lastModifiedTime()); assertTrue(false); } } // check size if (attrs1.isRegularFile()) assertTrue(attrs1.size() == attrs2.size()); }
@Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { if (pathMatcher.matches(file.getFileName())) { if (attrs.isSymbolicLink()) { System.out.format("Symbolic link: %s ", file); } else if (attrs.isRegularFile()) { System.out.format("Regular file: %s ", file); } else { System.out.format("Other: %s ", file); } System.out.println("(" + attrs.size() + "bytes)"); } return FileVisitResult.CONTINUE; }
/* * (non-Javadoc) * * @see org.apache.logging.log4j.core.appender.rolling.action.PathCondition#accept(java.nio.file.Path, * java.nio.file.Path, java.nio.file.attribute.BasicFileAttributes) */ @Override public boolean accept( final Path basePath, final Path relativePath, final BasicFileAttributes attrs) { accumulatedSize += attrs.size(); final boolean result = accumulatedSize > thresholdBytes; final String match = result ? ">" : "<="; final String accept = result ? "ACCEPTED" : "REJECTED"; LOGGER.trace( "IfAccumulatedFileSize {}: {} accumulated size '{}' {} thresholdBytes '{}'", accept, relativePath, accumulatedSize, match, thresholdBytes); if (result) { return IfAll.accept(nestedConditions, basePath, relativePath, attrs); } return result; }
public final void update(File[] xml) { if (xml != null || xml.length != 0) { data = new String[xml.length][columnNames.length]; try { for (int i = 0; i < xml.length; i++) { if (xml[i].isFile()) { BasicFileAttributes attrs = Files.readAttributes(xml[i].toPath(), BasicFileAttributes.class); data[i][0] = xml[i].getName(); data[i][1] = String.format("%d B", attrs.size()); data[i][2] = String.format("%1$tY/%1$tm/%1$td", new Date(attrs.creationTime().toMillis())); data[i][3] = String.format("%1$tY/%1$tm/%1$td", new Date(attrs.lastModifiedTime().toMillis())); } } rows = xml.length; fireTableStructureChanged(); } catch (IOException ex) { System.err.println(ex.getMessage()); } } else JOptionPane.showMessageDialog(null, "No existen facturas de consumidor final"); }
public FileAttrs getAttrs() throws IOException { FileAttrs result; BasicFileAttributes attr; DosFileAttributes dosAttr; PosixFileAttributes posixAttr; result = new FileAttrs(); attr = Files.readAttributes(this.path.toPath(), BasicFileAttributes.class); result.setCtime(attr.creationTime().toMillis()); result.setMtime(attr.lastModifiedTime().toMillis()); // result.append("symlink", attr.isSymbolicLink()); //Redundant result.setSize(attr.size()); if (System.getProperty("os.name").startsWith("Windows")) { dosAttr = Files.readAttributes(this.path.toPath(), DosFileAttributes.class); result.setDosArchive(dosAttr.isArchive()); result.setDosHidden(dosAttr.isHidden()); result.setDosReadonly(dosAttr.isReadOnly()); result.setDosSystem(dosAttr.isSystem()); } else { posixAttr = Files.readAttributes(this.path.toPath(), PosixFileAttributes.class); result.setPosixSymlink(this.isSymlink()); if (result.getPosixSymlink()) { result.setLinkTo(Files.readSymbolicLink(this.path.toPath()).toString()); } result.setPosixOwner(posixAttr.owner().getName()); result.setPosixGroup(posixAttr.group().getName()); result.setPosixPermission(PosixFilePermissions.toString(posixAttr.permissions())); } return result; }