List of usage examples for java.io FileInputStream available
public int available() throws IOException
From source file:com.BeeFramework.activity.CrashLogActivity.java
public void initLog() { try {/*from w w w . j a v a2s. co m*/ String path = Environment.getExternalStorageDirectory().getAbsolutePath() + AppConst.LOG_DIR_PATH; getFiles(logFilesList, path); for (int i = 0; i < logFilesList.size(); i++) { File file = logFilesList.get(i); try { FileInputStream fin = new FileInputStream(file); int length = fin.available(); byte[] buffer = new byte[length]; fin.read(buffer); String content = EncodingUtils.getString(buffer, "UTF-8"); fin.close(); String fileName = file.getName(); String[] nameArray = fileName.split("\\."); if (nameArray.length > 0) { String intStr = nameArray[0]; long timestamp = Long.parseLong(intStr); Date currentTime = new Date(timestamp); CrashMessage crashMessage = new CrashMessage(); SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd HH:mm:ss"); String dateString = formatter.format(currentTime); crashMessage.crashTime = dateString; crashMessage.crashContent = content; crashMessageArrayList.add(crashMessage); } } catch (FileNotFoundException e) { } catch (IOException e2) { e2.printStackTrace(); } } } catch (Exception e) { e.printStackTrace(); } finally { handler.sendEmptyMessage(0); } }
From source file:report.SOSearchExtract.java
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Connection con = null;//from ww w . j ava 2s . com HttpSession session = request.getSession(false); String url = "jdbc:postgresql://10.16.194.69:5432/ls"; String user = "test"; String password = "aerohive123!"; try { if (session != null && session.getAttribute("reseller") != null && session.getAttribute("sonumber") != null) { PreparedStatement pst = null; Class.forName("org.postgresql.Driver"); con = DriverManager.getConnection(url, user, password); //String reseller = "%"+request.getParameter("reseller")+"%"; StringBuffer sql = new StringBuffer(); sql.append( "select o.orderkey,ib.salesordernumber,ib.item,so_header.reseller,so_header.end_user as enduser,ib.serialnumber,ib.hmid, "); sql.append("so_header.po_check_number as ponumber "); sql.append( " from ns.temp_so_header so_header inner join ns.temp_ib ib on substring(ib.salesordernumber from 14 for 100) =so_header.so_number"); sql.append(" inner join orderkey_information o on so_header.entitlement_key=o.orderkey "); sql.append("where (ib.producttype='AP' or ib.producttype='License - AP') and so_header.so_number='" + session.getAttribute("sonumber") + "' "); sql.append(" and reseller ILIKE '%" + session.getAttribute("reseller") + "%'"); log.info("Sales Order Search Extract Query :" + sql); pst = con.prepareStatement(sql.toString()); //if(session!=null && session.getAttribute("reseller")!=null) //pst.setString(1,(String) session.getAttribute("reseller")); ResultSet rs = pst.executeQuery(); FileWriter sw = new FileWriter("SOSearchResults.csv"); CSVWriter writer = new CSVWriter(sw, '|'); writer.writeAll(rs, true); sw.close(); FileInputStream fis = new FileInputStream("SOSearchResults.csv"); byte b[]; int x = fis.available(); b = new byte[x]; System.out.println(" b size" + b.length); fis.read(b); // FIXME: this is ugly if (response != null) { response.setContentType("application/ms-excel"); response.setHeader("Content-Disposition", "attachment; filename=SOSearchResults.csv"); } //response.setContentType(mimeType); OutputStream os = response.getOutputStream(); os.write(b); os.flush(); writer.flush(); writer.close(); fis.close(); } else { log.info("Sales Order Search Extract :Reseller Blank"); String nextJSP = "/login.jsp"; RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(nextJSP); dispatcher.forward(request, response); } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:gcm.play.android.samples.com.gcm.MyGcmListenerService.java
public String readFile(String filename) throws FileNotFoundException, IOException { FileInputStream in = openFileInput(filename); InputStreamReader inputStreamReader = new InputStreamReader(in); byte[] data = new byte[in.available()]; in.read(data, 0, in.available());/*from w w w .j av a 2 s .c om*/ in.close(); return new String(data, "UTF-8"); }
From source file:com.mobilis.android.nfc.activities.MagTekFragment.java
public static String ReadSettings(Context context, String file) throws IOException { FileInputStream fis = null; InputStreamReader isr = null; String data = null;/*from ww w . j a va 2s . c o m*/ fis = context.openFileInput(file); isr = new InputStreamReader(fis); char[] inputBuffer = new char[fis.available()]; isr.read(inputBuffer); data = new String(inputBuffer); isr.close(); fis.close(); return data; }
From source file:com.gotraveling.insthub.BeeFramework.activity.CrashLogActivity.java
public void initLog() { try {/*w ww . j a v a2 s .com*/ String path = Environment.getExternalStorageDirectory().getAbsolutePath() + BeeFrameworkConst.LOG_DIR_PATH; getFiles(logFilesList, path); for (int i = 0; i < logFilesList.size(); i++) { File file = logFilesList.get(i); try { FileInputStream fin = new FileInputStream(file); int length = fin.available(); byte[] buffer = new byte[length]; fin.read(buffer); String content = EncodingUtils.getString(buffer, "UTF-8"); fin.close(); String fileName = file.getName(); String[] nameArray = fileName.split("\\."); if (nameArray.length > 0) { String intStr = nameArray[0]; long timestamp = Long.parseLong(intStr); Date currentTime = new Date(timestamp); CrashMessage crashMessage = new CrashMessage(); SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd HH:mm:ss"); String dateString = formatter.format(currentTime); crashMessage.crashTime = dateString; crashMessage.crashContent = content; crashMessageArrayList.add(crashMessage); } } catch (FileNotFoundException e) { } catch (IOException e2) { e2.printStackTrace(); } } } catch (Exception e) { e.printStackTrace(); } finally { handler.sendEmptyMessage(0); } }
From source file:org.panlab.tgw.ConfParser.java
public void run() { while (true) { String current_ptm = ""; try {//w w w. j a va 2s.c o m //PtmInfoParser.refreshPTMs(); FileInputStream fis = new FileInputStream("conf.xml"); int length = fis.available(); byte bArray[] = new byte[length]; fis.read(bArray); fis.close(); String content = new String(bArray); Object objs[] = XMLUtil.getElements(content); if (objs != null) { for (int i = 0; i < objs.length; i++) { XMLElement element = (XMLElement) (objs[i]); String attributeValue = element.m_attributes.get("cert"); //log.info(element.m_name + " "+ attributeValue.replace("\"","") +" "+element.m_value); App.ptm_indexes.put(element.m_name, new URL(element.m_value)); App.ptm_certs.put(element.m_name, attributeValue.replace("\"", "")); App.ptm_certs_ind.put(attributeValue.replace("\"", ""), element.m_name); //log.info(element.m_name+"@"+attributeValue.replace("\"","")); current_ptm = element.m_name; T1ServiceLocator l = new T1ServiceLocator(); T1SoapBindingStub stub; stub = (T1SoapBindingStub) (l .getT1((URL) (org.panlab.tgw.App.ptm_indexes.get(element.m_name)))); ProvisioningResponse ref; try { ref = stub.query("status_check", element.m_name + ".top-0", "<status></status>", null); //log.info(ref.getConfig_data()); if (ref.getConfig_data().contains("top-0")) App.ptm_status.put(current_ptm, App.OK); } catch (org.apache.axis.AxisFault ex) { if (App.DEBUG) log.error("======================" + current_ptm + "======================"); if (ex.getFaultReason() .equalsIgnoreCase("java.net.ConnectException: Connection refused")) App.ptm_status.put(current_ptm, App.PTM_OFFLINE); else if (ex.getFaultReason() .equalsIgnoreCase("java.net.NoRouteToHostException: No route to host")) App.ptm_status.put(current_ptm, App.PTM_OFFLINE); else if (ex.getFaultReason().contains("java.net.ConnectException: Connection refused")) App.ptm_status.put(current_ptm, App.RAL_OFFLINE); else if (ex.getFaultReason().contains("ralmanager")) App.ptm_status.put(current_ptm, App.RAL_MANAGER_OFFLINE); else if (ex.getFaultReason().contains("SSLHandshakeException")) App.ptm_status.put(current_ptm, App.SSL_PROBLEM); else { App.ptm_status.put(current_ptm, App.PTM_OFFLINE); //log.info("Reason: "+ex.getFaultReason()); //log.info("String: "+ex.getFaultString()); } if (App.DEBUG) log.error(ex); if (App.DEBUG) log.error("======================" + current_ptm + "======================"); } //log.info(current_ptm+" "+ getReason(App.ptm_status.get(current_ptm))); } } sleep(10000); } catch (ServiceException ex) { ex.printStackTrace(); } catch (InterruptedException ex) { ex.printStackTrace(); } catch (IOException ex) { log.info("Configuration file error" + ex.getClass().getName()); ex.printStackTrace(); } } }
From source file:ddf.content.provider.filesystem.FileSystemProviderTest.java
private String getFileContentsAsString(String filename) throws Exception { FileInputStream file = new FileInputStream(filename); byte[] b = new byte[file.available()]; file.read(b);//from w ww . jav a 2s.c o m file.close(); return new String(b); }
From source file:org.kaaproject.kaa.demo.iotworld.smarthome.fragment.device.PhotoDeviceFragment.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == REQUEST_SELECT_IMAGE && resultCode == Activity.RESULT_OK && null != data) { Uri selectedImage = data.getData(); String[] columns = { MediaStore.Images.Media.DATA }; Cursor cursor = mActivity.getContentResolver().query(selectedImage, columns, null, null, null); cursor.moveToFirst();/* w w w . j a va 2 s .c o m*/ int columnIndex = cursor.getColumnIndex(columns[0]); String imagePath = cursor.getString(columnIndex); cursor.close(); String imageFileName = null; byte[] imageData = null; try { File f = new File(imagePath); imageFileName = f.getName(); FileInputStream fis = new FileInputStream(imagePath); imageData = new byte[fis.available()]; fis.read(imageData); fis.close(); } catch (IOException e) { Log.e(getFragmentTag(), "Unable to read image from path: " + imagePath); } if (imageData != null) { mDevice.uploadPhoto(imageFileName, imageData); } } }
From source file:org.openmrs.contrib.metadatarepository.service.impl.PackageManagerImpl.java
/** * @param id/*from w w w . ja v a 2 s. c om*/ * The id of the package. * @throws APIException * If any error occurs while downloading package or if package * doesn't exist * @return returns MetadataPackage object of that particular id */ public MetadataPackage loadPackage(Long id) throws IOException { byte[] data = null; File f = new File(packagesStorageDir + "/" + id + ".zip"); if (f.exists()) { try { FileInputStream fis = new FileInputStream(f); data = new byte[fis.available()]; fis.read(data); fis.close(); } catch (FileNotFoundException e) { throw new APIException("Error downloading the package", e); } } else { Exception fe = null; throw new APIException("Package doesn't exist", fe); } MetadataPackage pkg = dao.get(id); pkg.setFile(data); return pkg; }
From source file:ru.org.linux.util.image.ImageInfo.java
public ImageInfo(File file, String extension) throws BadImageException, IOException { filename = file.getName();/*from w ww.j a v a 2 s . co m*/ FileInputStream fileStream = null; try { fileStream = new FileInputStream(file); size = fileStream.available(); if ("gif".equals(extension)) { getGifInfo(fileStream); } else if ("jpg".equals(extension) || "jpeg".equals(extension)) { getJpgInfo(fileStream); } else if ("png".equals(extension)) { getPngInfo(fileStream); } else { throw new BadImageException("Invalid image extension"); } if (height == -1 || width == -1) { throw new BadImageException(); } } finally { if (fileStream != null) { fileStream.close(); } } }