Java Code Examples for org.apache.commons.vfs2.FileType#IMAGINARY
The following examples show how to use
org.apache.commons.vfs2.FileType#IMAGINARY .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SftpClient.java From hop with Apache License 2.0 | 6 votes |
public FileType getFileType( String filename ) throws HopWorkflowException { try { SftpATTRS attrs = c.stat( filename ); if ( attrs == null ) { return FileType.IMAGINARY; } if ( ( attrs.getFlags() & SftpATTRS.SSH_FILEXFER_ATTR_PERMISSIONS ) == 0 ) { throw new HopWorkflowException( "Unknown permissions error" ); } if ( attrs.isDir() ) { return FileType.FOLDER; } else { return FileType.FILE; } } catch ( Exception e ) { throw new HopWorkflowException( e ); } }
Example 2
Source File: UrlFileObject.java From commons-vfs with Apache License 2.0 | 6 votes |
/** * Determines the type of the file. */ @Override protected FileType doGetType() throws Exception { try { // Attempt to connect & check status final URLConnection conn = url.openConnection(); final InputStream in = conn.getInputStream(); try { if (conn instanceof HttpURLConnection) { final int status = ((HttpURLConnection) conn).getResponseCode(); // 200 is good, maybe add more later... if (HttpURLConnection.HTTP_OK != status) { return FileType.IMAGINARY; } } return FileType.FILE; } finally { in.close(); } } catch (final FileNotFoundException e) { return FileType.IMAGINARY; } }
Example 3
Source File: LocalFile.java From commons-vfs with Apache License 2.0 | 6 votes |
/** * Returns the file's type. */ @Override protected FileType doGetType() throws Exception { // JDK BUG: 6192331 // if (!file.exists()) if (!file.exists() && file.length() < 1) { return FileType.IMAGINARY; } if (file.isDirectory()) { return FileType.FOLDER; } // In doubt, treat an existing file as file // if (file.isFile()) // { return FileType.FILE; // } // throw new FileSystemException("vfs.provider.local/get-type.error", file); }
Example 4
Source File: SftpFileObject.java From commons-vfs with Apache License 2.0 | 6 votes |
/** * Determines the type of this file, returns null if the file does not exist. */ @Override protected FileType doGetType() throws Exception { if (attrs == null) { statSelf(); } if (attrs == null) { return FileType.IMAGINARY; } if ((attrs.getFlags() & SftpATTRS.SSH_FILEXFER_ATTR_PERMISSIONS) == 0) { throw new FileSystemException("vfs.provider.sftp/unknown-permissions.error"); } if (attrs.isDir()) { return FileType.FOLDER; } return FileType.FILE; }
Example 5
Source File: HdfsFileObject.java From commons-vfs with Apache License 2.0 | 6 votes |
/** * @see org.apache.commons.vfs2.provider.AbstractFileObject#doGetType() */ @Override protected FileType doGetType() throws Exception { try { doAttach(); if (null == stat) { return FileType.IMAGINARY; } if (stat.isDirectory()) { return FileType.FOLDER; } return FileType.FILE; } catch (final FileNotFoundException fnfe) { return FileType.IMAGINARY; } }
Example 6
Source File: AbstractFileObject.java From commons-vfs with Apache License 2.0 | 5 votes |
/** * Creates this folder, if it does not exist. Also creates any ancestor files which do not exist. * * @throws FileSystemException if an error occurs. */ @Override public void createFolder() throws FileSystemException { synchronized (fileSystem) { // VFS-210: we create a folder only if it does not already exist. So this check should be safe. if (getType().hasChildren()) { // Already exists as correct type return; } if (getType() != FileType.IMAGINARY) { throw new FileSystemException("vfs.provider/create-folder-mismatched-type.error", fileName); } /* * VFS-210: checking for writeable is not always possible as the security constraint might be more complex * if (!isWriteable()) { throw new FileSystemException("vfs.provider/create-folder-read-only.error", name); * } */ // Traverse up the hierarchy and make sure everything is a folder final FileObject parent = getParent(); if (parent != null) { parent.createFolder(); } try { // Create the folder doCreateFolder(); // Update cached info handleCreate(FileType.FOLDER); } catch (final RuntimeException re) { throw re; } catch (final Exception exc) { throw new FileSystemException("vfs.provider/create-folder.error", fileName, exc); } } }
Example 7
Source File: DelegateFileObject.java From commons-vfs with Apache License 2.0 | 5 votes |
/** * Determines the type of the file, returns null if the file does not exist. */ @Override protected FileType doGetType() throws FileSystemException { if (file != null) { return file.getType(); } else if (children.size() > 0) { return FileType.FOLDER; } else { return FileType.IMAGINARY; } }
Example 8
Source File: DelegateFileObject.java From commons-vfs with Apache License 2.0 | 5 votes |
/** * Checks whether the file's type has changed, and fires the appropriate events. * * @param oldType The old FileType. * @throws Exception if an error occurs. */ private void maybeTypeChanged(final FileType oldType) throws Exception { final FileType newType = doGetType(); if (oldType == FileType.IMAGINARY && newType != FileType.IMAGINARY) { handleCreate(newType); } else if (oldType != FileType.IMAGINARY && newType == FileType.IMAGINARY) { handleDelete(); } }
Example 9
Source File: Http4FileObject.java From commons-vfs with Apache License 2.0 | 5 votes |
@Override protected FileType doGetType() throws Exception { lastHeadResponse = executeHttpUriRequest(new HttpHead(getInternalURI())); final int status = lastHeadResponse.getStatusLine().getStatusCode(); if (status == HttpStatus.SC_OK || status == HttpStatus.SC_METHOD_NOT_ALLOWED /* method is not allowed, but resource exist */) { return FileType.FILE; } else if (status == HttpStatus.SC_NOT_FOUND || status == HttpStatus.SC_GONE) { return FileType.IMAGINARY; } else { throw new FileSystemException("vfs.provider.http/head.error", getName(), Integer.valueOf(status)); } }
Example 10
Source File: AbstractFileObject.java From commons-vfs with Apache License 2.0 | 5 votes |
private void setFileType(final FileType type) { if (type != null && type != FileType.IMAGINARY) { try { fileName.setType(type); } catch (final FileSystemException e) { throw new RuntimeException(e.getMessage()); } } this.type = type; }
Example 11
Source File: HttpFileObject.java From commons-vfs with Apache License 2.0 | 5 votes |
/** * Determines the type of this file. Must not return null. The return value of this method is cached, so the * implementation can be expensive. */ @Override protected FileType doGetType() throws Exception { // Use the HEAD method to probe the file. final int status = this.getHeadMethod().getStatusCode(); if (status == HttpURLConnection.HTTP_OK || status == HttpURLConnection.HTTP_BAD_METHOD /* method is bad, but resource exist */) { return FileType.FILE; } else if (status == HttpURLConnection.HTTP_NOT_FOUND || status == HttpURLConnection.HTTP_GONE) { return FileType.IMAGINARY; } else { throw new FileSystemException("vfs.provider.http/head.error", getName(), Integer.valueOf(status)); } }
Example 12
Source File: FtpFileObject.java From commons-vfs with Apache License 2.0 | 5 votes |
/** * Determines the type of the file, returns null if the file does not exist. */ @Override protected FileType doGetType() throws Exception { // VFS-210 synchronized (getFileSystem()) { if (this.fileInfo == null) { getInfo(false); } if (this.fileInfo == UNKNOWN) { return FileType.IMAGINARY; } else if (this.fileInfo.isDirectory()) { return FileType.FOLDER; } else if (this.fileInfo.isFile()) { return FileType.FILE; } else if (this.fileInfo.isSymbolicLink()) { final FileObject linkDest = getLinkDestination(); // VFS-437: We need to check if the symbolic link links back to the symbolic link itself if (this.isCircular(linkDest)) { // If the symbolic link links back to itself, treat it as an imaginary file to prevent following // this link. If the user tries to access the link as a file or directory, the user will end up with // a FileSystemException warning that the file cannot be accessed. This is to prevent the infinite // call back to doGetType() to prevent the StackOverFlow return FileType.IMAGINARY; } return linkDest.getType(); } } throw new FileSystemException("vfs.provider.ftp/get-type.error", getName()); }
Example 13
Source File: RamFileData.java From commons-vfs with Apache License 2.0 | 5 votes |
/** */ void clear() { this.content = EMPTY; updateLastModified(); this.type = FileType.IMAGINARY; this.children.clear(); this.name = null; }
Example 14
Source File: ZipFileObject.java From commons-vfs with Apache License 2.0 | 5 votes |
protected ZipFileObject(final AbstractFileName name, final ZipEntry entry, final ZipFileSystem fs, final boolean zipExists) throws FileSystemException { super(name, fs); setZipEntry(entry); if (!zipExists) { type = FileType.IMAGINARY; } }
Example 15
Source File: SmbFileObject.java From commons-vfs with Apache License 2.0 | 5 votes |
/** * Determines the type of the file, returns null if the file does not exist. */ @Override protected FileType doGetType() throws Exception { if (!file.exists()) { return FileType.IMAGINARY; } else if (file.isDirectory()) { return FileType.FOLDER; } else if (file.isFile()) { return FileType.FILE; } throw new FileSystemException("vfs.provider.smb/get-type.error", getName()); }
Example 16
Source File: MimeFileObject.java From commons-vfs with Apache License 2.0 | 5 votes |
/** * Determines the type of the file, returns null if the file does not exist. */ @Override protected FileType doGetType() throws Exception { if (part == null) { return FileType.IMAGINARY; } if (isMultipart()) { // we cant have children ... return FileType.FILE_OR_FOLDER; } return FileType.FILE; }
Example 17
Source File: AbstractFileObject.java From commons-vfs with Apache License 2.0 | 5 votes |
/** * Called when the output stream for this file is closed. * * @throws Exception if an error occurs. */ protected void endOutput() throws Exception { if (getType() == FileType.IMAGINARY) { // File was created handleCreate(FileType.FILE); } else { // File has changed onChange(); } }
Example 18
Source File: WebSolutionFileObject.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 5 votes |
/** * Determines the type of this file. Must not return null. The return value of this method is cached, so the * implementation can be expensive. */ protected FileType doGetType() throws Exception { if ( getName().getDepth() < 2 ) { return FileType.FOLDER; } if ( fs.exists( getName() ) == false ) { return FileType.IMAGINARY; } if ( fs.isDirectory( getName() ) ) { return FileType.FOLDER; } return FileType.FILE; }
Example 19
Source File: AbstractFileObject.java From commons-vfs with Apache License 2.0 | 5 votes |
/** * Prepares this file for writing. Makes sure it is either a file, or its parent folder exists. Returns an output * stream to use to write the content of the file to. * * @param bAppend true when append to the file. * Note: If the underlying file system does not support appending, a FileSystemException is thrown. * @return An OutputStream where the new contents of the file can be written. * @throws FileSystemException if an error occurs; for example: * bAppend is true, and the underlying FileSystem does not support it */ public OutputStream getOutputStream(final boolean bAppend) throws FileSystemException { /* * VFS-210 if (getType() != FileType.IMAGINARY && !getType().hasContent()) { throw new * FileSystemException("vfs.provider/write-not-file.error", name); } if (!isWriteable()) { throw new * FileSystemException("vfs.provider/write-read-only.error", name); } */ if (bAppend && !fileSystem.hasCapability(Capability.APPEND_CONTENT)) { throw new FileSystemException("vfs.provider/write-append-not-supported.error", fileName); } if (getType() == FileType.IMAGINARY) { // Does not exist - make sure parent does final FileObject parent = getParent(); if (parent != null) { parent.createFolder(); } } // Get the raw output stream try { return doGetOutputStream(bAppend); } catch (final RuntimeException re) { throw re; } catch (final Exception exc) { throw new FileSystemException("vfs.provider/write.error", exc, fileName); } }
Example 20
Source File: RepositoryPublishDialog.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 4 votes |
protected boolean validateInputs( final boolean onConfirm ) { if ( super.validateInputs( onConfirm ) == false ) { return false; } if ( onConfirm == false ) { return true; } final String reportName = getFileNameTextField().getText(); if ( StringUtils.isEmpty( reportName ) == false && reportName.endsWith( REPORT_BUNDLE_EXTENSION ) == false ) { final String safeReportName = reportName + REPORT_BUNDLE_EXTENSION; getFileNameTextField().setText( safeReportName ); } try { final FileObject selectedView = getSelectedView(); final String validateName = getSelectedFile(); if ( validateName == null || selectedView == null ) { return false; } String filename = getFileNameTextField().getText(); if ( !PublishUtil.validateName( filename ) ) { JOptionPane.showMessageDialog( RepositoryPublishDialog.this, Messages.getInstance().formatMessage( "PublishToServerAction.IllegalName", filename, PublishUtil.getReservedCharsDisplay() ), Messages .getInstance().getString( "PublishToServerAction.Error.Title" ), JOptionPane.ERROR_MESSAGE ); return false; } final FileObject targetFile = selectedView.resolveFile( URLEncoder.encodeUTF8( getFileNameTextField().getText() ).replaceAll( ":", "%3A" ) .replaceAll( "\\+", "%2B" ).replaceAll( "\\!", "%21" ) ); if ( ROOT_DIRECTORY.equals( targetFile.getName().getParent().getPath() ) ) { JOptionPane.showMessageDialog( RepositoryPublishDialog.this, Messages.getInstance().formatMessage( "PublishToServerAction.TargetDirectoryIsRootDirectory", filename, PublishUtil.getReservedCharsDisplay() ), Messages .getInstance().getString( "PublishToServerAction.Error.Title" ), JOptionPane.ERROR_MESSAGE ); return false; } final FileObject fileObject = selectedView.getFileSystem().resolveFile( targetFile.getName() ); if ( fileObject.getType() == FileType.IMAGINARY ) { return true; } final int result = JOptionPane.showConfirmDialog( this, Messages.getInstance().formatMessage( "PublishToServerAction.FileExistsOverride", validateName ), Messages.getInstance().getString( "PublishToServerAction.Information.Title" ), JOptionPane.YES_NO_OPTION ); return result == JOptionPane.YES_OPTION; } catch ( FileSystemException fse ) { UncaughtExceptionsModel.getInstance().addException( fse ); return false; } catch ( UnsupportedEncodingException uee ) { UncaughtExceptionsModel.getInstance().addException( uee ); return false; } }