List of usage examples for org.apache.commons.vfs2 VFS getManager
public static synchronized FileSystemManager getManager() throws FileSystemException
From source file:org.wso2.carbon.transport.remotefilesystem.server.RemoteFileSystemConsumer.java
/** * Constructor for the RemoteFileSystemConsumer. * * @param id Name of the service that creates the consumer * @param fileProperties Map of property values * @param listener RemoteFileSystemListener instance to send callback * @throws RemoteFileSystemConnectorException if unable to start the connect to the remote server *///from w w w . j a va 2s . c om public RemoteFileSystemConsumer(String id, Map<String, String> fileProperties, RemoteFileSystemListener listener) throws RemoteFileSystemConnectorException { this.serviceName = id; this.fileProperties = fileProperties; this.remoteFileSystemListener = listener; setupParams(); try { fsManager = VFS.getManager(); Map<String, String> options = parseSchemeFileOptions(listeningDirURI); fso = FileTransportUtils.attachFileSystemOptions(options, fsManager); // TODO: Make this and other file related configurations configurable if (options != null && Constants.SCHEME_FTP.equals(options.get(Constants.SCHEME))) { FtpFileSystemConfigBuilder.getInstance().setPassiveMode(fso, true); } listeningDir = fsManager.resolveFile(listeningDirURI, fso); if (!listeningDir.isWriteable()) { postProcessAction = Constants.ACTION_NONE; } FileType fileType = getFileType(listeningDir); if (fileType != FileType.FOLDER) { String errorMsg = "[" + serviceName + "] File system server connector is used to " + "listen to a folder. But the given path does not refer to a folder."; final RemoteFileSystemConnectorException exception = new RemoteFileSystemConnectorException( errorMsg); remoteFileSystemListener.onError(exception); throw exception; } //Initialize the thread executor based on properties threadPool = new ThreadPoolFactory(threadPoolSize); } catch (FileSystemException e) { remoteFileSystemListener.onError(e); throw new RemoteFileSystemConnectorException( "[" + serviceName + "] Unable to initialize " + "the connection with server.", e); } }
From source file:pl.otros.logview.api.io.UtilsTest.java
@BeforeClass public static void setUp() throws IOException { fsManager = VFS.getManager(); System.out.println("Starting wiremock"); wireMock = new WireMockServer(wireMockConfig().port(PORT)); final byte[] gzipped = IOUtils .toByteArray(UtilsTest.class.getClassLoader().getResourceAsStream("hierarchy/hierarchy.log.gz")); final byte[] notGzipped = IOUtils .toByteArray(UtilsTest.class.getClassLoader().getResourceAsStream("hierarchy/hierarchy.log")); wireMock.stubFor(get(urlEqualTo("/log.txt")).willReturn( aResponse().withStatus(200).withHeader("Content-Type", "text/plain").withBody(notGzipped))); wireMock.stubFor(get(urlEqualTo("/log.txt.gz")).willReturn( aResponse().withStatus(200).withHeader("Content-Type", "text/plain").withBody(gzipped))); wireMock.start();/*w ww .j a va 2 s. c o m*/ }
From source file:pl.otros.logview.batch.BatchProcessor.java
public void process() throws Exception { StreamProcessingLogDataCollector logDataCollector = new StreamProcessingLogDataCollector( logDataParsedListener, batchProcessingContext); FileSystemManager manager = null;/*from w w w.j ava2 s.com*/ try { manager = VFS.getManager(); } catch (FileSystemException e1) { return; } int i = 0; ArrayList<FileObject> fileObjects = new ArrayList<FileObject>(); for (String file : files) { i++; FileObject resolveFile = null; try { batchProcessingContext.printIfVerbose("Resolving file %s [%d of %d]", file, i, files.size()); try { resolveFile = manager.resolveFile(file); } catch (Exception e) { file = new File(file).getAbsolutePath(); resolveFile = manager.resolveFile(file); } if (resolveFile != null) { fileObjects.add(resolveFile); } } catch (Exception e) { System.err.printf("Error resolving %s: %s", file, e.getMessage()); } } batchProcessingContext.setAllFiles(fileObjects); if (logDataParsedListener instanceof BatchProcessingListener) { ((BatchProcessingListener) logDataParsedListener).processingStarted(batchProcessingContext); } AutoDetectingImporterProvider importerProvider = new AutoDetectingImporterProvider( AllPluginables.getInstance().getLogImportersContainer().getElements()); i = 0; for (FileObject resolveFile : fileObjects) { i++; String fileName = resolveFile.getName().getBaseName(); try { batchProcessingContext.printIfVerbose("Opening file %s [%d of %d]", fileName, i, fileObjects.size()); batchProcessingContext.setCurrentFile(resolveFile); if (logDataParsedListener instanceof SingleFileBatchProcessingListener) { ((SingleFileBatchProcessingListener) logDataParsedListener) .processingFileStarted(batchProcessingContext); } LoadingInfo openFileObject = Utils.openFileObject(resolveFile); LogImporter logImporter = importerProvider.getLogImporter(openFileObject); if (logImporter == null) { System.err.println("Can't find suitable log importer for " + fileName); continue; } batchProcessingContext.printIfVerbose("Will user log importer: %s [%s]", logImporter.getName(), logImporter.getPluginableId()); // TODO for HTTP, Attempted read on closed stream. issue related to checking if file is gziped // Utils.closeQuietly(resolveFile); // String fileUrl = resolveFile.getURL().toString(); // resolveFile = manager.resolveFile(fileUrl); // openFileObject = Utils.openFileObject(resolveFile); batchProcessingContext.setCurrentFile(resolveFile); ParsingContext context = new ParsingContext(); context.setLogSource(resolveFile.getName().getFriendlyURI()); logImporter.initParsingContext(context); logImporter.importLogs(openFileObject.getContentInputStream(), logDataCollector, context); if (logDataParsedListener instanceof SingleFileBatchProcessingListener) { ((SingleFileBatchProcessingListener) logDataParsedListener) .processingFileFinished(batchProcessingContext); } batchProcessingContext.printIfVerbose("File %s processed [%d of %d]", fileName, i, files.size()); } catch (Exception e) { batchProcessingContext.printIfVerbose("Error processing file %s: %s", fileName, e.getMessage()); System.err.println("Can't resolve file " + fileName + ": " + e.getMessage()); continue; } } if (logDataParsedListener instanceof BatchProcessingListener) { ((BatchProcessingListener) logDataParsedListener).processingFinished(batchProcessingContext); } }
From source file:pl.otros.logview.gui.actions.read.DragAndDropFilesHandler.java
private void tryToImportUrl(TransferSupport support) throws UnsupportedFlavorException, IOException, ClassNotFoundException { URL transferData = (URL) support.getTransferable() .getTransferData(new DataFlavor(APPLICATION_X_JAVA_URL_DATA_FLAVOR)); openLogFile(VFS.getManager().resolveFile(transferData.toString())); }
From source file:pl.otros.logview.gui.actions.read.DragAndDropFilesHandler.java
private void tryToImportUriList(TransferSupport support) throws UnsupportedFlavorException, IOException, ClassNotFoundException { String transferData = (String) support.getTransferable().getTransferData(new DataFlavor(TEXT_URI_LIST)); String[] split = transferData.split("\n"); for (String string : split) { string = string.trim();/* w w w . j a va 2s. c om*/ if (StringUtils.isNotBlank(string)) { openLogFile(VFS.getManager().resolveFile(string)); } } }
From source file:pl.otros.logview.gui.actions.read.DragAndDropFilesHandler.java
private FileObject getFileObjectForLocalFile(File file) { try {/*from w w w. j a v a 2s. c om*/ return VFS.getManager().toFileObject(file); } catch (FileSystemException e) { throw new RuntimeException("Cannot open file: " + file, e); } }
From source file:pl.otros.logview.gui.Log4jPatternParserEditor.java
private void enableDragAndDrop() { logFileContent.setDragEnabled(true); final TransferHandler defaultTransferHandler = logFileContent.getTransferHandler(); TransferHandler transferHandler = new TransferHandler() { @Override/*from ww w. java 2 s . c o m*/ public boolean importData(TransferSupport support) { if (isText(support)) { try { String transferData = (String) support.getTransferable() .getTransferData(DataFlavor.stringFlavor); if (transferData.startsWith("file://")) { String firstLine = transferData; if (firstLine.indexOf('\n') > 0) { firstLine = firstLine.substring(0, firstLine.indexOf('\n') - 1); } loadLogContent(VFS.getManager().resolveFile(firstLine)); } else { defaultTransferHandler.importData(support); } return true; } catch (UnsupportedFlavorException e) { LOGGER.warning("Can't import data, UnsupportedFlavorException: " + e.getMessage()); } catch (IOException e) { LOGGER.warning("Can't import data, IOException: " + e.getMessage()); } } if (isListOfFiles(support)) { try { List data = (List) support.getTransferable().getTransferData(DataFlavor.javaFileListFlavor); if (data.size() > 0) { File file = (File) data.get(0); loadLogContent(VFS.getManager().resolveFile(file.getAbsolutePath())); return true; } } catch (UnsupportedFlavorException e) { LOGGER.warning("Can't import data, UnsupportedFlavorException: " + e.getMessage()); } catch (IOException e) { LOGGER.warning("Can't import data, IOException: " + e.getMessage()); } } return defaultTransferHandler.importData(support); } @Override public boolean canImport(TransferSupport support) { if (isText(support) || isListOfFiles(support)) { return true; } return defaultTransferHandler.canImport(support); } private boolean isListOfFiles(TransferSupport support) { return support.isDataFlavorSupported(DataFlavor.javaFileListFlavor); } private boolean isText(TransferSupport support) { return DataFlavor.selectBestTextFlavor(support.getDataFlavors()) != null; } }; logFileContent.setTransferHandler(transferHandler); loadLog.setTransferHandler(transferHandler); logFileContentLabel.setTransferHandler(transferHandler); }
From source file:pl.otros.logview.io.UtilsTest.java
@BeforeMethod @BeforeClass public static void setUp() throws FileSystemException { fsManager = VFS.getManager(); }
From source file:poisondog.android.image.ImageDiskCache.java
public synchronized Bitmap get(String key) throws FileSystemException { FileObject file = VFS.getManager().resolveFile(cache + "/" + HashFunction.md5(key)); Bitmap result = BitmapFactory.decodeFile(file.getURL().getPath(), new BitmapFactory.Options()); return result; }
From source file:poisondog.android.image.ImageDiskCache.java
public synchronized void put(String key, Bitmap value) throws FileSystemException, IOException { FileObject file = VFS.getManager().resolveFile(cache + "/" + HashFunction.md5(key)); OutputStream output = file.getContent().getOutputStream(); value.compress(Bitmap.CompressFormat.JPEG, 90, output); output.close();//from w w w . j av a2 s . c o m }