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:net.sf.jabref.exporter.BibDatabaseWriter.java

public SaveSession savePartOfDatabase(BibDatabaseContext bibDatabaseContext, List<BibEntry> entries,
        SavePreferences preferences) throws SaveException {

    SaveSession session;/*  ww  w. j  a  v a  2s. c om*/
    try {
        session = new SaveSession(preferences.getEncoding(), preferences.getMakeBackup());
    } catch (IOException e) {
        throw new SaveException(e.getMessage(), e.getLocalizedMessage());
    }

    exceptionCause = null;
    // Get our data stream. This stream writes only to a temporary file until committed.
    try (VerifyingWriter writer = session.getWriter()) {
        List<FieldChange> saveActionChanges = writePartOfDatabase(writer, bibDatabaseContext, entries,
                preferences);
        session.addFieldChanges(saveActionChanges);
    } catch (IOException ex) {
        LOGGER.error("Could not write file", ex);
        session.cancel();
        throw new SaveException(ex.getMessage(), ex.getLocalizedMessage(), exceptionCause);
    }

    return session;

}

From source file:com.honeywell.printer.net.autobaln_websocket.WebSocketWriter.java

@Override
public void run() {
    OutputStream outputStream = null;
    try {/*from   w  w  w.j  a  v  a  2  s .  co m*/
        outputStream = mSocket.getOutputStream();
    } catch (IOException e) {
        Log.e(TAG, e.getLocalizedMessage());
    }

    this.mOutputStream = outputStream;

    Looper.prepare();

    this.mHandler = new ThreadHandler(this);

    synchronized (this) {
        Log.d(TAG, "WebSocker writer running.");

        notifyAll();
    }

    Looper.loop();
}

From source file:com.epam.dlab.backendapi.core.commands.CommandExecutorMockAsync.java

/**
 * Return the section of resource statuses for docker action status.
 *///from  w w  w .ja v  a2s.com
private String getResponseLibInstall(boolean isSuccess) {
    List<LibInstallDTO> list;
    try {
        JsonNode json = MAPPER.readTree(parser.getJson());
        json = json.get("libs");
        list = MAPPER.readValue(json.toString(), new TypeReference<List<LibInstallDTO>>() {
        });
    } catch (IOException e) {
        throw new DlabException("Can't parse json content: " + e.getLocalizedMessage(), e);
    }

    for (LibInstallDTO lib : list) {
        if (isSuccess) {
            lib.setStatus(LibStatus.INSTALLED.toString());
        } else {
            lib.setStatus(LibStatus.FAILED.toString());
            lib.setErrorMessage("Mock error message");
        }
    }

    try {
        return MAPPER.writeValueAsString(list);
    } catch (JsonProcessingException e) {
        throw new DlabException("Can't generate json content: " + e.getLocalizedMessage(), e);
    }
}

From source file:com.epam.dlab.backendapi.core.commands.CommandExecutorMockAsync.java

/**
 * Return the section of resource statuses for docker action status.
 *///from   w  w  w .  j ava2  s .  co m
private String getResponseStatus(boolean noUpdate) {
    if (noUpdate) {
        return "{}";
    }
    EnvResourceList resourceList;
    try {
        JsonNode json = MAPPER.readTree(parser.getJson());
        json = json.get("edge_list_resources");
        resourceList = MAPPER.readValue(json.toString(), EnvResourceList.class);
    } catch (IOException e) {
        throw new DlabException("Can't parse json content: " + e.getLocalizedMessage(), e);
    }

    if (resourceList.getHostList() != null) {
        for (EnvResource host : resourceList.getHostList()) {
            host.setStatus(UserInstanceStatus.RUNNING.toString());
        }
    }
    if (resourceList.getClusterList() != null) {
        for (EnvResource host : resourceList.getClusterList()) {
            host.setStatus(UserInstanceStatus.RUNNING.toString());
        }
    }

    try {
        return MAPPER.writeValueAsString(resourceList);
    } catch (JsonProcessingException e) {
        throw new DlabException("Can't generate json content: " + e.getLocalizedMessage(), e);
    }
}

From source file:hudson.scm.CvsTagsParamDefinition.java

@Exported
public ListBoxModel getSymbolicNames() {
    ListBoxModel model = new ListBoxModel();
    CvsChangeSet changeSet = null;//from w ww . ja v a 2  s  .  c  o m

    RlogCommand statusCommand = new RlogCommand();
    statusCommand.setHeaderOnly(true);
    statusCommand.setModule(moduleName);
    statusCommand.setRecursive(true);

    try {
        final File tempRlogSpill = File.createTempFile("cvs",
                "status );                                                                                                                                                                                                 `                                                                                                                                                                                                                                                                                                                                                                   ");
        final DeferredFileOutputStream outputStream = new DeferredFileOutputStream(100 * 1024, tempRlogSpill);
        final PrintStream logStream = new PrintStream(outputStream, true,
                getCvsDescriptor().getChangelogEncoding());

        final OutputStream errorOutputStream = new OutputStream() {
            final StringBuffer buffer = new StringBuffer();

            @Override
            public void write(int b) throws IOException {
                if ((int) ("\n".getBytes()[0]) == b) {
                    flush();
                } else {
                    buffer.append(new String(new byte[] { (byte) b }));
                }
            }

            @Override
            public void flush() throws IOException {
                logger.info(buffer.toString());
                buffer.delete(0, buffer.length());
                super.flush();
            }

            public void close() throws IOException {
                flush();
                super.close();
            }
        };
        final PrintStream errorPrintStream = new PrintStream(errorOutputStream);
        Client cvsClient = getCvsClient(cvsRoot, passwordRequired, password);
        cvsClient.getEventManager().addCVSListener(new BasicListener(logStream, errorPrintStream));
        cvsClient.executeCommand(statusCommand, getGlobalOptions(cvsRoot));

        logStream.close();
        errorPrintStream.flush();
        errorPrintStream.close();

        CvsLog parser = new CvsLog() {
            @Override
            public Reader read() throws IOException {
                if (outputStream.isInMemory())
                    return new InputStreamReader(new ByteArrayInputStream(outputStream.getData()),
                            getCvsDescriptor().getChangelogEncoding());
                else
                    return new InputStreamReader(new FileInputStream(outputStream.getFile()),
                            getCvsDescriptor().getChangelogEncoding());
            }

            @Override
            public void dispose() {
                tempRlogSpill.delete();
            }
        };

        changeSet = parser.mapCvsLog(cvsRoot, new CvsRepositoryLocation.HeadRepositoryLocation());

    } catch (IOException ex) {
        model.add(new ListBoxModel.Option("Could not load symbolic names - " + ex.getLocalizedMessage()));
        return model;
    } catch (CommandAbortedException ex) {
        model.add(new ListBoxModel.Option("Could not load symbolic names - " + ex.getLocalizedMessage()));
        return model;
    } catch (CommandException ex) {
        model.add(new ListBoxModel.Option("Could not load symbolic names - " + ex.getLocalizedMessage()));
        return model;
    } catch (AuthenticationException ex) {
        model.add(new ListBoxModel.Option("Could not load symbolic names - " + ex.getLocalizedMessage()));
        return model;
    }

    model.add(new ListBoxModel.Option("Head", "HEAD"));

    for (String branchName : changeSet.getBranchNames()) {
        model.add(new ListBoxModel.Option(branchName + " (Branch)", branchName));
    }

    for (String tagName : changeSet.getTagNames()) {
        model.add(new ListBoxModel.Option(tagName + " (Tag)", tagName));
    }

    return model;
}

From source file:com.neovisionaries.security.DigestTest.java

private void doJsonTest(String json1, String json2, Digest digest1, Digest digest2, boolean equals) {
    if (digest1 == null) {
        digest1 = sha1();/*from   w  ww  .  j  a va 2  s. c o  m*/
    }

    if (digest2 == null) {
        digest2 = sha1();
    }

    try {
        String result1 = digest1.updateJson(json1).digestAsString();
        String result2 = digest2.updateJson(json2).digestAsString();

        if (equals) {
            assertEquals(result1, result2);
        } else {
            assertThat(result1, not(result2));
        }
    } catch (IOException e) {
        fail(e.getLocalizedMessage());
    }
}

From source file:com.kylinolap.rest.controller.CubeController.java

/**
 * Force rebuild a cube's lookup table snapshot
 * /*w  w w  . j a v  a 2  s . c  o  m*/
 * @throws IOException
 */
@RequestMapping(value = "/{cubeName}/segs/{segmentName}/refresh_lookup", method = { RequestMethod.PUT })
@ResponseBody
public CubeInstance rebuildLookupSnapshot(@PathVariable String cubeName, @PathVariable String segmentName,
        @RequestParam(value = "lookupTable") String lookupTable) {
    try {
        return cubeService.rebuildLookupSnapshot(cubeName, segmentName, lookupTable);
    } catch (IOException e) {
        logger.error(e.getLocalizedMessage(), e);
        throw new InternalErrorException(e.getLocalizedMessage());
    }
}

From source file:it.geosolutions.geoservertester.GeoServerTester.java

private void notMatch(Location l, FeatureCollection<SimpleFeatureType, SimpleFeature> features, String fname) {
    String path = conf.getString(OUTPUT_FOLDER_NAME);
    String prefix = conf.getString(PREFIX_NAME);
    File f;/* w  w w.j  a v  a2s  . c  o  m*/
    BufferedWriter writer = null;
    try {
        f = new File(path, prefix + fname);

        writer = new BufferedWriter(new FileWriter(f, this.getMode(f)));
        writer.write("\n[name = " + l.getName() + " parent = " + l.getParent().getName() + " type="
                + l.getType().ordinal() + "]");
        writer.write("FOUND:" + features.size());

    } catch (IOException e) {
        LOG.severe(e.getMessage());
    } finally {
        try {
            if (writer != null) {
                writer.close();
            }
        } catch (Exception e) {
            LOG.log(Level.FINE, e.getLocalizedMessage(), e);
        }

    }

}

From source file:com.jaspersoft.jasperserver.rest.services.RESTReport.java

/**
 * This method allows the user to create (run/fill) a new report.
 * /*from   w  w w.  j  ava  2  s .  c  o m*/
 *
 * @param req
 * @param resp
 * @throws ServiceException
 */
@Override
protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws ServiceException {

    // We are creating a new report here...
    // Add all the options...
    Map<String, String> options = new HashMap<String, String>();
    // Add as option all the GET parameters...
    Enumeration en = req.getParameterNames();
    while (en.hasMoreElements()) {
        String key = (String) en.nextElement();
        options.put(key, req.getParameter(key));
    }

    Map<String, Object> parameters = new HashMap<String, Object>();

    // We expect the user to send us a ResourceDescriptor with some parameters in it...
    HttpServletRequest mreq = restUtils.extractAttachments(runReportService, req);

    String resourceDescriptorXml = null;

    // get the resource descriptor...
    if (mreq instanceof MultipartHttpServletRequest) {
        resourceDescriptorXml = mreq.getParameter(restUtils.REQUEST_PARAMENTER_RD);
    } else {
        try {
            resourceDescriptorXml = IOUtils.toString(req.getInputStream());
        } catch (IOException ex) {
            throw new ServiceException(ServiceException.INTERNAL_SERVER_ERROR, ex.getLocalizedMessage());
        }
    }

    if (resourceDescriptorXml == null) {
        restUtils.setStatusAndBody(HttpServletResponse.SC_BAD_REQUEST, resp, "Missing parameter "
                + restUtils.REQUEST_PARAMENTER_RD + " " + runReportService.getInputAttachments());
        return;
    }

    // Parse the resource descriptor...
    InputSource is = new InputSource(new StringReader(resourceDescriptorXml));
    Document doc = null;
    ResourceDescriptor rd = null;
    try {
        doc = XMLUtil.getNewDocumentBuilder().parse(is);
        rd = Unmarshaller.readResourceDescriptor(doc.getDocumentElement());
    } catch (SAXException ex) {
        restUtils.setStatusAndBody(HttpServletResponse.SC_BAD_REQUEST, resp, "Invalid resource descriptor");
        return;
    } catch (ServiceException se) {

        if (se.getErrorCode() == ServiceException.RESOURCE_NOT_FOUND) {
            restUtils.setStatusAndBody(HttpServletResponse.SC_NOT_FOUND, resp, se.getLocalizedMessage());
            throw new ServiceException(HttpServletResponse.SC_NOT_FOUND, se.getMessage());
        } else {
            throw se;
        }
    } catch (Exception ex) {
        throw new ServiceException(ServiceException.INTERNAL_SERVER_ERROR, ex.getLocalizedMessage());
    }

    // At this point we have a resource descriptor, find the parameters in it and the uri
    String uri = rd.getUriString();

    List params = rd.getParameters();
    for (int i = 0; i < params.size(); ++i) {
        ListItem parameter = (ListItem) params.get(i);
        if (parameter.isIsListItem()) {
            // Check if a collection exists for this parameter..
            List collection = (List) parameters.get(parameter.getLabel());
            if (collection == null) {
                collection = new ArrayList<String>();
                parameters.put(parameter.getLabel(), collection);
            }
            collection.add(parameter.getValue());
        } else {
            parameters.put(parameter.getLabel(), parameter.getValue());
        }
    }

    if (log.isDebugEnabled())
        log.debug("Running report " + uri + " with parameters: " + parameters + " and options: " + options);

    // highcharts report for REST v1 is by default noninteractive.
    if (!options.containsKey(Argument.PARAM_INTERACTIVE)) {
        options.put(Argument.PARAM_INTERACTIVE, Boolean.FALSE.toString());
    }
    Map<String, DataSource> attachments = new ConcurrentHashMap<String, DataSource>();

    OperationResult or = runReportService.runReport(uri, parameters, options, attachments);

    if (or.getReturnCode() != 0) {
        restUtils.setStatusAndBody(HttpServletResponse.SC_BAD_REQUEST, resp, or.getMessage());
        return;
    } else {
        JasperPrint jp = (JasperPrint) runReportService.getAttributes().get("jasperPrint");

        // Store the attachments in the session, with proper keys...

        HttpSession session = req.getSession();

        String executionId = UUID.randomUUID().toString();

        Report report = new Report();

        report.setUuid(executionId);
        report.setOriginalUri(uri);
        report.setAttachments(attachments);
        report.setJasperPrint(jp);

        session.setAttribute(report.getUuid(), report);

        // Send out the xml...
        resp.setContentType("text/xml; charset=UTF-8");
        restUtils.setStatusAndBody(HttpServletResponse.SC_CREATED, resp, report.toXml());
    }
}

From source file:jfs.sync.encryption.JFSEncryptedFile.java

/**
 * @see JFSFile#getInputStream()//from   ww w.j  a  va 2s .  c  om
 */
@Override
protected InputStream getInputStream() {
    try {
        InputStream stream = fileProducer.getInputStream(getRelativePath());
        return JFSEncryptedStream.createInputStream(stream, getLength(), getCipher(Cipher.DECRYPT_MODE));
    } catch (IOException ioe) {
        log.error("getInputStream() I/O Exception " + ioe.getLocalizedMessage());
        return null;
    } // try/catch
}