private boolean length(final String[] args) throws IllegalUsageException { if (args.length != 1) throw new IllegalUsageException(); final long length = new TFile(args[0]).length(); out.println(length); return true; }
// Note that the actual path may refer to anything, even a nested archive file. TFile inner = new TFile("outer.zip/inner.zip"); TFile file = inner.toNonArchiveFile(); // convert - since TrueZIP 7.5 ... // there may be some I/O here TVFS.umount(inner); // unmount potential archive file // Now you can safely do any I/O to $file. long length = file.length();
private void ls( final TFile file, final String path, final boolean detailed) { final StringBuffer buf = new StringBuffer(); if (detailed) { align(buf, file.length(), 11); buf.append(' '); buf.append(dateFormat.format(new Date(file.lastModified()))); buf.append(' '); } buf.append(path); if (detailed) buf.append(file.isDirectory() ? (file.isFile() ? "+" : TFile.separator) : file.isFile() ? "" : file.exists() ? "?" : "\u2020"); // dagger '†' out.println(buf.toString()); }
private void assertInput(final TFile file) throws IOException { final InputStream in = new ByteArrayInputStream(getData()); try { file.input(in); } finally { in.close(); } assertEquals(getDataLength(), file.length()); }
public static long getSize(TFile file) { long size = 0; boolean symlink = false; if (!symlink) { try { if (file.isDirectory()) { // All files and subdirectories TFile[] files = file.listFiles(); for (int i = 0; i < files.length; i++) { if (files[i].isFile()) size += files[i].length(); else size += getSize(files[i]); } } } catch (Exception e) { SDFSLogger.getLog() .warn("Unable to count " + file.getPath(), e); } } return size; }
private void create(final TFile file) throws IOException { final OutputStream out = new TFileOutputStream(file); try { out.write(getData()); } finally { out.close(); } assertEquals(getDataLength(), file.length()); }
protected final void verifyTestFile(final TFile file) throws IOException { assertEquals(getDataLength(), file.length()); final byte[] array = new byte[getDataLength()]; final InputStream in = new TFileInputStream(file); try { new DataInputStream(in).readFully(array); } finally { in.close(); } assertArrayEquals(getData(), array); }
assertThat(b.length(), is(a.length())); assertThat(b.lastModified(), not(is(a.lastModified()))); TFile.cp_p(a, b); assertThat(b.length(), is(a.length())); long almd = a.lastModified() / granularity * granularity; long blmd = b.lastModified() / granularity * granularity; assertThat(a.length(), is(b.length())); assertThat(a.lastModified(), not(is(b.lastModified()))); TFile.cp_p(b, a); assertThat(a.length(), is(b.length())); almd = a.lastModified() / granularity * granularity; blmd = b.lastModified() / granularity * granularity;
assertFalse(file.isDirectory()); assertTrue(file.isFile()); assertEquals(0, file.length()); out.write(message); assertEquals(0, file.length()); out.flush(); assertEquals(0, file.length()); } finally { out.close(); assertFalse(file.isDirectory()); assertTrue(file.isFile()); assertEquals(message.length, file.length()); assertFalse(file.isDirectory()); assertTrue(file.isFile()); assertEquals(message.length, file.length()); assertFalse(file.isDirectory()); assertFalse(file.isFile()); assertEquals(0, file.length());
private void assertRm(final TFile file) throws IOException { file.rm(); assertFalse(file.exists()); assertFalse(file.isDirectory()); assertFalse(file.isFile()); assertEquals(0, file.length()); assertFalse(file.lastModified() > 0); }
private void assertDirectoryTree(TFile basePath, TFile reversePath) throws IOException { if (reversePath == null) { // We're at the leaf of the directory tree. final TFile test = new TFile(basePath, "test.txt"); //testCreateNewFile(basePath, test); assertFileOutputStream(test); return; } final TFile member = new TFile(basePath, reversePath.getName()); final boolean created = member.mkdir(); final TFile children = reversePath.getParentFile(); assertDirectoryTree(member, children); assertListFiles(basePath, member.getName()); assertTrue(member.exists()); assertTrue(member.isDirectory()); assertFalse(member.isFile()); if (member.isArchive()) assertEquals(0, member.length()); if (created) { member.rm(); assertFalse(member.exists()); assertFalse(member.isDirectory()); assertFalse(member.isFile()); assertEquals(0, member.length()); } }
@Test public final void testLenientFileOutputStream() throws IOException { TFile file = new TFile(archive, "dir/inner" + getSuffix() + "/dir/test.txt"); assertFileOutputStream(file); try { archive.rm(); fail("directory not empty"); } catch (IOException expected) { } umount(); // allow external modifications! TFile.rm(archive.toNonArchiveFile()); // use plain file to delete instead! assertFalse(archive.exists()); assertFalse(archive.isDirectory()); assertFalse(archive.isFile()); assertEquals(0, archive.length()); }
assertFalse(file.isDirectory()); assertTrue(file.isFile()); assertEquals(getDataLength(), file.length()); assertTrue(file.lastModified() > 0);