当前位置: 首页>>代码示例>>Java>>正文


Java FileObject.getContent方法代码示例

本文整理汇总了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();
}
 
开发者ID:MyCoRe-Org,项目名称:mycore,代码行数:23,代码来源:MCRCStoreVFS.java

示例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();
       }
       **/
	
}
 
开发者ID:cycronix,项目名称:cloudturbine,代码行数:52,代码来源:FilePumpWorker.java

示例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;
  }
 
开发者ID:lorthos,项目名称:incubator-zeppelin-druid,代码行数:32,代码来源:VFSNotebookRepo.java


注:本文中的org.apache.commons.vfs2.FileObject.getContent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。