public interface SaveAsCapable
DataEditorSupport
. So if your
editor support inherits from DataEditorSupport
you can implement "Save As" feature
for your documents by adding the following lines into your DataObject
's constructor:
getCookieSet().assign(SaveAsCapable.class, new SaveAsCapable() {
public void saveAs(FileObject folder, String fileName) throws IOException {
getDataEditorSupport().saveAs( folder, fileName );
}
});
If you have Node
, you may use the following code:
public class MyNode extends AbstractNode {
public MyNode() {
getCookieSet().assign(SaveAsCapable.class, new MySaveAsCapable());
...
}
private class MySaveAsCapable implements SaveAsCapable {
public void saveAs(FileObject folder, String fileName) throws IOException {
FileObject newFile = folder.getFileObject(fileName);
if (newFile == null) {
newFile = FileUtil.createData(folder, fileName);
}
OutputStream output = newFile.getOutputStream();
InputStream input = ... // get your input stream
try {
byte[] buffer = new byte[4096];
while (input.available() > 0) {
output.write(buffer, 0, input.read(buffer));
}
}
finally {
if (input != null) {
input.close();
}
if (output != null) {
output.close();
}
}
}
}
}
Modifier and Type | Method and Description |
---|---|
void |
saveAs(FileObject folder,
String name)
Invoke the save operation.
|
void saveAs(FileObject folder, String name) throws IOException
folder
- Folder to save to.name
- New file name to save to.IOException
- if the object could not be saved