| Method from org.apache.cocoon.components.source.FileSource Detail: |
public boolean canCancel(OutputStream stream) {
if (stream instanceof FileSourceOutputStream) {
FileSourceOutputStream fsos = (FileSourceOutputStream)stream;
if (fsos.getSource() == this) {
return fsos.canCancel();
}
}
// Not a valid stream for this source
throw new IllegalArgumentException("The stream is not associated to this source");
} Deprecated!Always return false. To be redefined by implementations that support
cancel(). |
public void cancel(OutputStream stream) throws Exception {
if (stream instanceof FileSourceOutputStream) {
FileSourceOutputStream fsos = (FileSourceOutputStream)stream;
if (fsos.getSource() == this) {
fsos.cancel();
return;
}
}
// Not a valid stream for this source
throw new IllegalArgumentException("The stream is not associated to this source");
} Deprecated!Cancels the output stream. |
public boolean exists() {
return this.file.exists();
} Deprecated! |
public long getContentLength() {
return this.file.length();
} Deprecated! |
public InputStream getInputStream() throws IOException, ProcessingException {
try {
return new FileInputStream(this.file);
} catch (FileNotFoundException e) {
throw new ResourceNotFoundException("Resource not found "
+ getSystemId(), e);
}
} Deprecated!Get the input stream for this source. |
public long getLastModified() {
return this.file.lastModified();
} Deprecated! |
public OutputStream getOutputStream() throws IOException, ProcessingException {
// Create a temp file. It will replace the right one when writing terminates,
// and serve as a lock to prevent concurrent writes.
File tmpFile = new File(this.file.getPath() + ".tmp");
// Ensure the directory exists
tmpFile.getParentFile().mkdirs();
// Can we write the file ?
if (this.file.exists() && !this.file.canWrite()) {
throw new IOException("Cannot write to file " + this.file.getPath());
}
// Check if it temp file already exists, meaning someone else currently writing
if (!tmpFile.createNewFile()) {
throw new ConcurrentModificationException("File " + this.file.getPath() +
" is already being written by another thread");
}
// Return a stream that will rename the temp file on close.
return new FileSourceOutputStream(tmpFile);
} Deprecated!Get an output stream to write to this source. The output stream returned
actually writes to a temp file that replaces the real one on close. This
temp file is used as lock to forbid multiple simultaneous writes. The
real file is updated atomically when the output stream is closed. |
public String getSystemId() {
if (this.systemId == null) {
try {
this.systemId = this.file.toURL().toExternalForm();
} catch(MalformedURLException mue) {
// Can this really happen ?
this.systemId = "file:" + this.file.getPath();
}
}
return this.systemId;
} Deprecated!Return the unique identifer for this source |
protected boolean isHTMLContent() {
return this.isHTMLContent;
} Deprecated!Returns true if the file name ends with ".htm" or ".html". |