List of usage examples for org.apache.commons.vfs2 FileObject getName
FileName getName();
From source file:pl.otros.vfs.browser.util.VFSUtils.java
private static boolean isLocalFileSystem(FileObject fileObject) { return fileObject.getName().getScheme().equalsIgnoreCase("file"); }
From source file:pl.otros.vfs.browser.VfsBrowser.java
License:asdf
public void goToUrl(final FileObject fileObject) { if (taskContext != null) { taskContext.setStop(true);/* ww w . ja v a 2s.c o m*/ } try { final FileObject[] files = VFSUtils.getFiles(fileObject); LOGGER.info("Have {} files in {}", files.length, fileObject.getName().getFriendlyURI()); this.currentLocation = fileObject; taskContext = new TaskContext(Messages.getMessage("browser.checkingSFtpLinksTask"), files.length); taskContext.setIndeterminate(false); SwingWorker<Void, Void> refreshWorker = new SwingWorker<Void, Void>() { int icon = 0; Icon[] icons = new Icon[] { Icons.getInstance().getNetworkStatusOnline(), Icons.getInstance().getNetworkStatusAway(), Icons.getInstance().getNetworkStatusOffline() }; @Override protected void process(List<Void> chunks) { loadingProgressBar.setIndeterminate(taskContext.isIndeterminate()); loadingProgressBar.setMaximum(taskContext.getMax()); loadingProgressBar.setValue(taskContext.getCurrentProgress()); loadingProgressBar.setString(String.format("%s [%d of %d]", taskContext.getName(), taskContext.getCurrentProgress(), taskContext.getMax())); loadingIconLabel.setIcon(icons[++icon % icons.length]); } @Override protected Void doInBackground() throws Exception { try { while (!taskContext.isStop()) { publish(); Thread.sleep(300); } } catch (InterruptedException ignore) { //ignore } return null; } }; new Thread(refreshWorker).start(); if (!skipCheckingLinksButton.isSelected()) { VFSUtils.checkForSftpLinks(files, taskContext); } taskContext.setStop(true); final FileObject[] fileObjectsWithParent = addParentToFiles(files); Runnable r = new Runnable() { @Override public void run() { vfsTableModel.setContent(fileObjectsWithParent); try { pathField.setText(fileObject.getURL().toString()); } catch (FileSystemException e) { LOGGER.error("Can't get URL", e); } if (tableFiles.getRowCount() > 0) { tableFiles.getSelectionModel().setSelectionInterval(0, 0); } updateStatusText(); } }; SwingUtils.runInEdt(r); } catch (Exception e) { LOGGER.error("Can't go to URL for " + fileObject, e); final String message = ExceptionsUtils.getRootCause(e).getClass().getName() + ": " + ExceptionsUtils.getRootCause(e).getLocalizedMessage(); Runnable runnable = new Runnable() { public void run() { JOptionPane.showMessageDialog(VfsBrowser.this, message, Messages.getMessage("browser.badlocation"), JOptionPane.ERROR_MESSAGE); } }; SwingUtils.runInEdt(runnable); } }
From source file:pl.otros.vfs.browser.VfsBrowser.java
License:asdf
public void selectNextFileStarting(String string) { LOGGER.debug("Looking for file starting with {}", string); int selectedRow = tableFiles.getSelectedRow(); selectedRow = selectedRow < 0 ? 0 : selectedRow; LOGGER.debug("Starting search with row {}", selectedRow); boolean fullLoop; int started = selectedRow; do {/*from w w w . j a v a 2 s. c o m*/ LOGGER.debug("Checking table row {}", selectedRow); int convertRowIndexToModel = tableFiles.convertRowIndexToModel(selectedRow); LOGGER.debug("Table row {} is row {} from model", selectedRow, convertRowIndexToModel); FileObject fileObject = vfsTableModel.get(convertRowIndexToModel); LOGGER.debug("Checking {} if begins with {}", fileObject.getName().getBaseName(), string); if (fileObject.getName().getBaseName().toLowerCase().startsWith(string.toLowerCase())) { tableFiles.getSelectionModel().setSelectionInterval(selectedRow, selectedRow); tableFiles.scrollRectToVisible(new Rectangle(tableFiles.getCellRect(selectedRow, 0, true))); break; } selectedRow++; selectedRow = selectedRow >= tableFiles.getRowCount() ? 0 : selectedRow; fullLoop = selectedRow == started; } while (!fullLoop); }
From source file:poisondog.android.image.ImageFetcher.java
protected Bitmap processBitmap(Object data) { if (!(data instanceof String)) return null; try {// w ww.ja v a 2 s . c om FileObject remote = VFS.getManager().resolveFile((String) data); if (remote.getURL().getProtocol() == "file") return super.processBitmap(remote.getURL().toString()); // FileObject file = CacheDirectory.download(remote); FileObject file = mDestination.resolveFile(remote.getName().getBaseName()); CopyTask task = new CopyTask(remote.getContent().getInputStream(), file.getContent().getOutputStream()); task.transport(); if (file == null) { return null; } return super.processBitmap(file.getURL().toString()); } catch (FileSystemException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return null; }
From source file:poisondog.commons.vfs.FileComparator.java
public int compare(FileObject obj1, FileObject obj2) { try {//from w w w. j a v a 2s . co m if (obj1.getType() == FileType.FOLDER && obj2.getType() != FileType.FOLDER) return -1; if (obj1.getType() != FileType.FOLDER && obj2.getType() == FileType.FOLDER) return 1; } catch (Exception e) { e.printStackTrace(); } return obj1.getName().getBaseName().compareTo(obj2.getName().getBaseName()); }
From source file:pt.webdetails.cpk.elements.impl.kettleoutputs.ResultFilesKettleOutput.java
@Override public void processResult(KettleResult result) { logger.debug("Process Result Files"); List<FileObject> files = new ArrayList<FileObject>(); for (ResultFile resultFile : result.getFiles()) { files.add(resultFile.getFile()); }//from w ww.j a va2s . c o m if (files.isEmpty()) { logger.warn("Processing result files but no files found"); this.getResponse().setStatus(HttpServletResponse.SC_NO_CONTENT); return; } String defaultAttachmentName = this.getConfiguration().getAttachmentName(); try { if (files.size() == 1 && files.get(0).getType() == FileType.FILE) { // Singe file FileObject file = files.get(0); InputStream fileInputStream = KettleVFS.getInputStream(file); FileName fileName = file.getName(); String defaultMimeType = this.getConfiguration().getMimeType(); String mimeType = defaultMimeType != null ? defaultMimeType : MimeTypes.getMimeType(fileName.getBaseName()); String attachmentName = defaultAttachmentName != null ? defaultAttachmentName : fileName.getBaseName(); CpkUtils.send(this.getResponse(), fileInputStream, mimeType, attachmentName, this.getConfiguration().getSendResultAsAttachment()); } else { // More than one file, or folder // Build a zip / tar and ship it over! ZipUtil zip = new ZipUtil(); zip.buildZipFromFileObjectList(files); String attachmentName = defaultAttachmentName != null ? defaultAttachmentName : zip.getZipNameToDownload(); CpkUtils.send(this.getResponse(), zip.getZipInputStream(), MimeTypes.ZIP, attachmentName, true); } } catch (FileSystemException ex) { logger.error("Failed sending files from kettle result.", ex); } }
From source file:pt.webdetails.cpk.utils.ZipUtil.java
private ZipOutputStream writeEntriesToZip(Collection<FileObject> files, ZipOutputStream zipOut) { int i = 0;//from w ww. j a v a2 s.co m try { for (FileObject file : files) { i++; logger.debug("Files to process:" + files.size()); logger.debug("Files processed: " + i); logger.debug("Files remaining: " + (files.size() - i)); logger.debug(file.getName().getPath()); fileListing.add(removeTopFilenamePathFromString(file.getName().getPath())); ZipEntry zip = null; if (file.getType() == FileType.FOLDER) { zip = new ZipEntry( removeTopFilenamePathFromString(file.getName().getPath() + File.separator + "")); zipOut.putNextEntry(zip); } else { zip = new ZipEntry(removeTopFilenamePathFromString(file.getName().getPath())); zipOut.putNextEntry(zip); byte[] bytes = IOUtils.toByteArray(file.getContent().getInputStream()); zipOut.write(bytes); zipOut.closeEntry(); } } } catch (Exception exception) { logger.error(exception); } return zipOut; }
From source file:se.kth.hopsworks.zeppelin.notebook.repo.FSNotebookRepo.java
@Override public List<NoteInfo> list() throws IOException { FileObject rootDir = getRootDir(); FileObject projectDir = null; if (this.project != null) { projectDir = rootDir.resolveFile(this.project.getName(), NameScope.CHILD); }// w w w. j a va 2 s.c o m LinkedList<FileObject> children = getNotes(rootDir, projectDir); List<NoteInfo> infos = new LinkedList<>(); for (FileObject f : children) { String fileName = f.getName().getBaseName(); if (f.isHidden() || fileName.startsWith(".") || fileName.startsWith("#") || fileName.startsWith("~")) { // skip hidden, temporary files continue; } if (!isDirectory(f)) { // currently single note is saved like, [NOTE_ID]/note.json. // so it must be a directory continue; } NoteInfo info = null; try { info = getNoteInfo(f); if (info != null) { infos.add(info); } } catch (IOException e) { logger.error("Can't read note " + f.getName().toString(), e); } } return infos; }
From source file:se.kth.hopsworks.zeppelin.notebook.repo.FSNotebookRepo.java
@Override public void save(Note note) throws IOException { GsonBuilder gsonBuilder = new GsonBuilder(); gsonBuilder.setPrettyPrinting();/*from w ww.j av a 2 s . c om*/ Gson gson = gsonBuilder.create(); String json = gson.toJson(note); FileObject rootDir = getRootDir(); FileObject projectDir = rootDir.resolveFile(this.project.getName(), NameScope.CHILD); if (!projectDir.exists()) { projectDir.createFolder(); } if (!isDirectory(projectDir)) { throw new IOException(projectDir.getName().toString() + " is not a directory"); } FileObject noteDir = projectDir.resolveFile(note.id(), NameScope.CHILD); if (!noteDir.exists()) { noteDir.createFolder(); } if (!isDirectory(noteDir)) { throw new IOException(noteDir.getName().toString() + " is not a directory"); } FileObject noteJson = noteDir.resolveFile("note.json", NameScope.CHILD); // false means not appending. creates file if not exists OutputStream out = noteJson.getContent().getOutputStream(false); out.write(json.getBytes(conf.getString(ConfVars.ZEPPELIN_ENCODING))); out.close(); noteJson.moveTo(noteDir.resolveFile("note.json", NameScope.CHILD)); }
From source file:se.kth.hopsworks.zeppelin.notebook.repo.FSNotebookRepo.java
@Override public void remove(String noteId) throws IOException { FileObject rootDir = fsManager.resolveFile(getPath("/")); FileObject projectDir = rootDir.resolveFile(this.project.getName(), NameScope.CHILD); if (!projectDir.exists() || !isDirectory(projectDir)) { // no project dir return;//from ww w. j a v a 2s .c o m } FileObject noteDir = projectDir.resolveFile(noteId, NameScope.CHILD); if (!noteDir.exists()) { // nothing to do return; } if (!isDirectory(noteDir)) { // it is not look like zeppelin note savings throw new IOException("Can not remove " + noteDir.getName().toString()); } noteDir.delete(Selectors.SELECT_SELF_AND_CHILDREN); }