public InputStream getInputStream(final ClientIdentification.Agent agent, final String username, final String pass) throws IOException { if (isFile()) return new BufferedInputStream(new FileInputStream(getFSFile())); if (isSMB()) return new BufferedInputStream(new SmbFileInputStream(getSmbFile())); if (isFTP()) { FTPStorageFactory client = new FTPStorageFactory(this.host, this.port < 0 ? 21 : this.port, username, pass, false); Asset<byte[]> asset = client.getStorage().load(this.path); return new ByteArrayInputStream(asset.getPayload()); } if (isHTTP() || isHTTPS()) { // TODO: add agent, user and pass return new ByteArrayInputStream(ClientConnection.load(this.toString())); } return null; }
/** * This URLConnection method just returns a new <tt>SmbFileInputStream</tt> created with this file. * * @throws IOException * thrown by <tt>SmbFileInputStream</tt> constructor */ @Override public InputStream getInputStream () throws IOException { return new SmbFileInputStream(this); }
/** * This URLConnection method just returns a new <tt>SmbFileInputStream</tt> created with this file. * * @throws IOException thrown by <tt>SmbFileInputStream</tt> constructor */ public InputStream getInputStream() throws IOException { return new SmbFileInputStream( this ); }
/** * This URLConnection method just returns a new <tt>SmbFileInputStream</tt> created with this file. * * @throws IOException thrown by <tt>SmbFileInputStream</tt> constructor */ public InputStream getInputStream() throws IOException { return new SmbFileInputStream( this ); }
@Override public SmbFileInputStream openInputStream ( int flags, int access, int sharing ) throws SmbException { return new SmbFileInputStream(this, flags, access, sharing, false); }
/** * This URLConnection method just returns a new <tt>SmbFileInputStream</tt> created with this file. * * @throws IOException thrown by <tt>SmbFileInputStream</tt> constructor */ public InputStream getInputStream() throws IOException { return new SmbFileInputStream( this ); }
@Override public SmbFileInputStream openInputStream () throws SmbException { return new SmbFileInputStream(this); }
/** * This URLConnection method just returns a new <tt>SmbFileInputStream</tt> created with this file. * * @throws IOException * thrown by <tt>SmbFileInputStream</tt> constructor */ @Override public InputStream getInputStream () throws IOException { return new SmbFileInputStream(this); }
public static HSSFWorkbook loadWorkbook(String fileName){ SmbFileInputStream fin = null; try{ fin = new SmbFileInputStream(...); } catch(...) { } //do stuff with fin }
/** * This URLConnection method just returns a new <tt>SmbFileInputStream</tt> created with this file. * * @throws IOException thrown by <tt>SmbFileInputStream</tt> constructor */ public InputStream getInputStream() throws IOException { return new SmbFileInputStream( this ); }
@Override public SmbFileInputStream openInputStream () throws SmbException { return new SmbFileInputStream(this); }
@Override public InputStream getInputStream() throws IOException { return new SmbFileInputStream(file); }
@Override public SmbFileInputStream openInputStream ( int flags, int access, int sharing ) throws SmbException { return new SmbFileInputStream(this, flags, access, sharing, false); }
public byte[] get(final ClientIdentification.Agent agent, final String username, final String pass) throws IOException { if (isFile()) return read(new FileInputStream(getFSFile())); if (isSMB()) return read(new SmbFileInputStream(getSmbFile())); if (isFTP()) { FTPStorageFactory client = new FTPStorageFactory(this.host, this.port < 0 ? 21 : this.port, username, pass, false); Asset<byte[]> asset = client.getStorage().load(this.path); return asset.getPayload(); } if (isHTTP() || isHTTPS()) { // TODO: add agent, user and pass return ClientConnection.load(this.toString()); } return null; }
SmbFileInputStream in = new SmbFileInputStream("smb://host/dir/file.ext"); InputStreamReader r=new InputStreamReader(in); char buf[] = new char[5000]; int count=r.read(buf); String s=String.valueOf(buf, 0, count);
private void copy(final SmbFile src, final File dest) { if (dest.exists() && !dest.canWrite()) { return; } try (BufferedInputStream in = new BufferedInputStream(new SmbFileInputStream(src)); BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(dest))) { final byte[] buf = new byte[1024]; int length; while (-1 < (length = in.read(buf))) { out.write(buf, 0, length); out.flush(); } } catch (final IOException e) { throw new IORuntimeException(e); } }
@Override @WorkerThread public File loadToCache(final Uri uri, final String extension, final IProgressIndicator progress) throws IOException { final UIFileCopying ui = new UIFileCopying(R.string.opds_loading_book, 64 * 1024, progress); return CacheManager.createTempDocument(new SmbFileInputStream(uri.toString()), uri.getLastPathSegment(), ui); } },
public static HSSFWorkbook loadWorkbook(String fileName)throws CustomException{ try{ SmbFileInputStream fin = new SmbFileInputStream(...); //do stuff with fin return wb; } catch(FileNotFoundException f) { //handle file not found throw new CustomException("File Not found ...", f); } catch(IOException io) { //handle io exception throw new CustomException("loadWorkBook failed", io); } }
protected void doFile ( HttpServletRequest req, HttpServletResponse resp, SmbFile file ) throws IOException { byte[] buf = new byte[8192]; @SuppressWarnings ( "resource" ) ServletOutputStream out = resp.getOutputStream(); String url; int n; try ( SmbFileInputStream in = new SmbFileInputStream(file) ) { url = file.getLocator().getPath(); resp.setContentType("text/plain"); resp.setContentType(URLConnection.guessContentTypeFromName(url)); resp.setHeader("Content-Length", file.length() + ""); resp.setHeader("Accept-Ranges", "Bytes"); while ( ( n = in.read(buf) ) != -1 ) { out.write(buf, 0, n); } } }
/** * Creates an input stream to read the file content from. */ @Override protected InputStream doGetInputStream() throws Exception { try { return new SmbFileInputStream(file); } catch (final SmbException e) { if (e.getNtStatus() == SmbException.NT_STATUS_NO_SUCH_FILE) { throw new org.apache.commons.vfs2.FileNotFoundException(getName()); } else if (file.isDirectory()) { throw new FileTypeHasNoContentException(getName()); } throw e; } }