List of usage examples for org.apache.commons.vfs2 FileObject createFile
void createFile() throws FileSystemException;
From source file:org.obiba.opal.fs.DecoratedFileObjectTest.java
@Test public void testMoveTo() throws FileSystemException { FileObject file_1 = root.resolveFile("file_1"); file_1.createFile(); FileObject file_2 = root.resolveFile("file_2"); FileObject decorate_1 = new DFO(file_1); FileObject decorate_2 = new DFO(file_2); System.out.println(decorate_1); System.out.println(decorate_2); decorate_1.moveTo(decorate_2);//from w ww . j av a 2s . c o m // System.out.println(file_1); // log.debug("file_1: {}", file_1); }
From source file:org.ow2.proactive_grid_cloud_portal.dataspace.FileSystem.java
public FileObject createFile(String pathname) throws FileSystemException { FileObject fo = fsm.resolveFile(pathname); fo.refresh();/* w ww. jav a 2 s. co m*/ if (!fo.exists()) { fo.createFile(); } return fo; }
From source file:org.ow2.proactive_grid_cloud_portal.dataspace.RestDataspaceImpl.java
@POST @Path("/{dataspace}/{path-name:.*}") public Response create(@HeaderParam("sessionid") String sessionId, @PathParam("dataspace") String dataspacePath, @PathParam("path-name") String pathname, @FormParam("mimetype") String mimeType) throws NotConnectedRestException, PermissionRestException { checkPathParams(dataspacePath, pathname); Session session = checkSessionValidity(sessionId); try {/* w w w . j a v a 2 s .co m*/ FileObject fileObject = resolveFile(session, dataspacePath, pathname); if (mimeType.equals(org.ow2.proactive_grid_cloud_portal.common.FileType.FOLDER.getMimeType())) { logger.debug(String.format("Creating folder %s in %s", pathname, dataspacePath)); fileObject.createFolder(); } else if (mimeType.equals(org.ow2.proactive_grid_cloud_portal.common.FileType.FILE.getMimeType())) { logger.debug(String.format("Creating file %s in %s", pathname, dataspacePath)); fileObject.createFile(); } else { return serverErrorRes("Cannot create specified file since mimetype is not specified"); } return Response.ok().build(); } catch (FileSystemException e) { logger.error(String.format("Cannot create %s in %s", pathname, dataspacePath), e); throw rethrow(e); } catch (Throwable e) { logger.error(String.format("Cannot create %s in %s", pathname, dataspacePath), e); throw rethrow(e); } }
From source file:org.ow2.proactive_grid_cloud_portal.dataspace.RestDataspaceImpl.java
public void writeFile(InputStream inputStream, FileObject outputFile, String encoding) throws FileSystemException, IOException { try {/* w ww . j av a 2 s. c o m*/ if (outputFile.exists()) { outputFile.delete(SELECT_SELF); } if (Strings.isNullOrEmpty(encoding)) { outputFile.createFile(); FileSystem.copy(inputStream, outputFile); } else if ("gzip".equals(encoding)) { VFSZipper.GZIP.unzip(inputStream, outputFile); } else if ("zip".equals(encoding)) { VFSZipper.ZIP.unzip(inputStream, outputFile); } else { outputFile.createFile(); FileSystem.copy(inputStream, outputFile); } } catch (Throwable error) { if (outputFile != null) { try { if (outputFile.exists()) { outputFile.delete(SELECT_SELF); } } catch (FileSystemException e1) { logger.error("Error occurred while deleting partially created file.", e1); } } Throwables.propagateIfInstanceOf(error, FileSystemException.class); Throwables.propagateIfInstanceOf(error, IOException.class); Throwables.propagate(error); } }
From source file:org.ow2.proactive_grid_cloud_portal.scheduler.SchedulerStateRest.java
/** * Pushes a file from the local file system into the given DataSpace * /*from www . ja va 2 s . c o m*/ * @param sessionId * a valid session id * @param spaceName * the name of the DataSpace * @param filePath * the path inside the DataSpace where to put the file e.g. * "/myfolder" * @param multipart * the form data containing : - fileName the name of the file * that will be created on the DataSpace - fileContent the * content of the file * @return true if the transfer succeeded * @see org.ow2.proactive.scheduler.common.SchedulerConstants for spaces * names **/ @Override public boolean pushFile(@HeaderParam("sessionid") String sessionId, @PathParam("spaceName") String spaceName, @PathParam("filePath") String filePath, MultipartFormDataInput multipart) throws IOException, NotConnectedRestException, PermissionRestException { checkAccess(sessionId, "pushFile"); Session session = dataspaceRestApi.checkSessionValidity(sessionId); Map<String, List<InputPart>> formDataMap = multipart.getFormDataMap(); List<InputPart> fNL = formDataMap.get("fileName"); if ((fNL == null) || (fNL.size() == 0)) { throw new IllegalArgumentException("Illegal multipart argument definition (fileName), received " + fNL); } String fileName = fNL.get(0).getBody(String.class, null); List<InputPart> fCL = formDataMap.get("fileContent"); if ((fCL == null) || (fCL.size() == 0)) { throw new IllegalArgumentException( "Illegal multipart argument definition (fileContent), received " + fCL); } InputStream fileContent = fCL.get(0).getBody(InputStream.class, null); if (fileName == null) { throw new IllegalArgumentException("Wrong file name : " + fileName); } filePath = normalizeFilePath(filePath, fileName); FileObject destfo = dataspaceRestApi.resolveFile(session, spaceName, filePath); URL targetUrl = destfo.getURL(); logger.info("[pushFile] pushing file to " + targetUrl); if (!destfo.isWriteable()) { RuntimeException ex = new IllegalArgumentException( "File " + filePath + " is not writable in space " + spaceName); logger.error(ex); throw ex; } if (destfo.exists()) { destfo.delete(); } // used to create the necessary directories if needed destfo.createFile(); dataspaceRestApi.writeFile(fileContent, destfo, null); return true; }
From source file:org.pentaho.di.repository.filerep.KettleFileRepository_DatabaseNames_Test.java
@Test public void getDatabaseId_ReturnsExactMatch_PriorToCaseInsensitiveMatch() throws Exception { final String exact = "databaseExactMatch"; final String similar = exact.toLowerCase(); assertNotSame(similar, exact);/*from w w w . ja va2 s. c o m*/ DatabaseMeta db = saveDatabase(exact); // simulate legacy repository - store a DB with a name different only in case DatabaseMeta another = new DatabaseMeta(); another.setName(similar); FileObject fileObject = repository.getFileObject(another); assertFalse(fileObject.exists()); // just create it - enough for this case fileObject.createFile(); assertTrue(fileObject.exists()); ObjectId id = this.repository.getDatabaseID(exact); assertEquals(db.getObjectId(), id); }
From source file:org.pentaho.di.trans.steps.pentahoreporting.urlrepository.FileObjectContentLocation.java
/** * Creates a new data item in the current location. This method must never return null. This method will fail if an * entity with the same name exists in this location. * * @param name the name of the new entity. * @return the newly created entity, never null. * @throws ContentCreationException if the item could not be created. *//*from ww w. j a v a2 s . c o m*/ public ContentItem createItem(final String name) throws ContentCreationException { if (RepositoryUtilities.isInvalidPathName(name)) { throw new IllegalArgumentException("The name given is not valid."); } try { final FileObject file = getBackend(); final FileObject child = file.resolveFile(name); if (child.exists()) { if (child.getContent().getSize() == 0) { // probably one of the temp files created by the pentaho-system return new FileObjectContentItem(this, child); } throw new ContentCreationException("File already exists: " + child); } try { child.createFile(); return new FileObjectContentItem(this, child); } catch (IOException e) { throw new ContentCreationException("IOError while create", e); } } catch (FileSystemException e) { throw new RuntimeException(e); } }
From source file:org.pentaho.di.trans.steps.pentahoreporting.urlrepository.FileObjectContentLocation.java
/** * Creates a new content location in the current location. This method must never return null. This method will fail * if an entity with the same name exists in this location. * * @param name the name of the new entity. * @return the newly created entity, never null. * @throws ContentCreationException if the item could not be created. *//*from w w w . j a va2 s . c o m*/ public ContentLocation createLocation(final String name) throws ContentCreationException { if (RepositoryUtilities.isInvalidPathName(name)) { throw new IllegalArgumentException("The name given is not valid."); } try { final FileObject file = getBackend(); final FileObject child = file.resolveFile(name); if (child.exists()) { throw new ContentCreationException("File already exists."); } child.createFile(); try { return new FileObjectContentLocation(this, child); } catch (ContentIOException e) { throw new ContentCreationException("Failed to create the content-location", e); } } catch (FileSystemException e) { throw new RuntimeException(e); } }
From source file:org.pentaho.di.utils.TestUtils.java
public static String createRamFile(String path) { try {/*from w w w . ja va 2 s .c om*/ FileObject file = KettleVFS.getInstance().getFileSystemManager().resolveFile("ram://" + path); file.createFile(); return file.getName().getURI(); } catch (FileSystemException e) { throw new RuntimeException(e); } }
From source file:org.pentaho.hadoop.shim.common.DistributedCacheTestUtil.java
static FileObject createTestHadoopConfiguration(String rootFolderName) throws Exception { FileObject location = KettleVFS.getFileObject(rootFolderName + "/hadoop-configurations/test-config"); FileObject lib = location.resolveFile("lib"); FileObject libPmr = lib.resolveFile("pmr"); FileObject pmrLibJar = libPmr.resolveFile("configuration-specific.jar"); lib.createFolder();// w w w . j a v a 2 s .co m lib.resolveFile("required.jar").createFile(); libPmr.createFolder(); pmrLibJar.createFile(); return location; }