jcifs.smb.SmbFileInputStream Java Examples
The following examples show how to use
jcifs.smb.SmbFileInputStream.
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: NetworkExplorer.java From jcifs with GNU Lesser General Public License v2.1 | 6 votes |
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); } } }
Example #2
Source File: NetworkExplorer.java From jcifs-ng with GNU Lesser General Public License v2.1 | 6 votes |
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); } } }
Example #3
Source File: MultiProtocolURL.java From yacy_grid_mcp with GNU Lesser General Public License v2.1 | 5 votes |
public InputStream getInputStream(final ClientIdentification.Agent agent, final String username, final String pass, boolean active) 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, active); 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; }
Example #4
Source File: MultiProtocolURL.java From yacy_grid_mcp with GNU Lesser General Public License v2.1 | 5 votes |
public byte[] get(final ClientIdentification.Agent agent, final String username, final String pass, boolean active) 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, active); 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; }
Example #5
Source File: JCifsUtil.java From seed with Apache License 2.0 | 5 votes |
/** * 拷贝远程文件到本地目录 * @param smbFile 远程SmbFile * @param localDirectory 本地存储目录,本地目录不存在时会自动创建,本地目录存在时可自行选择是否清空该目录下的文件 * @return 拷贝结果,true--成功,false--失败 */ private static boolean copyRemoteFile(SmbFile smbFile, String localDirectory) { File[] localFiles = new File(localDirectory).listFiles(); if(null == localFiles){ //目录不存在的话,就创建目录 //new File("D:/aa/bb.et").mkdirs()会在aa文件夹下创建一个名为bb.et的文件夹 new File(localDirectory).mkdirs(); }else if(localFiles.length > 0){ for(File file : localFiles){ //清空本地目录下的所有文件 //new File("D:/aa/bb.et").delete()会删除bb.et文件,但aa文件夹还存在 file.delete(); } } try(SmbFileInputStream in=new SmbFileInputStream(smbFile); FileOutputStream out=new FileOutputStream(localDirectory+smbFile.getName())){ byte[] buffer = new byte[1024]; int len; while((len=in.read(buffer)) > -1){ out.write(buffer, 0, len); } out.flush(); } catch (Exception e) { LogUtil.getLogger().info("拷贝远程文件到本地目录时发生异常,堆栈轨迹如下", e); return false; } return true; }
Example #6
Source File: SmbFileTest.java From onetwo with Apache License 2.0 | 5 votes |
@Test public void testSimple() throws Exception{ String path = "smb://administrator:[email protected]\\install\\ftp\\新建文本文档.txt"; try { FileUtils.readAsString(path); Assert.fail("path is error, must error"); } catch (Exception e) { e.printStackTrace(); } TimeCounter t = new TimeCounter("217"); t.start(); path = "smb://administrator:[email protected]/install/ftp/新建文本文档.txt"; SmbFile smbf = new SmbFile(path); InputStream in = new SmbFileInputStream(smbf); List<String> list = FileUtils.readAsList(in); for(String str : list){ System.out.println(str); } t.stop(); /*t.restart("local"); String baseDir = "smb://administrator:[email protected]/share/"; path = "/新建文本文档.txt"; in = FileUtils.newInputStream(baseDir, path); list = FileUtils.readAsList(in, "GBK"); for(String str : list){ System.out.println(str); } t.stop();*/ }
Example #7
Source File: SmbFileUtils.java From onetwo with Apache License 2.0 | 5 votes |
public static SmbFileInputStream newSmbInputStream(SmbFile smbf){ try { SmbFileInputStream in = new SmbFileInputStream(smbf); return in; } catch (Exception e) { throw new BaseException("create SmbFileInputStream error: " + e.getMessage(), e); } }
Example #8
Source File: SmbFileObject.java From commons-vfs with Apache License 2.0 | 5 votes |
/** * Creates an input stream to read the file content from. */ @Override protected InputStream doGetInputStream(final int bufferSize) 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; } }
Example #9
Source File: IconHolder.java From PowerFileExplorer with GNU General Public License v3.0 | 4 votes |
private Bitmap loadImage(String path) throws OutOfMemoryError { Bitmap bitsat; try { BitmapFactory.Options options = new BitmapFactory.Options(); options.inPreferredConfig= Bitmap.Config.ARGB_8888; options.inJustDecodeBounds = true; Bitmap b = BitmapFactory.decodeFile(path, options); options.inSampleSize = Utils.calculateInSampleSize(options, px, px); // Decode bitmap with inSampleSize set options.inJustDecodeBounds = false; Bitmap bit; if(path.startsWith("smb:/")) { bit = BitmapFactory.decodeStream(new SmbFileInputStream(path)); } else if (path.startsWith(CloudHandler.CLOUD_PREFIX_DROPBOX)) { CloudStorage cloudStorageDropbox = dataUtils.getAccount(OpenMode.DROPBOX); bit = BitmapFactory.decodeStream(cloudStorageDropbox.getThumbnail(CloudUtil .stripPath(OpenMode.DROPBOX, path))); } else if (path.startsWith(CloudHandler.CLOUD_PREFIX_BOX)) { CloudStorage cloudStorageBox = dataUtils.getAccount(OpenMode.BOX); bit = BitmapFactory.decodeStream(cloudStorageBox.getThumbnail(CloudUtil .stripPath(OpenMode.BOX, path))); } else if (path.startsWith(CloudHandler.CLOUD_PREFIX_GOOGLE_DRIVE)) { CloudStorage cloudStorageGDrive = dataUtils.getAccount(OpenMode.GDRIVE); bit = BitmapFactory.decodeStream(cloudStorageGDrive.getThumbnail(CloudUtil .stripPath(OpenMode.GDRIVE, path))); } else if (path.startsWith(CloudHandler.CLOUD_PREFIX_ONE_DRIVE)) { CloudStorage cloudStorageOneDrive = dataUtils.getAccount(OpenMode.ONEDRIVE); bit = BitmapFactory.decodeStream(cloudStorageOneDrive.getThumbnail(CloudUtil .stripPath(OpenMode.ONEDRIVE, path))); } else if (path.startsWith(OTGUtil.PREFIX_OTG)) { bit = BitmapFactory.decodeStream(OTGUtil.getDocumentFilesList(path, mContext, null).get(0).getInputStream(mContext)); } else bit= BitmapFactory.decodeFile(path, options); bitsat = bit;// decodeFile(path);//.createScaledBitmap(bits,imageViewReference.get().getHeight(),imageViewReference.get().getWidth(),true); } catch (Exception e) { Drawable img = ContextCompat.getDrawable(mContext, R.drawable.ic_doc_image); Bitmap img1 = ((BitmapDrawable) img).getBitmap(); bitsat = img1; }return bitsat; }
Example #10
Source File: Lmhosts.java From jcifs with GNU Lesser General Public License v2.1 | 4 votes |
void populate ( Reader r, CIFSContext tc ) throws IOException { String line; BufferedReader br = new BufferedReader(r); while ( ( line = br.readLine() ) != null ) { line = line.toUpperCase().trim(); if ( line.length() == 0 ) { continue; } else if ( line.charAt(0) == '#' ) { if ( line.startsWith("#INCLUDE ") ) { line = line.substring(line.indexOf('\\')); String url = "smb:" + line.replace('\\', '/'); try ( InputStreamReader rdr = new InputStreamReader(new SmbFileInputStream(url, tc)) ) { if ( this.alt > 0 ) { try { populate(rdr, tc); } catch ( IOException ioe ) { log.error("Failed to read include " + url, ioe); continue; } /* * An include was loaded successfully. We can skip * all other includes up to the #END_ALTERNATE tag. */ while ( ( line = br.readLine() ) != null ) { line = line.toUpperCase().trim(); if ( line.startsWith("#END_ALTERNATE") ) { break; } } } else { populate(rdr, tc); } } } else if ( line.startsWith("#BEGIN_ALTERNATE") ) {} else if ( line.startsWith("#END_ALTERNATE") && this.alt > 0 ) { throw new IOException("no lmhosts alternate includes loaded"); } } else if ( Character.isDigit(line.charAt(0)) ) { char[] data = line.toCharArray(); int ip, i, j; Name name; NbtAddress addr; char c; c = '.'; ip = i = 0; for ( ; i < data.length && c == '.'; i++ ) { int b = 0x00; for ( ; i < data.length && ( c = data[ i ] ) >= 48 && c <= 57; i++ ) { b = b * 10 + c - '0'; } ip = ( ip << 8 ) + b; } while ( i < data.length && Character.isWhitespace(data[ i ]) ) { i++; } j = i; while ( j < data.length && Character.isWhitespace(data[ j ]) == false ) { j++; } name = new Name(tc.getConfig(), line.substring(i, j), 0x20, null); addr = new NbtAddress(name, ip, false, NbtAddress.B_NODE, false, false, true, true, NbtAddress.UNKNOWN_MAC_ADDRESS); if ( log.isDebugEnabled() ) { log.debug("Adding " + name + " with addr " + addr); } this.table.put(name, addr); } } }
Example #11
Source File: Lmhosts.java From jcifs-ng with GNU Lesser General Public License v2.1 | 4 votes |
void populate ( Reader r, CIFSContext tc ) throws IOException { String line; BufferedReader br = new BufferedReader(r); while ( ( line = br.readLine() ) != null ) { line = line.toUpperCase().trim(); if ( line.length() == 0 ) { continue; } else if ( line.charAt(0) == '#' ) { if ( line.startsWith("#INCLUDE ") ) { line = line.substring(line.indexOf('\\')); String url = "smb:" + line.replace('\\', '/'); try ( InputStreamReader rdr = new InputStreamReader(new SmbFileInputStream(url, tc)) ) { if ( this.alt > 0 ) { try { populate(rdr, tc); } catch ( IOException ioe ) { log.error("Failed to read include " + url, ioe); continue; } /* * An include was loaded successfully. We can skip * all other includes up to the #END_ALTERNATE tag. */ while ( ( line = br.readLine() ) != null ) { line = line.toUpperCase().trim(); if ( line.startsWith("#END_ALTERNATE") ) { break; } } } else { populate(rdr, tc); } } } else if ( line.startsWith("#BEGIN_ALTERNATE") ) {} else if ( line.startsWith("#END_ALTERNATE") && this.alt > 0 ) { throw new IOException("no lmhosts alternate includes loaded"); } } else if ( Character.isDigit(line.charAt(0)) ) { char[] data = line.toCharArray(); int ip, i, j; Name name; NbtAddress addr; char c; c = '.'; ip = i = 0; for ( ; i < data.length && c == '.'; i++ ) { int b = 0x00; for ( ; i < data.length && ( c = data[ i ] ) >= 48 && c <= 57; i++ ) { b = b * 10 + c - '0'; } ip = ( ip << 8 ) + b; } while ( i < data.length && Character.isWhitespace(data[ i ]) ) { i++; } j = i; while ( j < data.length && Character.isWhitespace(data[ j ]) == false ) { j++; } name = new Name(tc.getConfig(), line.substring(i, j), 0x20, null); addr = new NbtAddress(name, ip, false, NbtAddress.B_NODE, false, false, true, true, NbtAddress.UNKNOWN_MAC_ADDRESS); if ( log.isDebugEnabled() ) { log.debug("Adding " + name + " with addr " + addr); } this.table.put(name, addr); } } }
Example #12
Source File: SmbFileUtils.java From onetwo with Apache License 2.0 | 4 votes |
public static SmbFileInputStream newSmbInputStream(String fpath){ return newSmbInputStream(newSmbFile(fpath)); }
Example #13
Source File: Samba1FileSystem.java From iaf with Apache License 2.0 | 4 votes |
@Override public InputStream readFile(SmbFile f) throws IOException { SmbFileInputStream is = new SmbFileInputStream(f); return is; }