List of usage examples for org.apache.commons.vfs2 FileObject getContent
FileContent getContent() throws FileSystemException;
From source file:org.ow2.proactive_grid_cloud_portal.dataspace.FileSystem.java
private static void fillFileProps(FileObject fo, Map<String, Object> properties) throws FileSystemException { properties.put("x-proactive-ds-type", "FILE"); properties.put(HttpHeaders.LAST_MODIFIED, new Date(fo.getContent().getLastModifiedTime())); properties.put(HttpHeaders.CONTENT_TYPE, contentType(fo)); properties.put(HttpHeaders.CONTENT_LENGTH, fo.getContent().getSize()); }
From source file:org.ow2.proactive_grid_cloud_portal.dataspace.FileSystem.java
public static void copy(InputStream is, FileObject outFile) throws IOException { outFile.refresh();/* w w w . j av a 2s.c o m*/ Closer closer = Closer.create(); closer.register(is); try { OutputStream os = outFile.getContent().getOutputStream(); closer.register(os); ByteStreams.copy(is, os); } catch (IOException ioe) { throw closer.rethrow(ioe); } finally { closer.close(); } }
From source file:org.ow2.proactive_grid_cloud_portal.dataspace.FileSystem.java
public static void copy(FileObject fo, OutputStream os) throws IOException { fo.refresh();//from w ww . java 2s .c o m Closer closer = Closer.create(); closer.register(os); try { InputStream is = fo.getContent().getInputStream(); closer.register(is); ByteStreams.copy(is, os); } catch (IOException ioe) { throw closer.rethrow(ioe); } finally { closer.close(); } }
From source file:org.ow2.proactive_grid_cloud_portal.dataspace.FileSystem.java
private static String contentType(FileObject fo) throws FileSystemException { return fo.getContent().getContentInfo().getContentType(); }
From source file:org.ow2.proactive_grid_cloud_portal.dataspace.RestDataspaceImpl.java
private String mediaType(FileObject fo) throws FileSystemException { String contentType = fo.getContent().getContentInfo().getContentType(); return Strings.isNullOrEmpty(contentType) ? MediaType.APPLICATION_OCTET_STREAM : contentType; }
From source file:org.ow2.proactive_grid_cloud_portal.dataspace.util.VFSZipper.java
public static void zip(FileObject file, OutputStream out) throws IOException { Closer closer = Closer.create();/*from ww w .j a v a2 s.c o m*/ try { closer.register(out); InputStream in = file.getContent().getInputStream(); closer.register(in); ByteStreams.copy(in, out); } catch (IOException ioe) { throw closer.rethrow(ioe); } finally { closer.close(); } }
From source file:org.ow2.proactive_grid_cloud_portal.dataspace.util.VFSZipper.java
public static void unzip(InputStream is, FileObject file) throws IOException { Closer closer = Closer.create();/* w w w . j av a 2 s. c om*/ closer.register(is); try { OutputStream os = file.getContent().getOutputStream(); ZipOutputStream zos = new ZipOutputStream(os); closer.register(zos); ByteStreams.copy(is, zos); } catch (IOException ioe) { throw closer.rethrow(ioe); } finally { closer.close(); } }
From source file:org.ow2.proactive_grid_cloud_portal.dataspace.util.VFSZipper.java
public static boolean isZipFile(FileObject fo) throws FileSystemException { return Zipper.isZipFile(fo.getContent().getInputStream()); }
From source file:org.ow2.proactive_grid_cloud_portal.dataspace.util.VFSZipper.java
private static void copyFileContents(FileObject fo, ZipOutputStream zos) throws IOException { Closer closer = Closer.create();/*from w w w .j a v a 2 s . com*/ try { InputStream inputStream = fo.getContent().getInputStream(); closer.register(inputStream); ByteStreams.copy(inputStream, zos); } catch (IOException ioe) { throw closer.rethrow(ioe); } finally { closer.close(); } }
From source file:org.ow2.proactive_grid_cloud_portal.scheduler.SchedulerStateRest.java
/** * Either Pulls a file from the given DataSpace to the local file system or * list the content of a directory if the path refers to a directory In the * case the path to a file is given, the content of this file will be * returns as an input stream In the case the path to a directory is given, * the input stream returned will be a text stream containing at each line * the content of the directory//from w w w.j a v a 2 s.com * * @param sessionId * a valid session id * @param spaceName * the name of the data space involved (GLOBAL or USER) * @param filePath * the path to the file or directory whose content must be * received **/ @Override public InputStream pullFile(@HeaderParam("sessionid") String sessionId, @PathParam("spaceName") String spaceName, @PathParam("filePath") String filePath) throws IOException, NotConnectedRestException, PermissionRestException { checkAccess(sessionId, "pullFile"); Session session = dataspaceRestApi.checkSessionValidity(sessionId); filePath = normalizeFilePath(filePath, null); FileObject sourcefo = dataspaceRestApi.resolveFile(session, spaceName, filePath); if (!sourcefo.exists() || !sourcefo.isReadable()) { RuntimeException ex = new IllegalArgumentException( "File " + filePath + " does not exist or is not readable in space " + spaceName); logger.error(ex); throw ex; } if (sourcefo.getType().equals(FileType.FOLDER)) { logger.info("[pullFile] reading directory content from " + sourcefo.getURL()); // if it's a folder we return an InputStream listing its content StringBuilder sb = new StringBuilder(); String nl = System.lineSeparator(); for (FileObject fo : sourcefo.getChildren()) { sb.append(fo.getName().getBaseName() + nl); } return IOUtils.toInputStream(sb.toString()); } else if (sourcefo.getType().equals(FileType.FILE)) { logger.info("[pullFile] reading file content from " + sourcefo.getURL()); return sourcefo.getContent().getInputStream(); } else { RuntimeException ex = new IllegalArgumentException( "File " + filePath + " has an unsupported type " + sourcefo.getType()); logger.error(ex); throw ex; } }