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:jenkins.plugins.publish_over_ssh.BapSshHostConfiguration.java

public BapSshClient createClient(final BPBuildInfo buildInfo, final boolean connectSftp) {

    final JSch ssh = createJSch();
    String[] hosts = getHosts();//from www .j av  a2 s.co m
    Session session = createSession(buildInfo, ssh, hosts[0], getPort());
    configureAuthentication(buildInfo, ssh, session);
    final BapSshClient bapClient = new BapSshClient(buildInfo, session, isEffectiveDisableExec());
    try {
        connect(buildInfo, session);
        for (int i = 1; i < hosts.length; i++) {
            int assignedPort = session.setPortForwardingL(0, hosts[i], getPort());
            session = createSession(buildInfo, ssh, LOCALHOST, assignedPort);
            bapClient.addSession(session);
            configureAuthentication(buildInfo, ssh, session);
            connect(buildInfo, session);
        }
        if (connectSftp)
            setupSftp(bapClient);
    } catch (IOException e) {
        bapClient.disconnectQuietly();
        throw new BapPublisherException(Messages.exception_failedToCreateClient(e.getLocalizedMessage()), e);
    } catch (JSchException e) {
        bapClient.disconnectQuietly();
        throw new BapPublisherException(Messages.exception_failedToCreateClient(e.getLocalizedMessage()), e);
    } catch (BapPublisherException e) {
        bapClient.disconnectQuietly();
        throw new BapPublisherException(Messages.exception_failedToCreateClient(e.getLocalizedMessage()), e);
    }
    return bapClient;
}

From source file:com.devilyang.musicstation.cache.ACache.java

/**
 * ? String?//from ww w  .j av  a  2  s  .  c o m
 * 
 * @param key
 * @return String ?
 */
public String getAsString(String key) {
    File file = mCacheManager.get(key);
    if (!file.exists())
        return null;
    boolean removeFile = false;
    BufferedReader in = null;
    try {
        in = new BufferedReader(new FileReader(file));
        String readString = "";
        String currentLine;
        while ((currentLine = in.readLine()) != null) {
            readString += currentLine;
        }
        Log.e("error", "readString = " + readString);
        if (!Utils.isDue(readString)) {
            LogUtil.i("error", "?");
            return Utils.clearDateInfo(readString);
        } else {
            LogUtil.e("error", "?");
            removeFile = true;
            return null;
        }
    } catch (IOException e) {
        Log.e("error", e.getLocalizedMessage());
        e.printStackTrace();
        return null;
    } finally {
        if (in != null) {
            try {
                in.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        if (removeFile)
            remove(key);
    }
}

From source file:com.searchbox.collection.oppfin.TopicCollection.java

/**
 * Load HTML page and extract the part with the description
 *
 * @param callFileName The call identifier in the URL
 * @return The html markup that corresponds to the description
 *///w w  w .  j a va 2  s.  co  m
private String getCallDescription(String callFileName) {

    // If the call is not cached, load it from URL
    if (!callList.containsKey(callFileName)) {
        callList.put(callFileName, new FieldMap());
        // callList.put(item.get("callIdentifier").toString(), item);
    }

    if (!callList.get(callFileName).containsKey("callDescriptionHtml")) {
        LOGGER.info("Loading call description [" + callFileName + "]");

        String topicUrlDetail = String.format(env.getProperty(CALL_DETAIL_URL, CALL_DETAIL_URL_DEFAULT),
                callFileName);

        //            String htmlValue = StringUtils.substringBetween(
        //                    this.loadFromUrl(topicUrlDetail),
        //                    env.getProperty(CALL_DETAIL_BEGIN, CALL_DETAIL_BEGIN_DEFAULT),
        //                    env.getProperty(CALL_DETAIL_END, CALL_DETAIL_END_DEFAULT)).trim();
        //TODO fix bug
        LOGGER.info("Loading topic loadFromUrl [" + topicUrlDetail + "]");
        String htmlValue = StringUtils.substringBetween(this.loadFromUrl(topicUrlDetail),
                env.getProperty(CALL_DETAIL_BEGIN, CALL_DETAIL_BEGIN_DEFAULT),
                env.getProperty(CALL_DETAIL_END, CALL_DETAIL_END_DEFAULT));
        if (htmlValue != null) {
            htmlValue = htmlValue.trim();
        } else {
            htmlValue = "cannot get Description";
        }
        callList.get(callFileName).put("callDescriptionHtml", htmlValue);

        String callDetailRaw = new HtmlToPlainText().getPlainText(Jsoup.parse(htmlValue));

        callList.get(callFileName).put("callDescriptionRaw", callDetailRaw);

        // Creating a new enhancedCall
        JSONObject enhancedCall = new JSONObject();
        // Pulling full HTML description from the web

        String callIdentifier = (String) callList.get(callFileName).get("callId").get(0);
        enhancedCall.put("eur_call_description_html", htmlValue);
        enhancedCall.put("eur_call_description_raw", callDetailRaw);

        enhancedCall.put("FileName", callFileName);
        enhancedCall.put("eur_call_timestamp", Calendar.getInstance().getTime());
        enhancedCall.put("eur_call_FileName", callFileName);
        enhancedCall.put("eur_call_CallId", callIdentifier);

        // Saving the enhanced file
        try {
            File file = new File("output/calls/" + callFileName + ".json");
            file.getParentFile().mkdirs();

            FileWriter writer = new FileWriter(file);
            writer.write(enhancedCall.toJSONString());
            writer.flush();
            writer.close();
            LOGGER.debug("File saved under " + file.getAbsolutePath());

            // Saving the list of calls identifiers
            File file2 = new File("output/calls/calls_identifiers.txt");
            FileWriter writer2 = new FileWriter(file2, true);
            writer2.write(callIdentifier + "\n");
            writer2.flush();
            writer2.close();
        } catch (IOException e) {
            LOGGER.error(e.getLocalizedMessage());
        }

    }

    return callList.get(callFileName).get("callDescriptionHtml").toString();
}

From source file:it.geosolutions.geobatch.geotiff.retile.GeotiffRetilerAction.java

@Override
public Queue<FileSystemEvent> execute(Queue<FileSystemEvent> events) throws ActionException {
    try {/*from  ww w . j  a v  a  2  s . c  om*/

        if (configuration == null) {
            final String message = "GeotiffRetiler::execute(): flow configuration is null.";
            if (LOGGER.isErrorEnabled())
                LOGGER.error(message);
            throw new ActionException(this, message);
        }
        if (events.size() == 0) {
            throw new ActionException(this,
                    "GeotiffRetiler::execute(): Unable to process an empty events queue.");
        }

        if (LOGGER.isInfoEnabled())
            LOGGER.info("GeotiffRetiler::execute(): Starting with processing...");

        listenerForwarder.started();

        // The return
        final Queue<FileSystemEvent> ret = new LinkedList<FileSystemEvent>();

        while (events.size() > 0) {

            FileSystemEvent event = events.remove();

            File eventFile = event.getSource();
            FileSystemEventType eventType = event.getEventType();

            if (eventFile.exists() && eventFile.canRead() && eventFile.canWrite()) {
                /*
                 * If here: we can start retiler actions on the incoming file event
                 */

                if (eventFile.isDirectory()) {

                    File[] fileList = eventFile.listFiles();
                    int size = fileList.length;
                    for (int progress = 0; progress < size; progress++) {

                        File inFile = fileList[progress];

                        final String absolutePath = inFile.getAbsolutePath();
                        final String inputFileName = FilenameUtils.getName(absolutePath);

                        if (LOGGER.isInfoEnabled())
                            LOGGER.info("is going to retile: " + inputFileName);

                        try {

                            listenerForwarder.setTask("GeotiffRetiler");
                            GeoTiffRetilerUtils.reTile(inFile, configuration, getTempDir());

                            // set the output
                            /*
                             * COMMENTED OUT 21 Feb 2011: simone: If the event represents a Dir
                             * we have to return a Dir. Do not matter failing files.
                             * 
                             * carlo: we may also want to check if a file is already tiled!
                             * 
                             * File outputFile=reTile(inFile); if (outputFile!=null){ //TODO:
                             * here we use the same event for each file in the ret.add(new
                             * FileSystemEvent(outputFile, eventType)); }
                             */

                        } catch (UnsupportedOperationException uoe) {
                            listenerForwarder.failed(uoe);
                            if (LOGGER.isWarnEnabled())
                                LOGGER.warn(uoe.getLocalizedMessage(), uoe);
                            continue;
                        } catch (IOException ioe) {
                            listenerForwarder.failed(ioe);
                            if (LOGGER.isWarnEnabled())
                                LOGGER.warn(ioe.getLocalizedMessage(), ioe);
                            continue;
                        } catch (IllegalArgumentException iae) {
                            listenerForwarder.failed(iae);
                            if (LOGGER.isWarnEnabled())
                                LOGGER.warn(iae.getLocalizedMessage(), iae);
                            continue;
                        } finally {
                            listenerForwarder.setProgress((progress * 100) / ((size != 0) ? size : 1));
                            listenerForwarder.progressing();
                        }
                    }

                    if (LOGGER.isInfoEnabled())
                        LOGGER.info("SUCCESSFULLY completed work on: " + event.getSource());

                    // add the directory to the return
                    ret.add(event);
                } else {
                    // file is not a directory
                    try {
                        listenerForwarder.setTask("GeotiffRetiler");
                        final File outputFile = GeoTiffRetilerUtils.reTile(eventFile, configuration,
                                getTempDir());

                        if (LOGGER.isInfoEnabled())
                            LOGGER.info("SUCCESSFULLY completed work on: " + event.getSource());
                        listenerForwarder.setProgress(100);
                        ret.add(new FileSystemEvent(outputFile, eventType));

                    } catch (UnsupportedOperationException uoe) {
                        listenerForwarder.failed(uoe);
                        if (LOGGER.isWarnEnabled())
                            LOGGER.warn(uoe.getLocalizedMessage(), uoe);
                        continue;
                    } catch (IOException ioe) {
                        listenerForwarder.failed(ioe);
                        if (LOGGER.isWarnEnabled())
                            LOGGER.warn(ioe.getLocalizedMessage(), ioe);
                        continue;
                    } catch (IllegalArgumentException iae) {
                        listenerForwarder.failed(iae);
                        if (LOGGER.isWarnEnabled())
                            LOGGER.warn(iae.getLocalizedMessage(), iae);
                        continue;
                    } finally {

                        listenerForwarder.setProgress((100) / ((events.size() != 0) ? events.size() : 1));
                        listenerForwarder.progressing();
                    }
                }
            } else {
                final String message = "The passed file event refers to a not existent "
                        + "or not readable/writeable file! File: " + eventFile.getAbsolutePath();
                if (LOGGER.isWarnEnabled())
                    LOGGER.warn(message);
                final IllegalArgumentException iae = new IllegalArgumentException(message);
                listenerForwarder.failed(iae);
            }
        } // endwile
        listenerForwarder.completed();

        // return
        if (ret.size() > 0) {
            events.clear();
            return ret;
        } else {
            /*
             * If here: we got an error no file are set to be returned the input queue is
             * returned
             */
            return events;
        }
    } catch (Exception t) {
        if (LOGGER.isErrorEnabled())
            LOGGER.error(t.getLocalizedMessage(), t);
        final ActionException exc = new ActionException(this, t.getLocalizedMessage(), t);
        listenerForwarder.failed(exc);
        throw exc;
    }
}

From source file:net.sf.jabref.external.ExternalFilePanel.java

private void pushXMP(final String fieldName, final FieldEditor editor) {

    JabRefExecutorService.INSTANCE.execute(new Runnable() {

        @Override//from   ww w.  j a  v a  2  s  .c  om
        public void run() {

            output(Localization.lang("Looking for pdf..."));

            // Find the default directory for this field type, if any:
            String[] dirs = metaData.getFileDirectory(fieldName);
            File file = null;
            if (dirs.length > 0) {
                File tmp = FileUtil.expandFilename(editor.getText(), dirs);
                if (tmp != null) {
                    file = tmp;
                }
            }

            if (file == null) {
                file = new File(editor.getText());
            }

            final File finalFile = file;

            output(Localization.lang("Writing XMP to '%0'...", finalFile.getName()));
            try {
                XMPUtil.writeXMP(finalFile, getEntry(), getDatabase());
                output(Localization.lang("Wrote XMP to '%0'.", finalFile.getName()));
            } catch (IOException e) {
                JOptionPane.showMessageDialog(editor.getParent(),
                        Localization.lang("Error writing XMP to file: %0", e.getLocalizedMessage()),
                        Localization.lang("Writing XMP"), JOptionPane.ERROR_MESSAGE);
                // String above and below
                LOGGER.info("Error writing XMP to file: " + finalFile.getAbsolutePath(), e);
                output(Localization.lang("Error writing XMP to file: %0", finalFile.getName()));

            } catch (TransformerException e) {
                JOptionPane.showMessageDialog(editor.getParent(),
                        Localization.lang("Error converting BibTeX to XMP: %0", e.getLocalizedMessage()),
                        Localization.lang("Writing XMP"), JOptionPane.ERROR_MESSAGE);
                LOGGER.info("Error while converting BibEntry to XMP " + finalFile.getAbsolutePath(), e);
                output(Localization.lang("Error converting XMP to '%0'...", finalFile.getName()));
            }
        }
    });
}

From source file:ca.phon.plugins.praat.TextGridManager.java

/**
 * Merge text grids for a session./*from   ww w .  ja  v  a  2  s . c  o  m*/
 * 
 * @param session
 * 
 * @return single TextGrid for merged session
 */
public TextGrid mergeTextGrids(Session session) throws IOException {
    // get xmin and xmax
    double xmin = 0;
    double xmax = 0;

    List<TextGrid> textGrids = new ArrayList<>();
    for (Record record : session.getRecords()) {
        final String id = record.getUuid().toString();

        final String textGridPath = textGridPath(id);
        final File textGridFile = new File(textGridPath);
        if (textGridFile.exists()) {
            try {
                TextGrid tg = loadTextGrid(textGridFile);

                xmin = Math.min(xmin, tg.getXmin());
                xmax = Math.max(xmax, tg.getXmax());

                textGrids.add(tg);
            } catch (IOException e) {
                // TODO - show warning to user
                LOGGER.log(Level.SEVERE, e.getLocalizedMessage(), e);
            }
        }
    }

    try {
        TextGrid retVal = TextGrid.createWithoutTiers(xmin, xmax);

        Map<String, Long> intervalTiers = new LinkedHashMap<>();
        Map<String, Long> pointTiers = new LinkedHashMap<>();

        for (TextGrid tg : textGrids) {
            for (long i = 1; i <= tg.numberOfTiers(); i++) {
                try {
                    IntervalTier intervalTier = tg.checkSpecifiedTierIsIntervalTier(i);

                    IntervalTier fullIntervalTier = null;
                    if (!intervalTiers.keySet().contains(intervalTier.getName().toString())) {
                        fullIntervalTier = IntervalTier.create(xmin, xmax);
                        fullIntervalTier.setForgetOnFinalize(false);
                        fullIntervalTier.setName(intervalTier.getName());
                        fullIntervalTier.removeInterval(1);

                        retVal.addTier(fullIntervalTier);
                        intervalTiers.put(intervalTier.getName().toString(), retVal.numberOfTiers());
                    }
                    Long tierNum = intervalTiers.get(intervalTier.getName().toString());
                    if (tierNum != null && tierNum > 0 && tierNum <= retVal.numberOfTiers()) {
                        try {
                            fullIntervalTier = retVal.checkSpecifiedTierIsIntervalTier(tierNum);
                        } catch (PraatException e) {
                            LOGGER.log(Level.SEVERE, e.getLocalizedMessage(), e);
                        }
                    }

                    if (fullIntervalTier != null) {
                        for (long j = 1; j <= intervalTier.numberOfIntervals(); j++) {
                            TextInterval interval = intervalTier.interval(j);
                            fullIntervalTier.addInterval(interval.getXmin(), interval.getXmax(),
                                    interval.getText());
                        }
                    }

                } catch (PraatException e) {
                    try {
                        TextTier pointTier = tg.checkSpecifiedTierIsPointTier(i);

                        TextTier fullPointTier = null;
                        if (!pointTiers.keySet().contains(pointTier.getName().toString())) {
                            fullPointTier = TextTier.create(xmin, xmax);
                            // don't delete native tier object when reference goes out of scope
                            fullPointTier.setForgetOnFinalize(false);
                            fullPointTier.setName(pointTier.getName());
                            fullPointTier.removePoint(1);

                            retVal.addTier(fullPointTier);
                            pointTiers.put(pointTier.getName().toString(), retVal.numberOfTiers());
                        }
                        Long tierNum = pointTiers.get(pointTier.getName().toString());
                        if (tierNum != null && tierNum > 0 && tierNum <= retVal.numberOfTiers()) {
                            try {
                                fullPointTier = retVal.checkSpecifiedTierIsPointTier(tierNum);
                            } catch (PraatException ex) {
                                LOGGER.log(Level.SEVERE, ex.getLocalizedMessage(), ex);
                            }
                        }

                        if (fullPointTier != null) {
                            for (long j = 1; j < pointTier.numberOfPoints(); j++) {
                                TextPoint tp = pointTier.point(j);
                                fullPointTier.addPoint(tp.getNumber(), tp.getText());
                            }
                        }

                    } catch (PraatException e1) {
                        LOGGER.log(Level.SEVERE, e1.getLocalizedMessage(), e1);
                    }
                }
            }
        }
        return retVal;
    } catch (PraatException e) {
        throw new IOException(e);
    }
}

From source file:com.kylinolap.cube.CubeManager.java

/**
 * After cube update, reload cube related cache
 * //from   w  ww . ja  va  2 s .  c  om
 * @param cube
 */
public void loadCubeCache(CubeInstance cube) {
    try {
        loadCubeInstance(cube.getResourcePath());
    } catch (IOException e) {
        logger.error(e.getLocalizedMessage(), e);
    }
}

From source file:controllers.BoxHandler.java

public Map<String, Boolean> getMapFoMaprStrings(String input) {
    Map<String, Boolean> boxIdMap = null;
    try {//w ww .  j  a  va2s  . c  o  m
        boxIdMap = objectMapper.readValue(input, new TypeReference<HashMap<String, Boolean>>() {
        });
    } catch (IOException e) {
        log.error(e.getLocalizedMessage());
        log.debug("trace:" + e);
    }
    if (boxIdMap == null || boxIdMap.isEmpty())
        return null;

    return boxIdMap;
}

From source file:com.icesoft.jasper.compiler.TldLocationsCache.java

/**
 * Scans the given JarURLConnection for TLD files located in META-INF (or a
 * subdirectory of it), adding an implicit map entry to the taglib map for
 * any TLD that has a <uri> element.
 *
 * @param conn   The JarURLConnection to the JAR file to scan
 * @param ignore true if any exceptions raised when processing the given JAR
 *               should be ignored, false otherwise
 *//*  ww w  . j a va  2s .c o  m*/
private void scanJar(JarURLConnection conn, boolean ignore) throws JasperException {

    JarFile jarFile = null;
    String resourcePath = conn.getJarFileURL().toString();
    try {
        if (redeployMode) {
            conn.setUseCaches(false);
        }
        jarFile = conn.getJarFile();
        Enumeration entries = jarFile.entries();
        while (entries.hasMoreElements()) {
            JarEntry entry = (JarEntry) entries.nextElement();
            String name = entry.getName();
            if (!name.startsWith("META-INF/"))
                continue;
            if (!name.endsWith(".tld"))
                continue;
            InputStream stream = jarFile.getInputStream(entry);
            try {
                String uri = getUriFromTld(resourcePath, stream);
                // Add implicit map entry only if its uri is not already
                // present in the map
                if (uri != null && mappings.get(uri) == null) {
                    mappings.put(uri, new String[] { resourcePath, name });
                }
            } finally {
                if (stream != null) {
                    try {
                        stream.close();
                    } catch (IOException e) {
                        if (log.isDebugEnabled()) {
                            log.debug(e.getLocalizedMessage(), e);
                        }
                    }
                }
            }
        }
    } catch (IOException ex) {
        if (log.isDebugEnabled()) {
            log.debug(ex.getMessage(), ex);
        }
        if (!redeployMode) {
            // if not in redeploy mode, close the jar in case of an error
            if (jarFile != null) {
                try {
                    jarFile.close();
                } catch (IOException e) {
                    if (log.isDebugEnabled()) {
                        log.debug(e.getLocalizedMessage(), e);
                    }
                }
            }
        }
        if (!ignore) {
            throw new JasperException(ex);
        }
    } finally {
        if (redeployMode) {
            // if in redeploy mode, always close the jar
            if (jarFile != null) {
                try {
                    jarFile.close();
                } catch (IOException e) {
                    if (log.isDebugEnabled()) {
                        log.debug(e.getLocalizedMessage(), e);
                    }
                }
            }
        }
    }
}

From source file:com.kylinolap.cube.CubeManager.java

private void afterCubeUpdated(CubeInstance updatedCube) {
    MetadataManager.getInstance(config).reload();
    cubeMap.put(updatedCube.getName().toUpperCase(), updatedCube);

    for (ProjectInstance project : ProjectManager.getInstance(config).getProjects(updatedCube.getName())) {
        try {//  w w  w  . j  av  a 2 s. c om
            ProjectManager.getInstance(config).loadProjectCache(project, true);
        } catch (IOException e) {
            logger.error(e.getLocalizedMessage(), e);
        }
    }
}