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:it.geosolutions.geobatch.actions.freemarker.FreeMarkerAction.java

private final File buildOutput(final File outputDir, final Map<String, Object> root) throws ActionException {
    // try to open the file to write into
    FileWriter fw = null;//from   w w  w.  j a va2  s.  c  o  m
    final File outputFile;
    try {
        final String outputFilePrefix = FilenameUtils.getBaseName(conf.getInput()) + "_";
        final String outputFileSuffix = "." + FilenameUtils.getExtension(conf.getInput());
        outputFile = File.createTempFile(outputFilePrefix, outputFileSuffix, outputDir);
        if (LOGGER.isInfoEnabled())
            LOGGER.info("Output file name: " + outputFile);
        fw = new FileWriter(outputFile);
    } catch (IOException ioe) {
        IOUtils.closeQuietly(fw);
        final String message = "Unable to build the output file writer: " + ioe.getLocalizedMessage();
        if (LOGGER.isErrorEnabled())
            LOGGER.error(message);
        throw new ActionException(this, message);
    }

    /*
     * If available, process the output file using the TemplateModel data
     * structure
     */
    try {
        // process the input template file
        processor.process(processor.wrapRoot(root), fw);

        // flush the buffer
        if (fw != null)
            fw.flush();

    } catch (IOException ioe) {
        throw new ActionException(this,
                "Unable to flush buffer to the output file: " + ioe.getLocalizedMessage(), ioe.getCause());
    } catch (TemplateModelException tme) {
        throw new ActionException(this, "Unable to wrap the passed object: " + tme.getLocalizedMessage(),
                tme.getCause());
    } catch (Exception e) {
        throw new ActionException(this, "Unable to process the input file: " + e.getLocalizedMessage(),
                e.getCause());
    } finally {
        IOUtils.closeQuietly(fw);
    }
    return outputFile;
}

From source file:com.bayontechnologies.bi.pentaho.plugin.openflashchart.OpenFlashChartComponent.java

protected boolean executeAction() {
    //get the input datas
    IPentahoResultSet data = (IPentahoResultSet) getInputValue(CHART_DATA_PROP);
    String chartTemplateString = getInputStringValue(CHART_TEMPLATE_STRING);
    Integer chartWidth = null;/*w w w . j av  a 2 s .  c  o  m*/
    IPentahoSession userSession = this.getSession();
    String input1 = getInputStringValue(CHART_WIDTH);
    if (null == input1) {
        chartWidth = new Integer(this.width);
    } else {
        chartWidth = Integer.valueOf(input1);
    }

    Integer chartHeight = null;
    String input2 = getInputStringValue(CHART_HEIGHT);
    if (null == input2) {
        chartHeight = new Integer(this.height);
    } else {
        chartHeight = Integer.valueOf(input2);
    }

    IActionResource fileResource = null;
    String ofcURL = getInputStringValue(OFC_URL);
    if (ofcURL == null || "".equals(ofcURL)) {
        ofcURL = "/pentaho-style/images/open-flash-chart.swf";
    }

    if (chartTemplateString == null || chartTemplateString.equals("")) {
        fileResource = this.getResource(CHART_TEMPLATE);
        try {

            chartTemplateString = PentahoSystem.getSolutionRepository(userSession)
                    .getResourceAsString(fileResource);

        } catch (IOException e) {
            error(e.getLocalizedMessage());
            return false;
        }
    }
    //parse the chart Template String and get the parsed tokens
    map = parseString(chartTemplateString);
    chartTemplateString = replaceChartDefParams(chartTemplateString, data);

    //replace the custom variables
    ArrayList<String> customs = map.get("customs");
    Set inputNames = this.getInputNames();
    for (Iterator iterator = inputNames.iterator(); iterator.hasNext();) {
        String name = (String) iterator.next();
        if (customs.contains(name)) {
            Object value = this.getInputValue(name);
            chartTemplateString = replaceLongStr(chartTemplateString, "{" + name + "}", "" + value);
        }
    }

    log.debug("chartTemplateString after replacing:" + chartTemplateString);

    String solutionName = this.getSolutionName();
    //uuid 
    String uuid = "openFlashChart-" + UUIDUtil.getUUIDAsString();

    IContentRepository repository = ContentRepository.getInstance(userSession);
    IContentLocation cl = null;
    cl = repository.getContentLocationByPath(LOCATION_DIR_PATH);
    if (cl == null)
        cl = repository.newContentLocation(LOCATION_DIR_PATH, solutionName, solutionName, this.getId(), true);
    //Fix me, to create a new contentitem every time is not a good choice.
    //Maybe we can remove the older and create a new one. But I can't find the solution right now. :( 
    IContentItem citem = cl.newContentItem(uuid, uuid, this.getActionTitle(), "txt", "text/plain", "",
            IContentItem.WRITEMODE_OVERWRITE);

    try {
        //get the  outputstream and write the content into the repository.
        OutputStream os = citem.getOutputStream(this.getActionName());
        os.write(chartTemplateString.getBytes(LocaleHelper.getSystemEncoding()));
        os.close();
    } catch (IOException e) {
        error(e.getLocalizedMessage());
        return false;
    }
    //replace the parameters in the flashFragment
    String flashContent = replace(flashFragment, citem.getId(), chartWidth, chartHeight, ofcURL);

    log.debug("html_fragment=" + flashContent);
    Set outputNames = this.getOutputNames();
    if (outputNames.contains("html_fragment")) {
        this.setOutputValue("html_fragment", flashContent);
    }
    if (outputNames.contains("content_url")) {
        this.setOutputValue("content_url", this.getTmpContentURL(citem.getId()));
    }

    return true;
}

From source file:com.nextgis.mobile.map.MapBase.java

/**
 * Load map properties and layers from map.json file
 *//* w  w  w.j  a v  a2  s.  c  om*/
protected synchronized void loadMap() {
    Log.d(TAG, "load map");
    File config_file = new File(mMapPath, MAP_CONFIG);
    try {
        String sData = FileUtil.readFromFile(config_file);
        JSONObject rootObject = new JSONObject(sData);
        mName = rootObject.getString(JSON_NAME_KEY);
        final JSONArray jsonArray = rootObject.getJSONArray(JSON_LAYERS_KEY);
        for (int i = 0; i < jsonArray.length(); i++) {
            JSONObject jsonLayer = jsonArray.getJSONObject(i);
            String sPath = jsonLayer.getString(JSON_PATH_KEY);
            File inFile = new File(mMapPath, sPath);
            if (inFile.exists())
                addLayer(inFile);
        }
        //let's draw the map
        runDrawThread();
    } catch (IOException e) {
        reportError(e.getLocalizedMessage());
    } catch (JSONException e) {
        reportError(e.getLocalizedMessage());
    }

    //load map without the order of layers
    /*File[] files = mMapPath.listFiles();
    for (File inFile : files) {
    if (inFile.isDirectory() && inFile.toString().startsWith(LAYER_PREFIX)) {
        addLayer(inFile);
    }
    }*/
}

From source file:com.nextgis.mobile.map.MapBase.java

/**
 * Create existed layer from path and add it to the map
 *
 * @param path A path to layer directory
 *//* www. ja  va 2s  .  com*/
protected void addLayer(File path) {
    File config_file = new File(path, LAYER_CONFIG);
    try {
        String sData = FileUtil.readFromFile(config_file);
        JSONObject rootObject = new JSONObject(sData);
        int nType = rootObject.getInt(JSON_TYPE_KEY);
        Layer layer = null;
        switch (nType) {
        case LAYERTYPE_LOCAL_TMS:
            layer = new LocalTMSLayer(this, path, rootObject);
            break;
        case LAYERTYPE_LOCAL_GEOJSON:
            layer = new LocalGeoJsonLayer(this, path, rootObject);
            break;
        case LAYERTYPE_LOCAL_RASTER:
            break;
        case LAYERTYPE_TMS:
            layer = new RemoteTMSLayer(this, path, rootObject);
            break;
        case LAYERTYPE_NGW:
            break;
        }

        if (layer != null) {
            mLayers.add(layer);
            saveMap();
            onLayerAdded(layer);
        }
    } catch (IOException e) {
        reportError(e.getLocalizedMessage());
    } catch (JSONException e) {
        reportError(e.getLocalizedMessage());
    }
}

From source file:gui.sqlmap.SqlmapUi.java

private void startSqlmap() {
    String python = textfieldPython.getText();
    String workingDir = textfieldWorkingdir.getText();
    String sqlmap = textfieldSqlmap.getText();

    // Do some basic tests
    File f;/*  w  w w  .  j av a  2s  .  c o m*/
    f = new File(python);
    if (!f.exists()) {
        JOptionPane.showMessageDialog(this, "Python path does not exist: " + python);
        return;
    }
    f = new File(workingDir);
    if (!f.exists()) {
        JOptionPane.showMessageDialog(this, "workingDir path does not exist: " + workingDir);
        return;
    }
    f = new File(sqlmap);
    if (!f.exists()) {
        JOptionPane.showMessageDialog(this, "sqlmap path does not exist: " + sqlmap);
        return;
    }

    // Write request file
    String requestFile = workingDir + "request.txt";
    try {
        FileOutputStream fos = new FileOutputStream(requestFile);
        fos.write(httpMessage.getRequest());
        fos.close();
    } catch (IOException e) {
        JOptionPane.showMessageDialog(this, "could not write request: " + workingDir + "request.txt");
        BurpCallbacks.getInstance().print("Error: " + e.getMessage());
    }

    // Start sqlmap
    args = new ArrayList<String>();
    args.add(python);
    args.add(sqlmap);
    args.add("-r");
    args.add(requestFile);
    args.add("--batch");

    args.add("-p");
    args.add(attackParam.getName());

    String sessionFile = workingDir + "sessionlog.txt";
    args.add("-s");
    args.add(sessionFile);
    args.add("--flush-session");

    String traceFile = workingDir + "tracelog.txt";
    args.add("-t");
    args.add(traceFile);

    args.add("--disable-coloring");
    args.add("--cleanup");

    textareaCommand.setText(StringUtils.join(args, " "));

    SwingWorker worker = new SwingWorker<String, Void>() {
        @Override
        public String doInBackground() {
            ProcessBuilder pb = new ProcessBuilder(args);
            //BurpCallbacks.getInstance().print(pb.command().toString());
            pb.redirectErrorStream(true);
            Process proc;
            try {
                proc = pb.start();

                InputStream is = proc.getInputStream();
                InputStreamReader isr = new InputStreamReader(is);
                BufferedReader br = new BufferedReader(isr);

                String line;
                int exit = -1;

                while ((line = br.readLine()) != null) {
                    // Outputs your process execution
                    addLine(line);
                    try {
                        exit = proc.exitValue();
                        if (exit == 0) {
                            // Process finished
                        }
                    } catch (IllegalThreadStateException t) {
                        // The process has not yet finished. 
                        // Should we stop it?
                        //if (processMustStop()) // processMustStop can return true 
                        // after time out, for example.
                        //{
                        //    proc.destroy();
                        //}
                    }
                }
            } catch (IOException ex) {
                BurpCallbacks.getInstance().print(ex.getLocalizedMessage());
            }
            return "";
        }

        @Override
        public void done() {
        }
    };

    worker.execute();

}

From source file:de.knowwe.diaflux.utils.DOTImporter.java

/**
 * Read a dot formatted input and populate the provided graph.
 * <p>//from  w w w  .j  av a2  s .c  om
 * The current implementation reads the whole input as a string and then parses the graph.
 *
 * @param graph the graph to update
 * @param input the input reader
 * @throws ImportException if there is a problem parsing the file.
 */
@Override
public void importGraph(Graph<V, E> graph, Reader input) throws ImportException {
    try {
        this.input = IOUtils.toString(input);
    } catch (IOException e) {
        throw new ImportException("IOException: " + e.getLocalizedMessage());
    }
    this.graph = graph;
    vertexes = new HashMap<>();
    position = 0;
    sectionBuffer = new StringBuilder();
    read();
}

From source file:com.googlecode.jgenhtml.JGenHtmlTest.java

private void runJgenhtml() {
    try {/*  w w  w  .  j a  v a 2 s  . co  m*/
        File outputDir = JGenHtmlTestUtils.getTestDir();
        FileUtils.cleanDirectory(outputDir);//START WITH A CLEAN DIRECTORY!
        jstdTestDir = new File(outputDir, "jstd");
        cCodeTestDir = new File(outputDir, "code");
        baselinedTestDir = new File(outputDir, "baselined");
        noSourceTestDir = new File(outputDir, "nosource");
        String[] argv = new String[] { "-o", jstdTestDir.getAbsolutePath(),
                JGenHtmlTestUtils.getJstdTraceFiles(false, false)[0] };
        JGenHtml.main(argv);
        argv = new String[] { "-o", cCodeTestDir.getAbsolutePath(),
                JGenHtmlTestUtils.getTraceFilesWithBranchAndFuncData()[0] };
        JGenHtml.main(argv);
        argv = new String[] { "-o", baselinedTestDir.getAbsolutePath(), "-b",
                JGenHtmlTestUtils.getBaselineFile(),
                JGenHtmlTestUtils.getTraceFilesWithBranchAndFuncData()[0] };
        JGenHtml.main(argv);
        argv = new String[] { "-o", noSourceTestDir.getAbsolutePath(), "--no-source",
                JGenHtmlTestUtils.getTraceFilesWithBranchAndFuncData()[0] };
        JGenHtml.main(argv);
    } catch (IOException ex) {
        fail(ex.getLocalizedMessage());
    }
}

From source file:com.qumasoft.qvcslib.CompareFilesWithApacheDiff.java

private void formatEditScript(Delta delta, DataOutputStream outStream, CompareLineInfo[] fileA)
        throws QVCSOperationException {
    try {//from   ww w .j a v  a2s.  c  o  m
        short editType;
        int seekPosition = -1;
        int deletedByteCount = 0;
        int insertedByteCount = 0;
        byte[] secondFileByteBuffer = null;
        if (delta instanceof ChangeDelta) {
            CompareLineInfo originalStartingLine = fileA[delta.getOriginal().anchor()];
            seekPosition = originalStartingLine.getLineSeekPosition();
            editType = CompareFilesEditInformation.QVCS_EDIT_REPLACE;
            deletedByteCount = computeDeletedByteCount(delta);
            insertedByteCount = computeInsertedByteCount(delta);
            secondFileByteBuffer = computeSecondFileByteBufferForInsert(delta, insertedByteCount);
        } else if (delta instanceof AddDelta) {
            int anchor = delta.getOriginal().anchor();
            if (anchor == 0) {
                CompareLineInfo originalStartingLine = fileA[delta.getOriginal().anchor()];
                seekPosition = originalStartingLine.getLineSeekPosition();
            } else {
                CompareLineInfo originalStartingLine = fileA[delta.getOriginal().anchor() - 1];
                byte[] lineAsByteArray = originalStartingLine.getLineString().getBytes(UTF8);
                seekPosition = originalStartingLine.getLineSeekPosition() + lineAsByteArray.length;
            }
            editType = CompareFilesEditInformation.QVCS_EDIT_INSERT;
            insertedByteCount = computeInsertedByteCount(delta);
            AddDelta insertDelta = (AddDelta) delta;
            secondFileByteBuffer = computeSecondFileByteBufferForInsert(insertDelta, insertedByteCount);
        } else if (delta instanceof DeleteDelta) {
            CompareLineInfo originalStartingLine = fileA[delta.getOriginal().anchor()];
            seekPosition = originalStartingLine.getLineSeekPosition();
            editType = CompareFilesEditInformation.QVCS_EDIT_DELETE;
            deletedByteCount = computeDeletedByteCount(delta);
        } else {
            throw new QVCSOperationException("Internal error -- invalid edit type");
        }
        CompareFilesEditInformation editInfo = new CompareFilesEditInformation(editType, seekPosition,
                deletedByteCount, insertedByteCount);

        switch (editType) {
        case CompareFilesEditInformation.QVCS_EDIT_DELETE:
            editInfo.write(outStream);
            break;
        case CompareFilesEditInformation.QVCS_EDIT_INSERT:
        case CompareFilesEditInformation.QVCS_EDIT_REPLACE:
            editInfo.write(outStream);
            outStream.write(secondFileByteBuffer, 0, insertedByteCount);
            break;
        default:
            throw new QVCSOperationException("Internal error -- invalid edit type");
        }
    } catch (IOException e) {
        throw new QVCSOperationException("IOException in formatEditScript() " + e.getLocalizedMessage());
    }
}

From source file:com.app.model.m3.M3UpgradModel.java

public void save(String path) {
    XMLManage xml = new XMLManage("m3upgrade", "envs");
    ArrayList<String> env = new ArrayList<>();
    env.add("" + this.listEntity.get(0).getEntity().getModelEntity().getIdLink());
    env.add("" + this.listEntity.get(0).getEntity().getModelEntity().getId());
    env.add("" + this.listEntity.get(1).getEntity().getModelEntity().getId());
    xml.add(new ArrayList(Arrays.asList(new String[] { "customer", "envsrc", "envtarg" })), env);

    //        for (int i = 0; i < configm3.getListConfig().size(); i++) {
    //            ArrayList<String> a = new ArrayList<>();
    //            a.add(configm3.getListConfig().get(i));
    //            a.add(configm3.getListConfig().get(i).equals(configm3.getConfigSelect()) ? "1" : "0");
    //            a.add(configm3.getListUnderConfig().contains(configm3.getListConfig().get(i)) ? "1" : "0");
    //            a.add(configm3.getListUnderConfigSelect().contains(configm3.getListConfig().get(i)) ? "1" : "0");
    //            xml.add("Config", new ArrayList(Arrays.asList(new String[]{"configId", "selected", "under", "underselected"})), a);
    //        }/*from   www. ja v  a  2s.  c  o m*/
    //        
    for (String s : configm3.getListConfig().keySet()) {
        ArrayList<String> a = new ArrayList<>();
        a.add(s);
        a.add(configm3.getListConfig().get(s).getDescription());
        a.add(s.equals(configm3.getConfigSelect()) ? "1" : "0");
        a.add(configm3.getListUnderConfig().containsKey(s) ? "1" : "0");
        a.add(configm3.getListUnderConfigSelect().containsKey(s) ? "1" : "0");
        xml.add("Config", new ArrayList(Arrays
                .asList(new String[] { "configId", "description", "selected", "under", "underselected" })), a);
    }

    ArrayList<String> a = new ArrayList<>();
    a.add(actionNumber.getActionNumberSelect());
    xml.add("ActionNumber", new ArrayList(Arrays.asList(new String[] { "actionumberId" })), a);

    for (int j = 0; j < m3user.getListUser().size(); j++) {
        a = new ArrayList<>();
        a.add(m3user.getListUser().get(j));
        a.add(m3user.getListUserSelect().contains(m3user.getListUser().get(j)) ? "1" : "0");
        xml.add("User", new ArrayList(Arrays.asList(new String[] { "userId", "userselected" })), a);
    }

    String[] headerLng = new String[M3UpdObjModel.header.length];
    for (int k = 0; k < M3UpdObjModel.header.length; k++) {
        headerLng[k] = i18n.Language.getLabel(M3UpdObjModel.header[k], "EN");
    }

    if (data != null) {
        for (Object[] data1 : data) {
            xml.add("Data", "Id", new ArrayList(Arrays.asList(headerLng)), new ArrayList(Arrays.asList(data1)));
        }
    }

    try {
        xml.save(path);
    } catch (IOException ex) {
        Ressource.logger.error(ex.getLocalizedMessage(), ex);
    }
}

From source file:net.agkn.field_stripe.record.reader.SmartJsonArrayRecordReader.java

@Override
public final boolean hasMoreRecords() throws IllegalStateException, InvalidDataException {
    if (isClosed)
        throw new IllegalStateException("The record reader has already been closed.")/*by contract*/;
    if (!stack.isEmpty())
        throw new IllegalStateException(
                "A record has already been started in the record reader.")/*by contract*/;

    // since this cannot be called within a record (see stack check above)
    // then a non-null 'rawRecord' indicates that this method was already
    // called and there was another record read.
    if (rawRecord != null)
        return true/*by definition*/;

    // read the next record. If there is a non-null result then there is a record
    try {//from ww w  .j ava2 s .com
        rawRecord = reader.readLine();
        return (rawRecord != null);
    } catch (final IOException ioe) {
        throw new InvalidDataException(ioe.getLocalizedMessage());
    }
}