List of usage examples for java.io BufferedInputStream read
public synchronized int read() throws IOException
read
method of InputStream
. From source file:net.jotel.ws.client.WebSocketReaderThread.java
private int read(BufferedInputStream is) throws IOException, WebSocketException { int b = is.read(); if (b == -1) { throw new WebSocketException("Unexpected EOF"); }//from w w w .j a v a 2 s .co m return b; }
From source file:org.deshang.content.indexing.util.jdbc.AbstractRowMapper.java
protected String getBlobContent(Blob blob) throws SQLException { LOGGER.debug("Enter getBlobContent(Blob)"); String blobContent = null;// ww w. j av a 2 s . c o m try { InputStream in = blob.getBinaryStream(); BufferedInputStream bis = new BufferedInputStream(in); ByteArrayOutputStream baos = new ByteArrayOutputStream(); int data = -1; while ((data = bis.read()) != -1) { baos.write(data); } blobContent = baos.toString("UTF-8"); } catch (IOException e) { throw new SQLException("Can't read blob conent", e); } LOGGER.debug("Exit getBlobContent(Blob)"); return blobContent; }
From source file:org.broadleafcommerce.admin.util.controllers.FileUploadController.java
protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) throws ServletException, IOException { // cast the bean FileUploadBean bean = (FileUploadBean) command; // let's see if there's content there MultipartFile file = bean.getFile(); if (file == null) { // hmm, that's strange, the user did not upload anything }/*from w w w.j av a2s . c om*/ try { String basepath = request.getPathTranslated().substring(0, request.getPathTranslated().indexOf(File.separator + "upload")); String absoluteFilename = basepath + File.separator + bean.getDirectory() + File.separator + file.getOriginalFilename(); FileSystemResource fileResource = new FileSystemResource(absoluteFilename); checkDirectory(basepath + File.separator + bean.getDirectory()); backupExistingFile(fileResource, basepath + bean.getDirectory()); FileOutputStream fout = new FileOutputStream(new FileSystemResource( basepath + File.separator + bean.getDirectory() + File.separator + file.getOriginalFilename()) .getFile()); BufferedOutputStream bout = new BufferedOutputStream(fout); BufferedInputStream bin = new BufferedInputStream(file.getInputStream()); int x; while ((x = bin.read()) != -1) { bout.write(x); } bout.flush(); bout.close(); bin.close(); return super.onSubmit(request, response, command, errors); } catch (Exception e) { //Exception occured; e.printStackTrace(); throw new RuntimeException(e); // return null; } }
From source file:com.sangupta.jerry.util.FileUtils.java
/** * Dump a given file into HEX starting at given offset and reading given number of rows where * a row consists of 16-bytes.//from w w w.ja va 2 s.c o m * * @param out * @param file * @param offset * @param maxRows * @throws IOException */ public static void hexDump(PrintStream out, File file, long offset, int maxRows) throws IOException { InputStream is = null; BufferedInputStream bis = null; try { is = new FileInputStream(file); bis = new BufferedInputStream(is); bis.skip(offset); int row = 0; if (maxRows == 0) { maxRows = Integer.MAX_VALUE; } StringBuilder builder1 = new StringBuilder(100); StringBuilder builder2 = new StringBuilder(100); while (bis.available() > 0) { out.printf("%04X ", row * 16); for (int j = 0; j < 16; j++) { if (bis.available() > 0) { int value = (int) bis.read(); builder1.append(String.format("%02X ", value)); if (!Character.isISOControl(value)) { builder2.append((char) value); } else { builder2.append("."); } } else { for (; j < 16; j++) { builder1.append(" "); } } } out.print(builder1); out.println(builder2); row++; if (row > maxRows) { break; } builder1.setLength(0); builder2.setLength(0); } } finally { IOUtils.closeQuietly(bis); IOUtils.closeQuietly(is); } }
From source file:com.joefernandez.irrduino.android.remote.HttpCommandTask.java
/** The system calls this to perform work in a worker thread and * delivers it the parameters given to AsyncTask.execute() */ protected String doInBackground(String... urls) { try {/* w ww . j av a 2 s . c om*/ URL commandURL = new URL(urls[0]); URLConnection conn = commandURL.openConnection(); InputStream is = conn.getInputStream(); BufferedInputStream bis = new BufferedInputStream(is); ByteArrayBuffer baf = new ByteArrayBuffer(50); int current = 0; while ((current = bis.read()) != -1) { baf.append((byte) current); } /* Convert the Bytes read to a String. */ return new String(baf.toByteArray()); } catch (Exception e) { Log.d(TAG, "http request exception for: " + urls[0]); Log.d(TAG, " Exception: " + e.getMessage()); } return null; }
From source file:org.nhnnext.android.androidnaming.ImageDownload.java
public void copy_img(String url, String save_name) { File img_cache_path;//w w w.ja v a 2 s . com img_cache_path = new File(HomeView.FILES_DIR + save_name); if (!img_cache_path.exists()) { // ************************************ try { URL Url = new URL(url); URLConnection conn = Url.openConnection(); conn.connect(); InputStream is = conn.getInputStream(); BufferedInputStream bis = new BufferedInputStream(is); ByteArrayBuffer baf = new ByteArrayBuffer(50); int current = 0; while ((current = bis.read()) != -1) { baf.append((byte) current); } FileOutputStream fos = context.openFileOutput(save_name, 0); fos.write(baf.toByteArray()); fos.close(); } catch (IOException e) { } } }
From source file:org.nhnnext.android.day3.Img_Downloader.java
public void copy_img(String url, String save_name) { File img_cache_path;//from w w w. j a va 2 s . c o m img_cache_path = new File(MainActivity.FILES_DIR + save_name); if (!img_cache_path.exists()) { // ************************************ try { URL Url = new URL(url); URLConnection conn = Url.openConnection(); conn.connect(); InputStream is = conn.getInputStream(); BufferedInputStream bis = new BufferedInputStream(is); ByteArrayBuffer baf = new ByteArrayBuffer(50); int current = 0; while ((current = bis.read()) != -1) { baf.append((byte) current); } FileOutputStream fos = context.openFileOutput(save_name, 0); fos.write(baf.toByteArray()); fos.close(); } catch (IOException e) { } } }
From source file:org.nhnnext.android.day5_simple.ImageDownloader.java
public void copy_img(String url, String save_name) { File img_cache_path;/*from w ww. j av a2 s. c o m*/ img_cache_path = new File(NextgramController.FILES_DIR + save_name); if (!img_cache_path.exists()) { // ************************************ try { URL Url = new URL(url); URLConnection conn = Url.openConnection(); conn.connect(); InputStream is = conn.getInputStream(); BufferedInputStream bis = new BufferedInputStream(is); ByteArrayBuffer baf = new ByteArrayBuffer(50); int current = 0; while ((current = bis.read()) != -1) { baf.append((byte) current); } FileOutputStream fos = context.openFileOutput(save_name, 0); fos.write(baf.toByteArray()); fos.close(); } catch (IOException e) { } } }
From source file:org.nhnnext.android.basic.ImageDownload.java
public void copy_img(String url, String save_name) { File img_cache_path;/*from w w w .j a va 2s . c o m*/ img_cache_path = new File(pref.getString(context.getString(R.string.files_directory), "") + save_name); if (!img_cache_path.exists()) { // ************************************ try { URL Url = new URL(url); URLConnection conn = Url.openConnection(); conn.connect(); InputStream is = conn.getInputStream(); BufferedInputStream bis = new BufferedInputStream(is); ByteArrayBuffer baf = new ByteArrayBuffer(50); int current = 0; while ((current = bis.read()) != -1) { baf.append((byte) current); } FileOutputStream fos = context.openFileOutput(save_name, 0); fos.write(baf.toByteArray()); fos.close(); } catch (IOException e) { } } }
From source file:it.eng.spagobi.kpi.service.KpiExporterAction.java
/** * This action is called by the user who wants to export the result of a Kpi in PDF * // w ww .j a v a2 s . com */ public void service(SourceBean serviceRequest, SourceBean serviceResponse) throws Exception { File tmpFile = null; logger.debug("IN"); HttpServletRequest httpRequest = getHttpRequest(); HttpSession session = httpRequest.getSession(); this.freezeHttpResponse(); try { // get KPI result List<KpiResourceBlock> listKpiBlocks = (List<KpiResourceBlock>) session.getAttribute("KPI_BLOCK"); //List<KpiResourceBlock> listKpiBlocks=executeKpi(objectId); // recover BiObject Name Object idObject = serviceRequest.getAttribute(SpagoBIConstants.OBJECT_ID); if (idObject == null) { logger.error("Document id not found"); return; } Integer id = Integer.valueOf(idObject.toString()); BIObject document = DAOFactory.getBIObjectDAO().loadBIObjectById(id); String docName = document.getName(); //Recover user Id HashedMap parameters = new HashedMap(); String userId = null; Object userIdO = serviceRequest.getAttribute("user_id"); if (userIdO != null) userId = userIdO.toString(); it.eng.spagobi.engines.exporters.KpiExporter exporter = new KpiExporter(); tmpFile = exporter.getKpiReportPDF(listKpiBlocks, document, userId); String outputType = "PDF"; String mimeType = "application/pdf"; logger.debug("Report exported succesfully"); HttpServletResponse response = getHttpResponse(); response.setContentType(mimeType); response.setHeader("Content-Disposition", "filename=\"report." + outputType + "\";"); response.setContentLength((int) tmpFile.length()); BufferedInputStream in = new BufferedInputStream(new FileInputStream(tmpFile)); int b = -1; while ((b = in.read()) != -1) { response.getOutputStream().write(b); } response.getOutputStream().flush(); in.close(); logger.debug("OUT"); } catch (Throwable e) { logger.error("An exception has occured", e); throw new Exception(e); } finally { tmpFile.delete(); } }