List of usage examples for org.apache.commons.vfs VFS getManager
public static synchronized FileSystemManager getManager() throws FileSystemException
From source file:org.vivoweb.harvester.util.FileAide.java
/** * Resolves a FileObject relative to the execution directory * @param path the path to resolve//ww w . j av a 2s.c om * @return the FileObject * @throws IOException error resolving */ private static FileObject getFileObject(String path) throws IOException { if (path == null) { return null; } return VFS.getManager().resolveFile(new File("."), path); }
From source file:pt.webdetails.cpf.repository.vfs.VfsRepositoryAccess.java
private FileObject setRepoPath(String path) { FileSystemManager fileSystemManager; try {/*from w w w. j a va2s . c om*/ if (!path.endsWith("" + File.separatorChar)) { path += File.separatorChar; } fileSystemManager = VFS.getManager(); FileObject fileObject; fileObject = fileSystemManager.resolveFile(path); if (fileObject == null) { throw new IOException("File cannot be resolved: " + path); } if (!fileObject.exists()) { throw new IOException("File does not exist: " + path); } return fileObject; } catch (Exception e) { log.error("Error setting path for repository: " + path, e); } return null; }
From source file:r.base.connections.GzFileConnectionTest.java
@Test public void readCompressed() throws IOException { FileObject file = VFS.getManager().resolveFile(getClass().getResource("test.txt.gz").getFile()); GzFileConnection conn = new GzFileConnection(file); BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream())); assertThat(reader.readLine(), equalTo("hello world")); }
From source file:r.base.connections.GzFileConnectionTest.java
@Test public void multipleReads() throws IOException { FileObject file = VFS.getManager().resolveFile(getClass().getResource("test2.txt").getFile()); GzFileConnection conn = new GzFileConnection(file); assertThat(Connections.readChar(conn, 9, false), equalTo("The quick")); assertThat(Connections.readChar(conn, 6, false), equalTo(" brown")); }
From source file:r.base.connections.GzFileConnectionTest.java
@Test public void readUnCompressed() throws IOException { FileObject file = VFS.getManager().resolveFile(getClass().getResource("test.txt").getFile()); GzFileConnection conn = new GzFileConnection(file); BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream())); assertThat(reader.readLine(), equalTo("Hello again, dear world")); }
From source file:r.lang.Context.java
/** * * @return a new top level context using the default VFS FileSystemManager and the * renjin-core jar as the R_HOME directory. * * @see org.apache.commons.vfs.VFS#getManager() * @see r.util.FileSystemUtils#homeDirectoryInCoreJar() *//*w w w. jav a2 s . c o m*/ public static Context newTopLevelContext() { try { return newTopLevelContext(VFS.getManager(), FileSystemUtils.homeDirectoryInCoreJar(), FileSystemUtils.workingDirectory(VFS.getManager())); } catch (FileSystemException e) { throw new RuntimeException("Could not init FileSystemManger", e); } }
From source file:rsc.backend.connections.localConnection.LocalConnection.java
private void init() { try {// w ww.j a v a 2 s.c o m cListener = new Vector<ConnectionListener>(); configurator = new LocalConnectionConfigurator(this); fs = VFS.getManager().resolveFile("file:///").getFileSystem(); } catch (FileSystemException ex) { RSC.log(Level.SEVERE, "cant initialize local vfs", ex); } }
From source file:rsc.backend.connections.sshConnection.SSHConnection.java
public void connect() throws ConnectionException { if (isConnected()) { return;/*from ww w . ja v a 2 s.c o m*/ } if (fs == null) { try { fs = VFS.getManager() .resolveFile("sftp://" + username + ":" + password + "@" + hostname + ":" + port + "/") .getFileSystem(); } catch (FileSystemException ex) { RSC.log(Level.SEVERE, "error connecting ssh-filesystem", ex); if (fs != null) { fs.getFileSystemManager().closeFileSystem(fs); fs = null; } session = null; throw new ConnectionException(); } } if (session == null) { createSession(); } UserInfo ui = new MyUserInfo(); session.setUserInfo(ui); try { session.connect(30000); } catch (JSchException ex) { RSC.log(Level.SEVERE, "error connecting ssh", ex); if (fs != null) { fs.getFileSystemManager().closeFileSystem(fs); fs = null; } session = null; System.out.println("cant connect: " + ex.getMessage()); throw new ConnectionException(); } for (ConnectionListener l : cListener) { l.connectionConnect(); } }
From source file:uk.ac.liv.shaman.vfsme.CommonVFSMediaAdaptor.java
@Override public Object parse(INode parent) throws Exception { String html = null;//from www . j a v a 2 s. c o m try { String pre = getExtension(); // Case for archive files if (pre != null) html = toHTML(pre); else { // case for files embedded in archives String s = getURI().toString(); int pos = s.lastIndexOf('/'); if (pos != -1) { s = s.substring(pos); pos = s.lastIndexOf('.'); if (pos != -1) s = s.substring(s.lastIndexOf('.')); else s = null; } else s = null; FileSystemManager m = VFS.getManager(); FileObject fo = m.resolveFile(getURI().toString()); // Workaround for loopy: loopy breaks when reading at the end of the input stram; // we stop at the lenght of the file to avoid an arrayindexoutofbound File f = Fab4utils.copyToTemp(fo.getContent().getInputStream(), "vfstemp", s, fo.getContent().getSize()); return Fab4utils.parseHelper(f, getURI(), getDocument(), parent); // FileInputStream is = new FileInputStream(f); // String mime = null; // String mime2 = null; // byte[] bufferData = new byte[Math.max(1024, FileGuess.minBytes)]; // int a; // MessageDigest md = null; // try { // md = MessageDigest.getInstance("MD5"); // } catch (NoSuchAlgorithmException e1) { // } // // while ((a = is.read(bufferData)) != -1) { // if (mime2 == null && a >= FileGuess.minBytes) { // mime2 = FileGuess // .guess(bufferData, getURI().toString()); // if (mime2 == null) // mime2 = ""; // } // if (md != null) // md.update(bufferData, 0, a); // } // is.close(); // is = new FileInputStream(f); // InputUni iu = InputUni.getInstance(is, getURI(), getGlobal() // .getCache()); // mime = iu.getContentType(); // byte[] digest = md.digest(); // 128 bit or 16 bytes // MediaLoader.MD5Cache.put(getURI(), digest); // MediaLoader.FileCache.put(getURI(), f); // if (mime == null // || mime.equalsIgnoreCase("application/octet-stream") // || mime.equals("text/html")) { // mime = mime2; // iu.setContentType(mime); // } // // String genre = getGlobal().getGenre(mime, getURI().toString()); // System.out.println(genre + " " + mime); // Layer dsl = getDocument().getLayers(); // Layer baseLayer = dsl.getInstance(Layer.BASE); // MediaAdaptor helper = (MediaAdaptor) Behavior.getInstance( // "helper", genre, null, baseLayer); // helper.setInput(iu); // float zoom = 1; // try { // zoom = Float.parseFloat(Multivalent.getInstance() // .getPreference(genre + "-zoom", "1")); // } catch (NumberFormatException nfe) { // } // helper.setZoom(zoom); // dsl.getInstance(genre); // // getDocument().setMediaAdaptor(helper); // // Node root = null; // try { // // root = (Node) helper.parse(parent); // } catch (Exception e) { // new LeafUnicode("ERROR " + e, null, parent); // // e.printStackTrace(); // } finally { // try { // helper.close(); // } catch (IOException ioe) { // } // } // // getDocument().removeAttr(Document.ATTR_LOADING); // return root; } } catch (Exception e) { e.printStackTrace(); html = e.toString(); } return parseHelper(html, "HTML", getLayer(), parent); }
From source file:uk.ac.liv.shaman.vfsme.CommonVFSMediaAdaptor.java
public String toHTML(String pre) throws IOException { URI u = getURI();//from w w w .java 2 s .co m FileSystemManager m = VFS.getManager(); m.getSchemes(); String su = u.toString(); // if (pre.equals("iso:")) // su = su.replaceFirst("file:", ""); String uri = pre + su + "!"; System.out.println("VFS Open: " + uri); FileObject o = m.resolveFile(uri); StringBuilder sb = new StringBuilder(5000); sb.append("<html><head><style type=\"text/css\">\n" + "body {\n" + " color: black; background-color: white;\n" + " font-size: 14pts; /* Mozilla: 16 for proportional, 13 for fixed */\n" + " padding: 10px;}\n" + "\n" + "a:link { color: blue; }\n" + "a:visited { color: magenta; }\n" + "a:hover { color: red; }\n" + "a:active { color: red; }\n" + "\n" + "a:link, a:visited, \n" + "a:active, a:hover {\n" + " text-decoration: underline;\n" + "}\n" + "\n" + "p {\n" + " margin-top: 10px;\n" + "}\n" + "text { padding: 5px; }\n" + "\n" + "pre { font-family: monospace; }\n" + "\n\n" + "h1 { font-size: 24pt; font-weight: bold; margin: 10px 0px; }\n" + "h2 { font-size: 18pt; font-weight: bold; margin: 9px 0px; }\n" + "h3 { font-size: 14pt; font-weight: bold; margin: 7px 0px; }\n" + "h4 { font-size: 12pt; font-weight: bold; margin: 6px 0px; }\n" + "h5 { font-size: 10pt; font-weight: bold; margin: 5px 0px; }\n" + "h6 { font-size: 9pt; font-weight: bold; margin: 5px 0px; }\n" + "" + "" + "</style>"); sb.append("<title>").append("Contents of the archive").append(u.getPath()).append("</title>"); sb.append("\t<base href='").append(u).append("!/'>\n"); sb.append("</head>\n"); sb.append("<body>\n"); sb.append("<h2>").append("Contents of the archive").append(u.getPath()).append("</h2>"); sb.append("\n<pre><table width='90%'>\n"); // headers. click to sort sb.append("<tr><span Behavior='ScriptSpan' script='event tableSort <node>' title='Sort table'>"); sb.append( "<th align='left'>File / <b>Directory<th align='right'>Size<th align='right'>Last Modified</b></span>\n"); processChild(o, m, sb); sb.append("</table>\n</body></html>\n"); return sb.toString(); }