本文整理汇总了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\""));
}