Example usage for java.io IOException getLocalizedMessage

List of usage examples for java.io IOException getLocalizedMessage

Introduction

In this page you can find the example usage for java.io IOException getLocalizedMessage.

Prototype

public String getLocalizedMessage() 

Source Link

Document

Creates a localized description of this throwable.

Usage

From source file:es.urjc.mctwp.bbeans.research.image.DownloadBean.java

public String accDownloadTaskImages() {
    Task tsk = getSession().getTask();/*  w  w  w.  java2  s  . c o  m*/

    try {
        if (tsk != null) {

            //Get images of task
            FindImagesByTask cmd = (FindImagesByTask) getCommand(FindImagesByTask.class);
            cmd.setTask(tsk);
            cmd = (FindImagesByTask) runCommand(cmd);

            if (cmd != null && cmd.getResult() != null) {
                ZipOutputStream zos = prepareZOS(taskHeader + tsk.getCode());
                downloadImages(cmd.getResult(), zos, taskHeader + tsk.getCode());
                if (zos != null)
                    zos.close();
                completeResponse();
            }
        }
    } catch (IOException e) {
        setErrorMessage(e.getLocalizedMessage());
        e.printStackTrace();
    }

    return null;
}

From source file:eu.lp0.cursus.ui.AboutDialog.java

private String loadResources(String... names) {
    StringBuilder sb = new StringBuilder();
    Iterator<String> it = Arrays.asList(names).iterator();
    while (it.hasNext()) {
        String name = it.next();/* www  . ja  va  2 s.  c om*/

        String content;
        try {
            URL resource = Main.class.getResource(name);
            if (resource == null) {
                throw new IOException("Not found"); //$NON-NLS-1$
            }
            content = IOUtils.toString(resource, "UTF-8"); //$NON-NLS-1$
        } catch (IOException e) {
            log.error("Unable to load " + name + " resource", e); //$NON-NLS-1$ //$NON-NLS-2$
            content = "Error loading " + name + " resource: " + e.getLocalizedMessage() + "\n"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        }
        sb.append(content);

        if (it.hasNext()) {
            sb.append(TEXT_SPLIT);
        }
    }
    return sb.toString();
}

From source file:fr.sanofi.fcl4transmart.controllers.listeners.geneExpression.SelectSTSMFListener.java

@Override
public void handleEvent(Event event) {
    String path = this.selectSTSMFUI.getPath();
    if (path == null)
        return;/*from  ww w.  j a va  2  s.co m*/
    if (path.contains("%")) {
        this.selectSTSMFUI.displayMessage("File name can not contain percent ('%') symbol.");
        return;
    }
    File file = new File(path);
    if (file.exists()) {
        if (file.isFile()) {
            if (!this.checkFormat(file))
                return;
            String newPath;
            if (file.getName().endsWith(".subject_mapping")) {
                newPath = this.dataType.getPath().getAbsolutePath() + File.separator + file.getName();
            } else {
                newPath = this.dataType.getPath().getAbsolutePath() + File.separator + file.getName()
                        + ".subject_mapping";
            }

            File copiedFile = new File(newPath);
            try {
                FileUtils.copyFile(file, copiedFile);
                ((GeneExpressionData) this.dataType).setSTSMF(copiedFile);

                this.selectSTSMFUI.displayMessage("File has been loaded");
                WorkPart.updateSteps();
                //to do: update files list
                UsedFilesPart.sendFilesChanged(this.dataType);
            } catch (IOException e) {
                // TODO Auto-generated catch block
                selectSTSMFUI.displayMessage("File error: " + e.getLocalizedMessage());
                e.printStackTrace();
            }
        } else {
            this.selectSTSMFUI.displayMessage("This is a directory");
        }
    } else {
        this.selectSTSMFUI.displayMessage("This path does no exist");
    }
}

From source file:de.thm.arsnova.util.ImageUtils.java

/**
 * Rescales an image represented by a Base64-encoded {@link String}
 *
 * @param originalImageString// w ww .  jav a2 s.  com
 *            The original image represented by a Base64-encoded
 *            {@link String}
 * @param width
 *            the new width
 * @param height
 *            the new height
 * @return The rescaled Image as Base64-encoded {@link String}, returns null
 *         if the passed-on image isn't in a valid format (a Base64-Image).
 */
String createCover(String originalImageString, final int width, final int height) {
    if (!isBase64EncodedImage(originalImageString)) {
        return null;
    } else {
        final String[] imgInfo = extractImageInfo(originalImageString);

        // imgInfo isn't null and contains two fields, this is checked by "isBase64EncodedImage"-Method
        final String extension = imgInfo[0];
        final String base64String = imgInfo[1];

        byte[] imageData = Base64.decodeBase64(base64String);
        try (final ByteArrayInputStream bais = new ByteArrayInputStream(imageData);
                final ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
            BufferedImage originalImage = ImageIO.read(bais);
            BufferedImage newImage = new BufferedImage(width, height, originalImage.getType());
            Graphics2D g = newImage.createGraphics();

            final double ratio = ((double) originalImage.getWidth()) / ((double) originalImage.getHeight());

            int x = 0, y = 0, w = width, h = height;
            if (originalImage.getWidth() > originalImage.getHeight()) {
                final int newWidth = (int) Math.round((float) height * ratio);
                x = -(newWidth - width) >> 1;
                w = newWidth;
            } else if (originalImage.getWidth() < originalImage.getHeight()) {
                final int newHeight = (int) Math.round((float) width / ratio);
                y = -(newHeight - height) >> 1;
                h = newHeight;
            }
            g.drawImage(originalImage, x, y, w, h, null);
            g.dispose();

            StringBuilder result = new StringBuilder();
            result.append(IMAGE_PREFIX_START);
            result.append(extension);
            result.append(IMAGE_PREFIX_MIDDLE);

            ImageIO.write(newImage, extension, baos);

            baos.flush();

            result.append(Base64.encodeBase64String(baos.toByteArray()));

            return result.toString();
        } catch (IOException e) {
            logger.error(e.getLocalizedMessage());
            return null;
        }
    }
}

From source file:es.urjc.mctwp.bbeans.research.image.DownloadBean.java

public String accDownloadPatientImages() {
    LoadPatient cmd = (LoadPatient) getCommand(LoadPatient.class);
    cmd.setPatientId(getSession().getPatient().getCode());
    cmd = (LoadPatient) runCommand(cmd);

    if (cmd != null && cmd.getResult() != null) {
        Patient patient = cmd.getResult();

        try {//from w w w  .ja va2 s .c o  m
            if (patient.getStudies() != null) {
                ZipOutputStream zos = prepareZOS(patientHeader + patient.getCode());
                downloadPatienImages(patient, zos, null);
                if (zos != null)
                    zos.close();
                completeResponse();
            }
        } catch (IOException e) {
            setErrorMessage(e.getLocalizedMessage());
            e.printStackTrace();
        }
    }

    return null;
}

From source file:com.francetelecom.clara.cloud.mvn.consumer.MvnConsumerConfigurer.java

public void loadAssemblyTemplateFile() {
    Validate.notNull(assemblyTemplateFile, "assemblyTemplateFile should not be null");
    BufferedReader reader = null;
    try {//from   www  . j  a  v  a  2s  .  com
        reader = new BufferedReader(new InputStreamReader(assemblyTemplateFile));
        StringBuilder sb = new StringBuilder();
        String line = null;

        while ((line = reader.readLine()) != null) {
            sb.append(line + "\n");
        }
        this.assemblyTemplate = sb.toString();
    } catch (IOException e) {
        logger.error(e.getLocalizedMessage());
        throw new TechnicalException(e);
    } finally {
        try {
            if (reader != null) {
                reader.close();
            }
        } catch (IOException e) {
            logger.error(e.getLocalizedMessage());
            throw new TechnicalException(e);
        }
    }
}

From source file:com.panet.imeta.trans.step.errorhandling.AbstractFileErrorHandler.java

private void close(Writer outputStreamWriter) throws KettleException {
    if (outputStreamWriter != null) {
        try {//ww w . j  a v a2  s. c om
            outputStreamWriter.flush();
        } catch (IOException exception) {
            log.logError(Messages.getString("AbstractFileErrorHandler.Log.CouldNotFlushContentToFile"), //$NON-NLS-1$
                    exception.getLocalizedMessage());
        }
        try {
            outputStreamWriter.close();
        } catch (IOException exception) {
            throw new KettleException(
                    Messages.getString("AbstractFileErrorHandler.Exception.CouldNotCloseFile"), exception); //$NON-NLS-1$
        } finally {
            outputStreamWriter = null;
        }
    }
}

From source file:ec.edu.chyc.manejopersonal.managebean.GestorAcuerdoConfidencialidad.java

public void fileUploadListener(FileUploadEvent event) {
    UploadedFile file = event.getFile();
    //nombre del archivo que ya se encuentra almacenado en las propiedades
    String nombreArchivoGuardado;
    nombreArchivoGuardado = acuerdoConfidencial.getArchivoAcuerdoConf();

    if (nombreArchivoGuardado.isEmpty() && !modoModificar) {
        //si la propiedad esta llena, significa que antes ya se subi un archivo y ahora est subiendo uno nuevo para reemplazarlo
        // por lo tanto hay que eliminar el archivo anterior
        Path pathArchivoAnterior = ServerUtils.getPathTemp().resolve(nombreArchivoGuardado).normalize();
        File archivoEliminar = pathArchivoAnterior.toFile();
        //borrar el archivo anterior en caso de existir
        if (archivoEliminar.isFile()) {
            archivoEliminar.delete();//from w  ww.  j  a  va  2 s  . c o  m
        }
    }
    if (file != null) {
        String extensionSubida = FilenameUtils.getExtension(file.getFileName());
        String nombreArchivoSubido = ServerUtils.generarNombreValidoArchivo(extensionSubida);
        Path pathArchivo = ServerUtils.getPathTemp().resolve(nombreArchivoSubido).normalize();

        File newFile = pathArchivo.toFile();

        try {
            BeansUtils.subirArchivoPrimefaces(file, newFile);

            acuerdoConfidencial.setArchivoAcuerdoConf(nombreArchivoSubido);
            tamanoArchivo = ServerUtils.humanReadableByteCount(file.getSize());

        } catch (IOException ex) {
            GestorMensajes.getInstance().mostrarMensajeError(ex.getLocalizedMessage());
            Logger.getLogger(GestorAcuerdoConfidencialidad.class.getName()).log(Level.SEVERE, null, ex);
        }
    } else {
        System.err.println("Error al subir archivo");
    }
}

From source file:broadwick.phylo.NewickTreeParser.java

/**
 * Create the parser./*w w w. j a v a 2  s .  c  om*/
 * @param newickFile the name of the file containing the tree.
 */
public NewickTreeParser(final String newickFile) {
    try (FileInput file = new FileInput(newickFile)) {
        newickString = file.read();
    } catch (IOException ex) {
        log.error("Could not read Newick file {}. {}", newickFile, ex.getLocalizedMessage());
    }
}

From source file:fr.sanofi.fcl4transmart.controllers.listeners.clinicalData.SetStudyTreeListener.java

@Override
public void handleEvent(Event event) {
    // TODO Auto-generated method stub
    this.columnsDone = new HashMap<String, Vector<Integer>>();
    for (File rawFile : ((ClinicalData) this.dataType).getRawFiles()) {
        this.columnsDone.put(rawFile.getName(), new Vector<Integer>());
    }//from  w w w.j av a 2 s  .c o m
    if (((ClinicalData) this.dataType).getCMF() == null) {
        this.setStudyTreeUI.displayMessage("Error: no column mapping file");
        return;
    }
    File file = new File(this.dataType.getPath().toString() + File.separator
            + this.dataType.getStudy().toString() + ".columns.tmp");
    try {
        FileWriter fw = new FileWriter(file);
        BufferedWriter out = new BufferedWriter(fw);
        out.write(
                "Filename\tCategory Code\tColumn Number\tData Label\tData Label Source\tControlled Vocab Code\n");

        try {
            BufferedReader br = new BufferedReader(new FileReader(((ClinicalData) this.dataType).getCMF()));
            String line = br.readLine();
            while ((line = br.readLine()) != null) {
                if (line.split("\t", -1)[3].compareTo("SUBJ_ID") == 0
                        || line.split("\t", -1)[3].compareTo("VISIT_NAME") == 0
                        || line.split("\t", -1)[3].compareTo("SITE_ID") == 0) {
                    out.write(line + "\n");
                    this.columnsDone.get(line.split("\t", -1)[0])
                            .add(Integer.parseInt(line.split("\t", -1)[2]));
                } else if (line.split("\t", -1)[3].compareTo("OMIT") != 0
                        && line.split("\t", -1)[3].compareTo("\\") != 0) {
                    File rawFile = new File(this.dataType.getPath() + File.separator + line.split("\t", -1)[0]);
                    this.labels.put(
                            FileHandler.getColumnByNumber(rawFile, Integer.parseInt(line.split("\t", -1)[2])),
                            line.split("\t", -1)[3]);

                }
            }
            br.close();
        } catch (Exception e) {
            this.setStudyTreeUI.displayMessage("File error: " + e.getLocalizedMessage());
            e.printStackTrace();
            out.close();
        }

        this.writeLine(this.setStudyTreeUI.getRoot(), out, "");

        for (String key : this.columnsDone.keySet()) {
            File rawFile = null;
            for (File f : ((ClinicalData) this.dataType).getRawFiles()) {
                if (f.getName().compareTo(key) == 0) {
                    rawFile = f;
                }
            }
            if (rawFile != null) {
                for (int i = 1; i <= FileHandler.getColumnsNumber(rawFile); i++) {
                    if (!this.columnsDone.get(key).contains(i)) {
                        out.write(key + "\t" + "" + "\t" + i + "\t" + "OMIT" + "\t\t\n");
                    }
                }
            }
        }

        out.close();
        try {
            String fileName = ((ClinicalData) this.dataType).getCMF().getName();
            ((ClinicalData) this.dataType).getCMF().delete();
            File fileDest = new File(this.dataType.getPath() + File.separator + fileName);
            FileUtils.moveFile(file, fileDest);
            ((ClinicalData) this.dataType).setCMF(fileDest);
        } catch (IOException ioe) {
            this.setStudyTreeUI.displayMessage("File error: " + ioe.getLocalizedMessage());
            return;
        }
    } catch (Exception e) {
        this.setStudyTreeUI.displayMessage("Error: " + e.getLocalizedMessage());
        e.printStackTrace();
    }
    this.setStudyTreeUI.displayMessage("Column mapping file updated");
    WorkPart.updateSteps();
    WorkPart.updateFiles();
}