List of usage examples for java.io FileInputStream toString
public String toString()
From source file:de.escoand.readdaily.DownloadHandler.java
@Override public void onReceive(final Context context, final Intent intent) { final DownloadManager manager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE); final Database db = Database.getInstance(context); final Cursor downloads = db.getDownloads(); LogHandler.log(Log.WARN, "receive starting"); while (downloads.moveToNext()) { final long id = downloads.getLong(downloads.getColumnIndex(Database.COLUMN_ID)); final String name = downloads.getString(downloads.getColumnIndex(Database.COLUMN_SUBSCRIPTION)); final String mime = downloads.getString(downloads.getColumnIndex(Database.COLUMN_TYPE)); final Cursor download = manager.query(new DownloadManager.Query().setFilterById(id)); // download exists if (!download.moveToFirst()) continue; // download finished if (download.getInt( download.getColumnIndex(DownloadManager.COLUMN_STATUS)) != DownloadManager.STATUS_SUCCESSFUL) continue; // import file in background new Thread(new Runnable() { @Override//w w w . j ava 2 s. c o m public void run() { try { LogHandler.log(Log.WARN, "import starting of " + name); final FileInputStream stream = new ParcelFileDescriptor.AutoCloseInputStream( manager.openDownloadedFile(id)); final String mimeServer = manager.getMimeTypeForDownloadedFile(id); LogHandler.log(Log.INFO, "id: " + String.valueOf(id)); LogHandler.log(Log.INFO, "manager: " + manager.toString()); LogHandler.log(Log.INFO, "stream: " + stream.toString()); LogHandler.log(Log.INFO, "mime: " + mime); LogHandler.log(Log.INFO, "mimeServer: " + mimeServer); switch (mime != null ? mime : (mimeServer != null ? mimeServer : "")) { // register feedback case "application/json": final byte[] buf = new byte[256]; final int len = stream.read(buf); LogHandler.log(Log.WARN, "register feedback: " + new String(buf, 0, len)); break; // csv data case "text/plain": db.importCSV(name, stream); break; // xml data case "application/xml": case "text/xml": db.importXML(name, stream); break; // zipped data case "application/zip": db.importZIP(name, stream); break; // do nothing default: LogHandler.log(new IntentFilter.MalformedMimeTypeException()); break; } stream.close(); LogHandler.log(Log.WARN, "import finished (" + name + ")"); } // file error catch (FileNotFoundException e) { LogHandler.logAndShow(e, context, R.string.message_download_open); } // stream error catch (IOException e) { LogHandler.logAndShow(e, context, R.string.message_download_read); } // xml error catch (XmlPullParserException e) { LogHandler.logAndShow(e, context, R.string.message_download_xml); } // clean finally { manager.remove(id); db.removeDownload(id); LogHandler.log(Log.WARN, "clean finished"); } } }).start(); } downloads.close(); LogHandler.log(Log.WARN, "receiving done"); }
From source file:ftp_server.FileUpload.java
public void uploading() { FTPClient client = new FTPClient(); FileInputStream fis = null; try {// w ww. j ava 2 s. c o m client.connect("shamalmahesh.net78.net"); client.login("a9959679", "9P3IckDo"); client.setFileType(FTP.BINARY_FILE_TYPE); int reply = client.getReplyCode(); if (FTPReply.isPositiveCompletion(reply)) { System.out.println("Uploading...."); } else { System.out.println("Failed connect to the server!"); } // String filename = "DownloadedLook1.txt"; String path = "D:\\jpg\\"; // String filename = "1.jpg"; String filename = "appearance.jpg"; System.out.println(path + filename); fis = new FileInputStream(path + filename); System.out.println(fis.toString()); boolean status = client.storeFile("/public_html/testing/" + filename, fis); System.out.println("Status : " + status); System.out.println("Done!"); client.logout(); } catch (IOException e) { e.printStackTrace(); } finally { try { if (fis != null) { fis.close(); } client.disconnect(); } catch (IOException e) { e.printStackTrace(); } } }