本文整理汇总了Java中org.apache.commons.vfs2.FileObject.getContent方法的典型用法代码示例。如果您正苦于以下问题:Java FileObject.getContent方法的具体用法?Java FileObject.getContent怎么用?Java FileObject.getContent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.vfs2.FileObject
的用法示例。
在下文中一共展示了FileObject.getContent方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doStoreContent
import org.apache.commons.vfs2.FileObject; //导入方法依赖的package包/类
@Override
protected String doStoreContent(MCRFile file, MCRContentInputStream source) throws Exception {
StringBuilder storageId = new StringBuilder();
String[] slots = buildSlotPath();
// Recursively create directory name
for (String slot : slots) {
storageId.append(slot).append("/");
}
String fileId = buildNextID(file);
storageId.append(fileId);
FileObject targetObject = fsManager.resolveFile(getBase(), storageId.toString());
FileContent targetContent = targetObject.getContent();
try (OutputStream out = targetContent.getOutputStream()) {
IOUtils.copy(source, out);
} finally {
targetContent.close();
}
return storageId.toString();
}
示例2: writeToSFTP
import org.apache.commons.vfs2.FileObject; //导入方法依赖的package包/类
protected void writeToSFTP(String filename, int random_num) {
String connectionStr = baseConnectionStr + "/" + filename;
if(debug) System.err.println(connectionStr);
try {
// Create remote file object
FileObject remoteFile = manager.resolveFile(connectionStr, fileSystemOptions);
FileContent fc = remoteFile.getContent();
OutputStream ostream = fc.getOutputStream();
if(ostream==null) {
throw new IOException("Error opening output stream to SFTP");
}
// Write content to file
PrintWriter pw = new PrintWriter(ostream);
pw.format("%06d\n",random_num);
pw.close();
// Cleanup
if (remoteFile != null) remoteFile.close();
} catch (Exception e) {
e.printStackTrace();
}
/**
// Here's an alternate approach that creates a local file and then copies the
// local file to remote directory
// Create the local file
File local_file = new File("C:\\TEMP\\TEST",filename);
try {
FileWriter fw = new FileWriter(local_file,false);
PrintWriter pw = new PrintWriter(fw);
// Write out the index and a random number to the file
pw.format("%06d\n",random_num);
pw.close();
} catch (Exception e) {
e.printStackTrace();
}
// Copy the local file to remote SFTP server
try {
// Create local file object
FileObject localFile = manager.resolveFile(local_file.getAbsolutePath());
// Create remote file object
FileObject remoteFile = manager.resolveFile(connectionStr, fileSystemOptions);
// Copy local file to SFTP server
remoteFile.copyFrom(localFile, Selectors.SELECT_SELF);
} catch (Exception e) {
e.printStackTrace();
}
**/
}
示例3: getNote
import org.apache.commons.vfs2.FileObject; //导入方法依赖的package包/类
private Note getNote(FileObject noteDir) throws IOException {
if (!isDirectory(noteDir)) {
throw new IOException(noteDir.getName().toString() + " is not a directory");
}
FileObject noteJson = noteDir.resolveFile("note.json", NameScope.CHILD);
if (!noteJson.exists()) {
throw new IOException(noteJson.getName().toString() + " not found");
}
GsonBuilder gsonBuilder = new GsonBuilder();
gsonBuilder.setPrettyPrinting();
Gson gson = gsonBuilder.create();
FileContent content = noteJson.getContent();
InputStream ins = content.getInputStream();
String json = IOUtils.toString(ins, conf.getString(ConfVars.ZEPPELIN_ENCODING));
ins.close();
Note note = gson.fromJson(json, Note.class);
// note.setReplLoader(replLoader);
// note.jobListenerFactory = jobListenerFactory;
for (Paragraph p : note.getParagraphs()) {
if (p.getStatus() == Status.PENDING || p.getStatus() == Status.RUNNING) {
p.setStatus(Status.ABORT);
}
}
return note;
}