本文整理匯總了Java中org.apache.commons.vfs2.FileObject.createFile方法的典型用法代碼示例。如果您正苦於以下問題:Java FileObject.createFile方法的具體用法?Java FileObject.createFile怎麽用?Java FileObject.createFile使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.commons.vfs2.FileObject
的用法示例。
在下文中一共展示了FileObject.createFile方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: create
import org.apache.commons.vfs2.FileObject; //導入方法依賴的package包/類
/**
* Stores a newly created document under the given ID.
*
* @param xml
* the XML document to be stored
* @param id
* the ID under which the document should be stored
* @return the stored metadata object
*/
public MCRStoredMetadata create(MCRContent xml, int id) throws IOException, JDOMException {
if (id <= 0) {
throw new MCRException("ID of metadata object must be a positive integer");
}
FileObject fo = getSlot(id);
if (fo.exists()) {
String msg = "Metadata object with ID " + id + " already exists in store";
throw new MCRException(msg);
}
fo.createFile();
MCRStoredMetadata meta = buildMetadataObject(fo, id);
meta.create(xml);
return meta;
}
示例2: fileMove
import org.apache.commons.vfs2.FileObject; //導入方法依賴的package包/類
/**
* Move the file
*
* @param destination New location of the folder
* @param remoteFile Location of the file
* @param messageContext The message context that is processed by a handler in the handle method
* @param manager Standard file system manager
*/
private void fileMove(String destination, FileObject remoteFile, MessageContext messageContext,
StandardFileSystemManager manager) throws IOException {
FileObject file = manager.resolveFile(destination, FileConnectorUtils.init(messageContext));
if (FileConnectorUtils.isFolder(file)) {
if (!file.exists()) {
file.createFolder();
}
file = manager.resolveFile(destination + File.separator + remoteFile.getName().getBaseName(),
FileConnectorUtils.init(messageContext));
} else if (!file.exists()) {
file.createFile();
}
remoteFile.moveTo(file);
}
示例3: repairMetadata
import org.apache.commons.vfs2.FileObject; //導入方法依賴的package包/類
@Test
public void repairMetadata() throws Exception {
MCRFileCollection col = getStore().create();
Document xml1 = col.getMetadata().clone();
col.repairMetadata();
Document xml2 = col.getMetadata().clone();
assertTrue(equals(xml1, xml2));
MCRDirectory dir = col.createDir("foo");
xml1 = col.getMetadata().clone();
assertFalse(equals(xml1, xml2));
dir.delete();
xml1 = col.getMetadata().clone();
assertTrue(equals(xml1, xml2));
MCRDirectory dir2 = col.createDir("dir");
MCRFile file1 = col.createFile("test1.txt");
file1.setContent(new MCRStringContent("Test 1"));
MCRFile readme = dir2.createFile("readme.txt");
readme.setContent(new MCRStringContent("Hallo Welt!"));
MCRFile file3 = col.createFile("test2.txt");
file3.setContent(new MCRStringContent("Test 2"));
file3.setLabel("de", "Die Testdatei");
xml2 = col.getMetadata().clone();
col.repairMetadata();
xml1 = col.getMetadata().clone();
assertTrue(equals(xml1, xml2));
file3.clearLabels();
xml2 = col.getMetadata().clone();
col.fo.getChild("mcrdata.xml").delete();
col = getStore().retrieve(col.getID());
xml1 = col.getMetadata().clone();
assertTrue(equals(xml1, xml2));
col.fo.getChild("test1.txt").delete();
FileObject tmp = col.fo.resolveFile("test3.txt");
tmp.createFile();
new MCRStringContent("Hallo Welt!").sendTo(tmp);
col.repairMetadata();
String xml3 = new MCRJDOMContent(col.getMetadata()).asString();
assertFalse(xml3.contains("name=\"test1.txt\""));
assertTrue(xml3.contains("name=\"test3.txt\""));
}