Examples of DropboxInputStream


Examples of com.dropbox.client2.DropboxAPI.DropboxInputStream

        was.setAccessTokenPair(accessToken);
        DropboxAPI<WebAuthSession> api = new DropboxAPI<WebAuthSession>(was);
       
        try {
            Entry meta = api.metadata(filePath, 1, null, false, null);
            DropboxInputStream streamData = api.getFileStream(filePath, null);
           
            try
            {
                int bufferSize = 1024;
                byte[] buffer = new byte[bufferSize];
                ByteArrayOutputStream baos = new ByteArrayOutputStream(bufferSize);           
                int bytesread = 0;
                while(true){
                    bytesread = streamData.read(buffer);
                    if (bytesread == -1) break;
                    baos.write(buffer,0,bytesread);
                }
               
                String name = "";
                int offset = filePath.lastIndexOf("/");
                if (offset!=-1) name = filePath.substring(offset+1);
               
                res.setContentType(meta.mimeType);    
                if (!"".equals((name)))
                    res.setHeader("Content-Disposition", "attachment; filename=" + name);
                res.setHeader("Cache-Control", "no-cache");   
                res.setContentLength(baos.size());
                ServletOutputStream sos = res.getOutputStream();
                baos.writeTo(sos);
                sos.flush();
                streamData.close();
                return null;
            }
            catch(Exception ex)
            {
                ex.printStackTrace();
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.