List of usage examples for org.apache.commons.vfs2 FileObject getContent
FileContent getContent() throws FileSystemException;
From source file:hadoopInstaller.installation.Installer.java
private FileObject getConfigurationSchema() throws InstallationFatalError { /*//from w ww . j av a 2 s. c o m * As i can not find a way to load a resource directly using VFS, the * resource is written to a temporary VFS file and we return that file. */ try { FileObject configurationSchema; configurationSchema = VFS.getManager().resolveFile("ram:///" + InstallerConstants.CONFIGURATION_SCHEMA);//$NON-NLS-1$ try (OutputStream out = configurationSchema.getContent().getOutputStream(); InputStream in = this.getClass() .getResourceAsStream(InstallerConstants.CONFIGURATION_SCHEMA);) { while (in.available() > 0) { out.write(in.read()); } } return configurationSchema; } catch (IOException e) { throw new InstallationFatalError(e, "HadoopInstaller.Configure.CouldNotReadFile", //$NON-NLS-1$ InstallerConstants.CONFIGURATION_SCHEMA); } }
From source file:com.stratuscom.harvester.deployer.FolderBasedAppRunner.java
private Map<String, DeploymentRecord> scanDeploymentArchives() throws FileSystemException { /*//from w ww .j av a 2s . c o m Go through the deployment directory looking for services to deploy. */ Map<String, DeploymentRecord> deployDirListing = new HashMap<String, DeploymentRecord>(); deploymentDirectoryFile.refresh(); List<FileObject> serviceArchives = Utils.findChildrenWithSuffix(deploymentDirectoryFile, com.stratuscom.harvester.Strings.JAR); if (serviceArchives != null) { log.log(Level.FINER, MessageNames.FOUND_SERVICE_ARCHIVES, new Object[] { serviceArchives.size(), deployDirectory }); for (FileObject serviceArchive : serviceArchives) { DeploymentRecord rec = new DeploymentRecord(); rec.fileObject = serviceArchive; rec.name = serviceArchive.getName().getBaseName(); rec.updateTime = serviceArchive.getContent().getLastModifiedTime(); deployDirListing.put(rec.name, rec); } } return deployDirListing; }
From source file:de.innovationgate.wgpublisher.design.sync.DesignDeployment.java
public void doAttachFile(WGDocument doc, FileObject file) throws WGDesignSyncException { try {/*from www.java2 s . c o m*/ if (!file.exists()) { throw new WGDesignSyncException("Attaching file '" + file.getName().getPath() + "' to document '" + doc.getDocumentKey() + "' failed because the file does not exist."); } if (!doc.attachFile(file.getContent().getInputStream(), file.getName().getBaseName())) { throw new WGDesignSyncException("Attaching file '" + file.getName().getPath() + "' to document '" + doc.getDocumentKey() + "' failed."); } } catch (Exception e) { throw new WGDesignSyncException("Attaching file '" + file.getName().getPath() + "' to document '" + doc.getDocumentKey() + "' failed.", e); } }
From source file:erigo.filepump.FilePumpWorker.java
protected void writeToSFTP(String filename, int random_num) { String connectionStr = baseConnectionStr + "/" + filename; if (debug)/*w ww . ja v a2 s . c o m*/ System.err.println(connectionStr); try { // Create remote file object FileObject fo = manager.resolveFile(connectionStr, fileSystemOptions); FileContent fc = fo.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 (fo != null) fo.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:de.innovationgate.utils.DirComparer.java
private void addFileHash(Map<String, String> hashes, FileObject file, FileObject root) throws NoSuchAlgorithmException, IOException, FileSystemException { String path = root.getName().getRelativeName(file.getName()); if (file.getType().equals(FileType.FOLDER)) { hashes.put(path, ""); } else {/*w w w. j a va 2s. co m*/ String hash = MD5HashingInputStream.getStreamHash(file.getContent().getInputStream()); hashes.put(path, hash); } }
From source file:io.hops.hopsworks.api.zeppelin.util.ZeppelinResource.java
private String readPid(FileObject file) { //pid value can only be extended up to a theoretical maximum of //32768 for 32 bit systems or 4194304 for 64 bit: byte[] pid = new byte[8]; if (file == null) { return null; }/*from w w w .j av a2 s .co m*/ try { file.getContent().getInputStream().read(pid); file.close(); } catch (FileSystemException ex) { return null; } catch (IOException ex) { return null; } String s; try { s = new String(pid, "UTF-8").trim(); } catch (UnsupportedEncodingException ex) { return null; } return s; }
From source file:net.sf.jabb.web.action.VfsTreeAction.java
/** * It transforms FileObject into JsTreeNodeData. * @param file the file whose information will be encapsulated in the node data structure. * @return The node data structure which presents the file. * @throws FileSystemException //from w w w. j a v a2 s . c om */ protected JsTreeNodeData populateTreeNodeData(FileObject file, boolean noChild, String relativePath) throws FileSystemException { JsTreeNodeData node = new JsTreeNodeData(); String baseName = file.getName().getBaseName(); FileContent content = file.getContent(); FileType type = file.getType(); node.setData(baseName); Map<String, Object> attr = new HashMap<String, Object>(); node.setAttr(attr); attr.put("id", relativePath); attr.put("rel", type.getName()); attr.put("fileType", type.getName()); if (content != null) { long fileLastModifiedTime = file.getContent().getLastModifiedTime(); attr.put("fileLastModifiedTime", fileLastModifiedTime); attr.put("fileLastModifiedTimeForDisplay", DateFormat.getDateTimeInstance().format(new Date(fileLastModifiedTime))); if (file.getType() != FileType.FOLDER) { attr.put("fileSize", content.getSize()); attr.put("fileSizeForDisplay", FileUtils.byteCountToDisplaySize(content.getSize())); } } // these fields should not appear in JSON for leaf nodes if (!noChild) { node.setState(JsTreeNodeData.STATE_CLOSED); } return node; }
From source file:com.stratuscom.harvester.codebase.ClassServer.java
/** * Read specified number of bytes and always close the stream. *///from w ww. j a v a 2s . co m private byte[] getBytes(FileObject fo) throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; InputStream in = fo.getContent().getInputStream(); int bytesRead = in.read(buffer); while (bytesRead > 0) { out.write(buffer, 0, bytesRead); bytesRead = in.read(buffer); } byte[] bytes = out.toByteArray(); out.close(); in.close(); return bytes; }
From source file:com.sludev.commons.vfs2.provider.s3.SS3FileProviderTest.java
@Test public void A004_getContentSize() throws Exception { String currAccountStr = testProperties.getProperty("s3.access.id"); String currKey = testProperties.getProperty("s3.access.secret"); String currContainerStr = testProperties.getProperty("s3.test0001.bucket.name"); String currHost = testProperties.getProperty("s3.host"); String currRegion = testProperties.getProperty("s3.region"); String currFileNameStr;//from www .j a v a2 s . co m SS3FileProvider currSS3 = new SS3FileProvider(); DefaultFileSystemManager currMan = new DefaultFileSystemManager(); currMan.addProvider(SS3Constants.S3SCHEME, currSS3); currMan.init(); StaticUserAuthenticator auth = new StaticUserAuthenticator("", currAccountStr, currKey); FileSystemOptions opts = new FileSystemOptions(); DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, auth); currFileNameStr = "test01.tmp"; String currUriStr = String.format("%s://%s/%s/%s", SS3Constants.S3SCHEME, currHost, currContainerStr, currFileNameStr); FileObject currFile = currMan.resolveFile(currUriStr, opts); log.info(String.format("getContent() file '%s'", currUriStr)); FileContent cont = currFile.getContent(); long contSize = cont.getSize(); Assert.assertTrue(contSize > 0); }
From source file:io.dockstore.common.FileProvisioning.java
private void downloadFromHttp(String path, String targetFilePath) { // VFS call, see https://github.com/abashev/vfs-s3/tree/branch-2.3.x and // https://commons.apache.org/proper/commons-vfs/filesystems.html try {/*from ww w .j a va 2s.co m*/ // trigger a copy from the URL to a local file path that's a UUID to avoid collision FileSystemManager fsManager = VFS.getManager(); org.apache.commons.vfs2.FileObject src = fsManager.resolveFile(path); org.apache.commons.vfs2.FileObject dest = fsManager .resolveFile(new File(targetFilePath).getAbsolutePath()); InputStream inputStream = src.getContent().getInputStream(); long inputSize = src.getContent().getSize(); OutputStream outputSteam = dest.getContent().getOutputStream(); copyFromInputStreamToOutputStream(inputStream, inputSize, outputSteam); // dest.copyFrom(src, Selectors.SELECT_SELF); } catch (IOException e) { LOG.error(e.getMessage()); throw new RuntimeException("Could not provision input files", e); } }