/** * Checks, whether an content entity with the given name exists in this content location. This method will report * invalid filenames as non-existent. * * @param name the name of the new entity. * @return true, if an entity exists with this name, false otherwise. */ public boolean exists( final String name ) { if ( RepositoryUtilities.isInvalidPathName( name ) ) { return false; } try { final FileObject file = getBackend(); final FileObject child = file.resolveFile( name ); return child.exists(); } catch ( FileSystemException e ) { throw new RuntimeException( e ); } } }
/** * 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. */ 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 ); } }
/** * Returns the content entity with the given name. If the entity does not exist, an Exception will be raised. * * @param name the name of the entity to be retrieved. * @return the content entity for this name, never null. * @throws ContentIOException if an repository error occured. */ public ContentEntity getEntry( final String name ) throws ContentIOException { try { if ( RepositoryUtilities.isInvalidPathName( name ) ) { throw new IllegalArgumentException( "The name given is not valid." ); } final FileObject file = getBackend(); final FileObject child = file.resolveFile( name ); if ( child.exists() == false ) { throw new ContentIOException( "Not found:" + child ); } if ( child.isFolder() ) { return new FileObjectContentLocation( this, child ); } else if ( child.isFile() ) { return new FileObjectContentItem( this, child ); } else { throw new ContentIOException( "Not File nor directory." ); } } catch ( FileSystemException e ) { throw new RuntimeException( e ); } }
final FileObject child = file.resolveFile( name ); if ( child.exists() ) { if ( child.getContent().getSize() == 0 ) {
String baseFolder = info.getBaseFolder().toString(); String path = fullName.substring( fullName.indexOf( baseFolder ) + baseFolder.length() + 1 ); file_name = destinationFolderObject.resolveFile( path, NameScope.DESCENDENT );
@Override public FileObject resolveFile(final String path) throws FileSystemException { return decoratedFileObject.resolveFile(path); }
public static FileObject nextFile(final FileObject lastFile, final FileObject parent) throws FileSystemException { if (lastFile == null) return parent.resolveFile(genVersionSuffix(0)); final int lastVersion = getVersion(lastFile); return lastFile.getParent().resolveFile(genVersionSuffix(lastVersion + 1)); }
public void testFilesCache() throws Exception { final FileObject scratchFolder = getWriteFolder(); final FileObject dir1 = scratchFolder.resolveFile("dir1"); final FileObject dir1_2 = scratchFolder.resolveFile("dir1"); // since both are still referenced they are not purged assertSame(dir1, dir1_2); }
public void testFilesCache() throws Exception { final FileObject scratchFolder = getWriteFolder(); final FileObject dir1 = scratchFolder.resolveFile("dir1"); final FileObject dir1_2 = scratchFolder.resolveFile("dir1"); assertFalse("Should always be new instance with NullCache", dir1 == dir1_2); }
public void testFilesCache() throws Exception { final FileObject scratchFolder = getWriteFolder(); final FileObject dir1 = scratchFolder.resolveFile("dir1"); final FileObject dir1_2 = scratchFolder.resolveFile("dir1"); // since both are still referenced they are not purged assertSame(dir1, dir1_2); }
@Override public InputStream getObject(String externalKey) { try { return root.resolveFile(externalKey).getContent().getInputStream(); } catch (FileSystemException ex) { throw new StorageException(ex); } }
/** * Tests content. */ public void testContent() throws Exception { // Test non-empty file FileObject file = getReadFolder().resolveFile("file1.txt"); assertSameContent(FILE1_CONTENT, file); // Test empty file file = getReadFolder().resolveFile("empty.txt"); assertSameContent("", file); }
/** Helper method, may be used in cache specific tests. */ protected int getFileHashCode() throws FileSystemException { final FileObject fo = getWriteFolder().resolveFile("file2"); if (!fo.exists()) { fo.createFile(); } return fo.hashCode(); } }
/** * Tests resolution of an absolute file name. */ public void testHashURL() throws Exception { final FileObject file = getReadFolder().resolveFile("test-hash-#test.txt"); assertEquals(file.toString(), UriParser.decode(file.getURL().toString())); } }
/** * Deletes a non existent file */ public void testDeleteNonExistantFile() throws Exception { final FileObject scratchFolder = createScratchFolder(); final FileObject file = scratchFolder.resolveFile("dir1/aa.txt"); assertFalse(file.delete()); }
/** * Tests getting the last modified time of a folder. * * @throws FileSystemException if error occurred */ public void testGetLastModifiedFolder() throws FileSystemException { final FileObject file = getReadFolder().resolveFile("dir1"); assertNotEquals(0L, file.getContent().getLastModifiedTime()); }
/** * Clean up the permission-modified file to not affect other tests. */ @Override protected void tearDown() throws Exception { final FileObject scratchFolder = getWriteFolder(); final FileObject file = scratchFolder.resolveFile(FILENAME); file.setWritable(true, true); file.delete(); super.tearDown(); }
@Test public void testNestedAttributes() throws Exception { final FileObject nested = JarProviderTestCase.getTestJar(VFS.getManager(), "nested.jar"); final FileObject file = nested.resolveFile("test.jar"); final Map<String, Object> attributes = file.getContent().getAttributes(); Assert.assertEquals("1.0", attributes.get("Manifest-Version")); // Debugging: // this.printAttributes(attributes); } }
/** * Tests create-delete-create-a-file sequence on the same file system. */ public void testRenameFile() throws Exception { final FileObject scratchFolder = createScratchFolder(); // Create direct child of the test folder final FileObject file = scratchFolder.resolveFile("file1.txt"); assertTrue(!file.exists()); final String content = createTestFile(file); // Make sure we can move the new file to another file on the same file system moveFile(scratchFolder, file, content); }
private void moveFile(final FileObject scratchFolder, final FileObject file, final String content) throws FileSystemException, Exception { final FileObject fileMove = scratchFolder.resolveFile("file1move.txt"); assertTrue(!fileMove.exists()); file.moveTo(fileMove); assertTrue(!file.exists()); assertTrue(fileMove.exists()); assertSameContent(content, fileMove); // Delete the file. assertTrue(fileMove.exists()); assertTrue(fileMove.delete()); }