List of usage examples for javax.imageio.stream FileImageInputStream read
public int read(byte[] b) throws IOException
From source file:com.bc.util.io.FileUtils.java
public static void copy(File source, File target) throws IOException { final byte[] buffer = new byte[ONE_KB * ONE_KB]; int bytesRead; FileImageInputStream sourceStream = null; FileImageOutputStream targetStream = null; try {/*ww w .ja v a 2s . c o m*/ final File targetDir = target.getParentFile(); if (!targetDir.isDirectory()) { if (!targetDir.mkdirs()) { throw new IOException("failed to create target directory: " + targetDir.getAbsolutePath()); } } target.createNewFile(); sourceStream = new FileImageInputStream(source); targetStream = new FileImageOutputStream(target); while ((bytesRead = sourceStream.read(buffer)) >= 0) { targetStream.write(buffer, 0, bytesRead); } } finally { if (sourceStream != null) { sourceStream.close(); } if (targetStream != null) { targetStream.flush(); targetStream.close(); } } }
From source file:com.aurel.track.admin.customize.category.report.execute.ReportExecuteAction.java
/** * Writes the preview image into the servlet response * @return//w ww . j a va 2s .c o m */ public String showPreviewImage() { File imgFile = null; if (!leaf) { String folderDirectory = ""; if ("projects-ticon".equals(iconCls)) { folderDirectory = ApplicationBean.getInstance().getServletContext().getRealPath( "/" + Constants.DESIGN_DIRECTORY + "/" + Constants.DEFAULTDESIGNPATH + "/img/project.png"); } else { folderDirectory = ApplicationBean.getInstance().getServletContext().getRealPath( "/" + Constants.DESIGN_DIRECTORY + "/" + Constants.DEFAULTDESIGNPATH + "/img/folder.png"); } imgFile = new File(folderDirectory); } else { File templateDir = ReportBL.getDirTemplate(templateID); String imageName = (String) descriptionMap.get(IDescriptionAttributes.PREVIEW_GIF); imgFile = new File(templateDir, imageName); } if (templateID != null) { if (imgFile != null && imgFile.exists()) { try { FileImageInputStream input = new FileImageInputStream(imgFile); ByteArrayOutputStream output = new ByteArrayOutputStream(); byte[] buf = new byte[1024]; byte[] data; int numBytesRead; while ((numBytesRead = input.read(buf)) != -1) { output.write(buf, 0, numBytesRead); } data = output.toByteArray(); output.close(); input.close(); servletResponse.setContentType("image/gif"); OutputStream outputStream = servletResponse.getOutputStream(); outputStream.write(data); outputStream.flush(); } catch (Exception e) { LOGGER.warn("Getting the preview image failed with " + e.getMessage()); LOGGER.debug(ExceptionUtils.getStackTrace(e)); } } } return null; }
From source file:com.lynk.hrm.ui.dialog.InfoEmployee.java
private void startRead() { new SwingWorker<String, Void>() { @Override/* w ww. ja v a 2 s. co m*/ protected String doInBackground() throws Exception { int result; IdCard idCard = new IdCard(); String photoPath = System.getProperty("user.dir") + "/temp/" + "idCard.bmp"; WString imageFile = new WString(photoPath); result = IdCardLibrary.INSTANCE.OpenCardReader(0, 4, 115200); if (result != 0) { showErrorMsg(IdCard.getErrorMsg(result)); return null; } try { result = IdCardLibrary.INSTANCE.GetPersonMsgW(idCard, imageFile); if (result == 0) { uiName.setText(idCard.getName()); uiNamePy.setText(PinyinUtil.getPinpin(idCard.getName())); uiIdCard.setText(idCard.getCardId()); uiGender.setText(idCard.getSex()); uiBirthday.setText(idCard.getBirthday()); uiAge.setText(Integer.toString(Utils.getAge(idCard.getBirthday()))); uiCensusAddress.setText(idCard.getAddress()); RenderedImage imgOri = ImageIO.read(new File(photoPath)); File imgFile = File.createTempFile("photo_", ".png", new File(System.getProperty("user.dir") + "/temp")); ImageIO.write(imgOri, "png", imgFile); uiPhoto.setImage(imgFile.getPath()); uiPhoto.putClientProperty("path", imgFile.getPath()); FileImageInputStream fiis = new FileImageInputStream(new File(imgFile.getPath())); byte[] photoByte = new byte[(int) fiis.length()]; fiis.read(photoByte); fiis.flush(); fiis.close(); uiPhoto.putClientProperty("photo", photoByte); IdCardLibrary.INSTANCE.CloseCardReader(); } Thread.sleep(1000); } catch (Exception e) { showErrorMsg(e); } return null; } }.execute(); }