private OutputStream getOutputStream(boolean append) throws IOException { File f = getNotNullFile(); if (f.exists()) { if (f.isFile() && !append) { f.delete(); } } else { File p = f.getParentFile(); if (p != null && !(p.exists())) { p.mkdirs(); } } return FileUtils.newOutputStream(f.toPath(), append); }
/** * Return an InputStream for reading the contents of this Resource. * @return an InputStream object. * @throws IOException if an error occurs. */ @Override public InputStream getInputStream() throws IOException { return isReference() ? getCheckedRef().getInputStream() : Files.newInputStream(getNotNullFile().toPath()); }
/** * Learn whether the resource is a directory. * @return boolean flag indicating if the resource is a directory. */ @Override public boolean isDirectory() { return isReference() ? getCheckedRef().isDirectory() : getNotNullFile().isDirectory(); }
/** * Learn whether this file exists. * @return true if this resource exists. */ @Override public boolean isExists() { return isReference() ? getCheckedRef().isExists() : getNotNullFile().exists(); }
/** * Get the size of this Resource. * @return the size, as a long, 0 if the Resource does not exist. */ @Override public long getSize() { return isReference() ? getCheckedRef().getSize() : getNotNullFile().length(); }
/** * Get the modification time in milliseconds since 01.01.1970 . * @return 0 if the resource does not exist. */ @Override public long getLastModified() { return isReference() ? getCheckedRef().getLastModified() : getNotNullFile().lastModified(); }
/** * Get the name of this FileResource. If the basedir is set, * the name will be relative to that. Otherwise the basename * only will be returned. * @return the name of this resource. */ @Override public String getName() { if (isReference()) { return getCheckedRef().getName(); } File b = getBaseDir(); return b == null ? getNotNullFile().getName() : FILE_UTILS.removeLeadingPath(b, getNotNullFile()); }
/** * Implement the Touchable interface. * @param modTime new last modification time. */ @Override public void touch(long modTime) { if (isReference()) { getCheckedRef().touch(modTime); return; } if (!getNotNullFile().setLastModified(modTime)) { log("Failed to change file modification time", Project.MSG_WARN); } }