Example usage for javax.imageio.stream FileImageOutputStream FileImageOutputStream

List of usage examples for javax.imageio.stream FileImageOutputStream FileImageOutputStream

Introduction

In this page you can find the example usage for javax.imageio.stream FileImageOutputStream FileImageOutputStream.

Prototype

public FileImageOutputStream(RandomAccessFile raf) 

Source Link

Document

Constructs a FileImageOutputStream that will write to a given RandomAccessFile .

Usage

From source file:de.hpi.fgis.hdrs.node.Node.java

private void writeSegmentIdCounter() {
    try {/*  w  w  w .ja v  a 2 s. c o m*/
        File f = new File(rootDir.getAbsolutePath() + File.separator + SEGMENT_ID_COUNTER_FILE);
        if (f.isFile()) {
            if (!f.delete()) {
                throw new IOException("Cannot delete old index meta file");
            }
        }
        FileImageOutputStream out = new FileImageOutputStream(f);
        out.writeInt(segmentIdCounter);
        out.close();
    } catch (IOException ex) {
        LOG.error("Error writing store meta file", ex);
    }
}

From source file:com.lynk.hrm.ui.dialog.InfoEmployee.java

private void updateData() {
    uiId.setText(employee.getId());//from w  w  w.j  a  va  2  s .  co m
    uiName.setText(employee.getName());
    uiNamePy.setText(employee.getNamePy());
    if (StringUtils.isNotEmpty(employee.getState())) {
        uiState.setSelectedItem(employee.getState());
        switch (employee.getState()) {
        case Employee.STATE_LEAVE:
        case Employee.STATE_RETIRE:
        case Employee.STATE_DELETE:
            uiInfoTab.setSelectedIndex(1);
            break;
        case Employee.STATE_SUSPEND:
            uiInfoTab.setSelectedIndex(2);
            break;
        case Employee.STATE_PROBATION:
        case Employee.STATE_CONTRACT:
        default:
            break;
        }
    }
    uiTimeCardLeaveCertify.setText(employee.getTimeCard());
    uiIdCard.setText(employee.getIdCard());
    uiBirthday.setText(employee.getBirthday());
    uiAge.setText(employee.getAge().toString());
    uiGender.setText(employee.getGender());
    if (StringUtils.isNotEmpty(employee.getMaritalStatus())) {
        uiMarital.setSelectedItem(employee.getMaritalStatus());
    }
    uiContact.setText(employee.getContact());
    if (StringUtils.isNotEmpty(employee.getCensus())) {
        uiCensus.setSelectedItem(employee.getCensus());
    }
    uiCensusAddress.setText(employee.getCensusAddress());

    // ?
    if (employee.getEmployeePhoto() != null && employee.getEmployeePhoto().getPhoto() != null
            && employee.getEmployeePhoto().getPhoto().length > 0) {
        EmployeePhoto photo = employee.getEmployeePhoto();
        try {
            File imageFile = new File(System.getProperty("user.dir") + "/temp/" + employee.getId() + ".png");
            FileImageOutputStream fios = new FileImageOutputStream(imageFile);
            fios.write(photo.getPhoto());
            fios.flush();
            fios.close();
            uiPhoto.putClientProperty("path", imageFile.getPath());
            uiPhoto.setImage(imageFile.getPath());
        } catch (Exception e) {
            showErrorMsg(e);
        }
    } else {
        uiPhoto.setImage("resource/image/default_emp_photo.png", true);
    }

    uiAddress.setText(employee.getAddress());
    if (StringUtils.isNotEmpty(employee.getCensusProvince())) {
        uiResidencePermit.setSelectedItem(employee.getCensusProvince());
    }
    if (StringUtils.isNotEmpty(employee.getDept())) {
        uiDept.setText(employee.getDept());
    }
    if (StringUtils.isNotEmpty(employee.getJob())) {
        uiJob.setText(employee.getJob());
    }
    if (StringUtils.isNotEmpty(employee.getEntryDate())) {
        uiEntryDate.setDate(Utils.dateFromStr(employee.getEntryDate()));
    }
    uiWorkAge.setText(UtilsClient.convertWorkAgeToStr(employee.getWorkAge()));
    if (StringUtils.isNotEmpty(employee.getProbationDate())) {
        uiProbation.setDate(Utils.dateFromStr(employee.getProbationDate()));
    }
    if (StringUtils.isNotEmpty(employee.getExpirationDate())) {
        uiExpiration.setText(employee.getExpirationDate());
    }
    if (StringUtils.isNotEmpty(employee.getDegree())) {
        uiDegree.setSelectedItem(employee.getDegree());
    }
    uiSchool.setText(employee.getSchool());
    uiMajor.setText(employee.getMajor());
    //      uiSuspendEnd.setText(employee.getSuspendEnd());
    uiWorkExperience.setText(employee.getWorkExperience());
    uiSocialCard.setText(employee.getSocialCard());
    uiHousingCard.setText(employee.getHousingCard());
    uiBankCard.setText(employee.getBankCard());
    uiNote.setText(employee.getNote());
    uiPerformance.setText(employee.getCensusCity());
    if (StringUtils.isNotEmpty(employee.getLeaveDate())) {
        uiLeaveDate.setDate(Utils.dateFromStr(employee.getLeaveDate()));
    }

    if (StringUtils.isNotEmpty(employee.getSocialEndDate())) {
        uiSocialEndDate.setText(employee.getSocialEndDate());
    }
    if (StringUtils.isNotEmpty(employee.getHousingEndDate())) {
        uiHousingEndDate.setText(employee.getHousingEndDate());
    }
    uiLeaveType.setSelectedItem(employee.getLeaveType());
    uiLeaveReason.setText(employee.getLeaveReason());
    uiFactory.setSelectedItem(employee.getSuspendNote());
    uiDdg.setSelectedItem(employee.getSuspendStart());
}

From source file:com.lynk.hrm.ui.dialog.InfoEmployee.java

private void initData(final String id) {
    showWaitPanel("?......");
    new SwingWorker<Employee, Void>() {

        @Override//w  w w. j ava2s  . com
        protected Employee doInBackground() throws Exception {
            if (StringUtils.isEmpty(id)) {
                return Employee.createNewEmployee();
            } else {
                return HrmBiz.getInstance().getEmployee(id);
            }
        }

        @Override
        protected void done() {
            try {
                employee = get();
                uiEntryDate.setCalendar(Calendar.getInstance());
                uiId.setText(employee.getId());
                uiName.setText(employee.getName());
                uiNamePy.setText(employee.getNamePy());
                if (StringUtils.isNotEmpty(employee.getState())) {
                    uiState.setSelectedItem(employee.getState());
                    switch (employee.getState()) {
                    case Employee.STATE_LEAVE:
                    case Employee.STATE_RETIRE:
                    case Employee.STATE_DELETE:
                        uiInfoTab.setSelectedIndex(1);
                        break;
                    case Employee.STATE_SUSPEND:
                        uiInfoTab.setSelectedIndex(2);
                        break;
                    case Employee.STATE_PROBATION:
                    case Employee.STATE_CONTRACT:
                    default:
                        break;
                    }
                }
                uiTimeCardLeaveCertify.setText(employee.getTimeCard());
                uiIdCard.setText(employee.getIdCard());
                uiBirthday.setText(employee.getBirthday());
                uiAge.setText(employee.getAge().toString());
                uiGender.setText(employee.getGender());
                if (StringUtils.isNotEmpty(employee.getMaritalStatus())) {
                    uiMarital.setSelectedItem(employee.getMaritalStatus());
                }
                uiContact.setText(employee.getContact());
                if (StringUtils.isNotEmpty(employee.getCensus())) {
                    uiCensus.setSelectedItem(employee.getCensus());
                }
                uiCensusAddress.setText(employee.getCensusAddress());

                // ?
                if (employee.getEmployeePhoto() != null && employee.getEmployeePhoto().getPhoto() != null
                        && employee.getEmployeePhoto().getPhoto().length > 0) {
                    EmployeePhoto photo = employee.getEmployeePhoto();
                    uiPhoto.putClientProperty("photo", employee.getEmployeePhoto().getPhoto());
                    try {
                        File imageFile = new File(
                                System.getProperty("user.dir") + "/temp/" + employee.getId() + ".png");
                        FileImageOutputStream fios = new FileImageOutputStream(imageFile);
                        fios.write(photo.getPhoto());
                        fios.flush();
                        fios.close();
                        uiPhoto.putClientProperty("path", imageFile.getPath());
                        uiPhoto.setImage(imageFile.getPath());
                    } catch (Exception e) {
                        showErrorMsg(e);
                    }
                } else {
                    uiPhoto.setImage("resource/image/default_emp_photo.png", true);
                }

                uiAddress.setText(employee.getAddress());
                if (StringUtils.isNotEmpty(employee.getCensusProvince())) {
                    uiResidencePermit.setSelectedItem(employee.getCensusProvince());
                }
                if (StringUtils.isNotEmpty(employee.getSuspendNote())) {
                    uiFactory.setSelectedItem(employee.getSuspendNote());
                }
                if (StringUtils.isNotEmpty(employee.getDept())) {
                    uiDept.setText(employee.getDept());
                }
                if (StringUtils.isNotEmpty(employee.getJob())) {
                    uiJob.setText(employee.getJob());
                }
                if (StringUtils.isNotEmpty(employee.getSuspendStart())) {
                    uiDdg.setSelectedItem(employee.getSuspendStart());
                }
                if (StringUtils.isNotEmpty(employee.getEntryDate())) {
                    uiEntryDate.setDate(Utils.dateFromStr(employee.getEntryDate()));
                }
                uiWorkAge.setText(UtilsClient.convertWorkAgeToStr(employee.getWorkAge()));
                if (StringUtils.isNotEmpty(employee.getProbationDate())) {
                    uiProbation.setDate(Utils.dateFromStr(employee.getProbationDate()));
                }
                if (StringUtils.isNotEmpty(employee.getExpirationDate())) {
                    uiExpiration.setText(employee.getExpirationDate());
                }
                if (StringUtils.isNotEmpty(employee.getDegree())) {
                    uiDegree.setSelectedItem(employee.getDegree());
                }
                uiSchool.setText(employee.getSchool());
                uiMajor.setText(employee.getMajor());
                uiWorkExperience.setText(employee.getWorkExperience());
                //               uiSuspendEnd.setText(employee.getSuspendEnd());
                uiSocialCard.setText(employee.getSocialCard());
                uiHousingCard.setText(employee.getHousingCard());
                uiBankCard.setText(employee.getBankCard());
                uiNote.setText(employee.getNote());
                uiPerformance.setText(employee.getCensusCity());
                uiPhoneShort.setText(employee.getPhoneShort());
                if (StringUtils.isNotEmpty(employee.getLeaveDate())) {
                    uiLeaveDate.setDate(Utils.dateFromStr(employee.getLeaveDate()));
                }

                if (StringUtils.isNotEmpty(employee.getSocialEndDate())) {
                    uiSocialEndDate.setText(employee.getSocialEndDate());
                }
                if (StringUtils.isNotEmpty(employee.getHousingEndDate())) {
                    uiHousingEndDate.setText(employee.getHousingEndDate());
                }
                uiLeaveType.setSelectedItem(employee.getLeaveType());
                uiLeaveReason.setText(employee.getLeaveReason());
                if (StringUtils.isNotEmpty(employee.getJobTitle())) {
                    uiGuide.setText(employee.getJobTitle());
                }
                hideWaitPanel();
            } catch (Exception e) {
                hideWaitPanel();
                showErrorMsg(e);
            }

        }

    }.execute();
}

From source file:org.angcms.util.ResourceUtils.java

public static String createImage_(String folder, String imageFileName, byte[] data) {
    try {//from w ww . jav a  2s  .co  m
        String actualFileName = getUniqueName(getRealPath(folder), imageFileName);
        FileImageOutputStream imageOutput;
        imageOutput = new FileImageOutputStream(new File(actualFileName));
        imageOutput.write(data, 0, data.length);
        imageOutput.close();
        return actualFileName.substring(actualFileName.lastIndexOf(File.separator) + 1);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
        return null;
    } catch (IOException e) {
        e.printStackTrace();
        return null;
    }
}

From source file:org.dcm4che2.tool.dcm2dcm.Dcm2Dcm.java

/**
 * Recodes the images from the source transfer syntax, as read from the src
 * file, to the specified destination syntax.
 *//*from w w  w .j  av a 2  s  .  co  m*/
public void recodeImages(File src, File dest) throws IOException {
    ImageReader reader = new DicomImageReaderSpi().createReaderInstance();
    ImageWriter writer = new DicomImageWriterSpi().createWriterInstance();

    DicomStreamMetaData writeMeta = (DicomStreamMetaData) writer.getDefaultStreamMetadata(null);

    DicomObject ds;
    int frames;

    FileImageOutputStream output = null;

    try {
        FileImageInputStream input = new FileImageInputStream(src);

        try {
            reader.setInput(input);
            if (dest.exists())
                dest.delete();
            output = new FileImageOutputStream(dest);
            writer.setOutput(output);
            DicomStreamMetaData streamMeta = (DicomStreamMetaData) reader.getStreamMetadata();
            ds = streamMeta.getDicomObject();

            DicomObject newDs = new BasicDicomObject();
            ds.copyTo(newDs);
            writeMeta.setDicomObject(newDs);
            frames = ds.getInt(Tag.NumberOfFrames, 1);
            newDs.putString(Tag.TransferSyntaxUID, VR.UI, destinationSyntax.uid());
            newDs.putString(Tag.ImplementationClassUID, VR.UI, Implementation.classUID());
            newDs.putString(Tag.ImplementationVersionName, VR.SH, Implementation.versionName());
            if (overwriteObject != null) {
                overwriteObject.copyTo(newDs);
            }
        } finally {
            reader.dispose();
        }
        writer.prepareWriteSequence(writeMeta);
        for (int i = 0; i < frames; i++) {
            FileInputStream inputStream = new FileInputStream(src);
            try {
                WritableRaster r = (WritableRaster) readRaster(inputStream, i);

                ColorModel cm = ColorModelFactory.createColorModel(ds);
                BufferedImage bi = new BufferedImage(cm, r, false, null);
                IIOImage iioimage = new IIOImage(bi, null, null);
                writer.writeToSequence(iioimage, null);
            } catch (NoSuchFieldException ex) {
                System.err.println(ex.toString());
            } catch (IllegalAccessException ex) {
                System.err.println(ex.toString());
            } finally {
                inputStream.close();
            }
        }
        writer.endWriteSequence();
    } finally {
        if (output != null) {
            output.close();
        }
    }
}

From source file:org.giavacms.base.common.util.ResourceUtils.java

public static String createImage_(String folder, String imageFileName, byte[] data) {
    try {//from w ww.  j  a  va2s  .c  o  m
        String actualFileName = getUniqueName(getRealPath() + folder, imageFileName);
        FileImageOutputStream imageOutput;
        imageOutput = new FileImageOutputStream(new File(actualFileName));
        imageOutput.write(data, 0, data.length);
        imageOutput.close();
        return actualFileName.substring(actualFileName.lastIndexOf(File.separator) + 1);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
        return null;
    } catch (IOException e) {
        e.printStackTrace();
        return null;
    }
}

From source file:org.jahia.services.image.AbstractJava2DImageService.java

protected void saveImageToFile(BufferedImage dest, String mimeType, File destFile) throws IOException {
    Iterator<ImageWriter> suffixWriters = ImageIO.getImageWritersByMIMEType(mimeType);
    if (suffixWriters.hasNext()) {
        ImageWriter imageWriter = suffixWriters.next();
        ImageOutputStream imageOutputStream = new FileImageOutputStream(destFile);
        imageWriter.setOutput(imageOutputStream);
        imageWriter.write(dest);/* w w  w  .j a  v  a2 s.  co m*/
        imageOutputStream.close();
    } else {
        logger.warn(
                "Couldn't find a writer for mime type : " + mimeType + "(" + this.getClass().getName() + ")");
    }
}

From source file:org.meveo.admin.util.ModuleUtil.java

public static void cropPicture(String filename, CroppedImage croppedImage) throws Exception {
    FileImageOutputStream imageOutput = new FileImageOutputStream(new File(filename));
    imageOutput.write(croppedImage.getBytes(), 0, croppedImage.getBytes().length);
    imageOutput.flush();//from  w w w  .  j a  v a 2  s .  c  o m
    imageOutput.close();
}

From source file:org.olat.core.commons.services.image.spi.ImageHelperImpl.java

/**
 * Can change this to choose a better compression level as the default
 * @param image//www.ja v a  2 s  .  co  m
 * @param scaledImage
 * @return
 */
public static boolean writeTo(BufferedImage image, File scaledImage, Size scaledSize, String outputFormat) {
    try {
        if (!StringHelper.containsNonWhitespace(outputFormat)) {
            outputFormat = OUTPUT_FORMAT;
        }

        Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName(outputFormat);
        if (writers.hasNext()) {
            ImageWriter writer = writers.next();
            ImageWriteParam iwp = getOptimizedImageWriteParam(writer, scaledSize);
            IIOImage iiOImage = new IIOImage(image, null, null);
            ImageOutputStream iOut = new FileImageOutputStream(scaledImage);
            writer.setOutput(iOut);
            writer.write(null, iiOImage, iwp);
            writer.dispose();
            iOut.flush();
            iOut.close();
            return true;
        } else {
            return ImageIO.write(image, outputFormat, scaledImage);
        }
    } catch (IOException e) {
        return false;
    }
}

From source file:org.onehippo.forge.gallerymagick.core.command.ScalrProcessorUtils.java

/**
 * Creates and returns an {@link ImageWriter} instance from the {@code targetFile}.
 * @param targetFile target file/*from www  .  j  a  v  a2  s  .co  m*/
 * @return an {@link ImageWriter} instance
 * @throws IOException if IOException occurs
 */
private static ImageWriter getImageWriter(File targetFile) throws IOException {
    ImageWriter writer = null;
    String extension = FilenameUtils.getExtension(targetFile.getName());
    Iterator<ImageWriter> it = ImageIO.getImageWritersBySuffix(extension);

    if (it.hasNext()) {
        writer = it.next();
        ImageOutputStream output = new FileImageOutputStream(targetFile);
        writer.setOutput(output);
    }

    return writer;
}