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:com.thinkbiganalytics.nifi.v2.ingest.StripHeader.java

@Override
public void onTrigger(final ProcessContext context, final ProcessSession session) {
    final StripHeaderSupport headerSupport = new StripHeaderSupport();
    final FlowFile flowFile = session.get();
    if (flowFile == null) {
        return;//from   ww w.j a  va2s  .co  m
    }

    final boolean isEnabled = context.getProperty(ENABLED).evaluateAttributeExpressions(flowFile).asBoolean();
    final int headerCount = context.getProperty(HEADER_LINE_COUNT).evaluateAttributeExpressions(flowFile)
            .asInteger();

    // Empty files and no work to do will simply pass along content
    if (!isEnabled || headerCount == 0 || flowFile.getSize() == 0L) {
        final FlowFile contentFlowFile = session.clone(flowFile);
        session.transfer(contentFlowFile, REL_CONTENT);
        session.transfer(flowFile, REL_ORIGINAL);
        return;
    }

    final MutableLong headerBoundaryInBytes = new MutableLong(-1);

    session.read(flowFile, false, rawIn -> {
        try {
            // Identify the byte boundary of the header
            long bytes = headerSupport.findHeaderBoundary(headerCount, rawIn);
            headerBoundaryInBytes.setValue(bytes);

            if (bytes < 0) {
                getLog().error("Unable to strip header {} expecting at least {} lines in file",
                        new Object[] { flowFile, headerCount });
            }

        } catch (IOException e) {
            getLog().error("Unable to strip header {} due to {}; routing to failure",
                    new Object[] { flowFile, e.getLocalizedMessage() }, e);
        }

    });

    long headerBytes = headerBoundaryInBytes.getValue();
    if (headerBytes < 0) {
        session.transfer(flowFile, REL_FAILURE);
    } else {
        // Transfer header
        final FlowFile headerFlowFile = session.clone(flowFile, 0, headerBytes);
        session.transfer(headerFlowFile, REL_HEADER);

        // Transfer content
        long contentBytes = flowFile.getSize() - headerBytes;
        final FlowFile contentFlowFile = session.clone(flowFile, headerBytes, contentBytes);
        session.transfer(contentFlowFile, REL_CONTENT);

        session.transfer(flowFile, REL_ORIGINAL);
    }
}

From source file:com.photon.maven.plugins.android.standalonemojos.UpdateBuildInfoMojo.java

@Override
public void execute() throws MojoExecutionException, MojoFailureException {

    try {/*from   w ww  . j a  v a2s .  c  om*/
        buildInfoList = new ArrayList<BuildInfo>(); // initialization
        //         srcDir = new File(baseDir.getPath() + File.separator + sourceDirectory);
        buildDir = new File(baseDir.getPath() + buildDirectory);
        if (!buildDir.exists()) {
            buildDir.mkdir();
            getLog().info("Build directory created..." + buildDir.getPath());
        }
        buildInfoFile = new File(buildDir.getPath() + "/build.info");

        nextBuildNo = generateNextBuildNo();

        currentDate = Calendar.getInstance().getTime();
    } catch (IOException e) {
        throw new MojoFailureException("APK could not initialize " + e.getLocalizedMessage());
    }

    // Initialize apk build configuration
    File outputFile = new File(project.getBuild().getDirectory(),
            project.getBuild().getFinalName() + '.' + APK);

    if (outputFile.exists()) {

        try {
            getLog().info("APK created.. Copying to Build directory.....");
            String buildName = project.getBuild().getFinalName() + '_' + getTimeStampForBuildName(currentDate);
            File destFile = new File(buildDir, buildName + '.' + APK);
            FileUtils.copyFile(outputFile, destFile);
            getLog().info("copied to..." + destFile.getName());
            apkFileName = destFile.getName();

            getLog().info("Creating deliverables.....");
            ZipArchiver zipArchiver = new ZipArchiver();
            File inputFile = new File(apkFileName);
            zipArchiver.addFile(destFile, destFile.getName());
            File deliverableZip = new File(buildDir, buildName + ".zip");
            zipArchiver.setDestFile(deliverableZip);
            zipArchiver.createArchive();

            deliverable = deliverableZip.getName();
            getLog().info("Deliverables available at " + deliverableZip.getName());
            writeBuildInfo(true);
        } catch (IOException e) {
            throw new MojoExecutionException("Error in writing output...");
        }

    }
}

From source file:com.anrisoftware.sscontrol.scripts.locale.ubuntu_12_04.Ubuntu_12_04_InstallLocaleLogger.java

ScriptException errorLoadLocales(Ubuntu_12_04_InstallLocale installLocale, IOException e, File file) {
    return logException(
            new ScriptException(error_load_locales, e).add(the_locale, installLocale).add(the_file, file),
            error_load_locales_message, file, e.getLocalizedMessage());
}

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

@Override
public Bitmap getBitmap(TileItem tile) {
    // try to get tile from local cache
    File tilePath = new File(mPath, tile.toString("{z}/{x}/{y}.tile"));
    if (tilePath.exists()
            && System.currentTimeMillis() - tilePath.lastModified() < DEFAULT_MAXIMUM_CACHED_FILE_AGE) {
        return BitmapFactory.decodeFile(tilePath.getAbsolutePath());
    }/*from   ww w  .ja  va2  s .  co  m*/

    if (!mMap.isNetworkAvaliable())
        return null;
    // try to get tile from remote
    try {

        final HttpUriRequest head = new HttpGet(tile.toString(mURL));
        final HttpResponse response;
        response = mHTTPClient.execute(head);

        // Check to see if we got success
        final org.apache.http.StatusLine line = response.getStatusLine();
        if (line.getStatusCode() != 200) {
            Log.w(TAG, "Problem downloading MapTile: " + tile.toString(mURL) + " HTTP response: " + line);
            return null;
        }

        final HttpEntity entity = response.getEntity();
        if (entity == null) {
            Log.w(TAG, "No content downloading MapTile: " + tile.toString(mURL));
            return null;
        }

        FileUtil.createDir(tilePath.getParentFile());

        InputStream input = entity.getContent();
        OutputStream output = new FileOutputStream(tilePath.getAbsolutePath());
        byte data[] = new byte[IO_BUFFER_SIZE];

        FileUtil.copyStream(input, output, data, IO_BUFFER_SIZE);

        output.close();
        input.close();
        return BitmapFactory.decodeFile(tilePath.getAbsolutePath());

    } catch (IOException e) {
        Log.w(TAG, e.getLocalizedMessage());
    }
    return null;
}

From source file:com.anrisoftware.sscontrol.scripts.locale.ubuntu_12_04.Ubuntu_12_04_InstallLocaleLogger.java

ScriptException errorAttachLocale(Ubuntu_12_04_InstallLocale installLocale, IOException e, File file) {
    return logException(
            new ScriptException(error_attach_locale, e).add(the_locale, installLocale).add(the_file, file),
            error_attach_locale_message, file, e.getLocalizedMessage());
}

From source file:fr.fastconnect.factory.tibco.bw.maven.compile.CompileEARMojo.java

public void execute() throws MojoExecutionException {
    if (skipCompile || skipEARCompile) {
        getLog().info(SKIPPING);//  w  w w . j  a v  a2s .co m

        File outputFile = getOutputFile();
        if (outputFile != null && !outputFile.exists() && touchEARIfSkipped) {
            // EAR was not created because compilation is skipped
            // however we "touch" the EAR file so there is an empty EAR file created
            try {
                outputFile.getParentFile().mkdirs();
                outputFile.createNewFile();
            } catch (IOException e) {
                throw new MojoExecutionException(e.getLocalizedMessage(), e);
            }
        }
        if (outputFile != null && outputFile.exists()) {
            attachArtifact(outputFile);
        } else {
            getLog().warn(WARN_NO_ARTIFACT_ATTACHED);
        }
        return;
    }

    if (isCurrentGoal("bw:launch-designer")) {
        return; // ignore
    }

    doCleanDefaultVars();

    super.execute();
    checkOutputDirectory();
    File outputFile = getOutputFile();
    getLog().debug(EAR_LOCATION + outputFile.getAbsolutePath());

    try {
        buildEAR(outputFile);
    } catch (IOException e) {
        throw new MojoExecutionException(BUILD_EAR_FAILED, e);
    }

    try {
        if (!packageDirectory.exists()) {
            packageDirectory.mkdirs();
        }
        FileUtils.copyFile(outputFile, new File(packageDirectory + File.separator + outputFile.getName()));
    } catch (IOException e) {
        throw new MojoExecutionException(COPY_EAR_FAILED, e);
    }

    attachArtifact(outputFile);
}

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

protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServiceException {
    try {//from ww w  .ja v  a  2 s  .c  om
        String userName = restUtils.extractResourceName(req.getPathInfo());

        WSUser user = restUtils.unmarshal(WSUser.class, req.getInputStream());
        if (isUserNameValid(userName, user))
            this.updateUser(user);
        else {
            throw new ServiceException(HttpServletResponse.SC_BAD_REQUEST, "check your request parameters");
        }
        restUtils.setStatusAndBody(HttpServletResponse.SC_OK, resp, "");
    } catch (AxisFault axisFault) {
        throw new ServiceException(axisFault.getLocalizedMessage());
    } catch (IOException e) {
        throw new ServiceException(e.getLocalizedMessage());
    } catch (JAXBException e) {
        throw new ServiceException(HttpServletResponse.SC_BAD_REQUEST, "could not marshal the user descriptor");
    }
}

From source file:net.osten.watermap.convert.AZTReport.java

/**
 * Converts the AT PDF datafile to water reports.
 *
 * @return set of water reports//ww  w .  j  a  va 2s . c  o  m
 */
public Set<WaterReport> convert() {
    Set<WaterReport> results = new HashSet<WaterReport>();

    boolean inData = false;
    int lineNumber = 1;

    try {
        ImmutableList<String> lines = filePath != null
                ? Files.asCharSource(new File(filePath), Charsets.UTF_8).readLines()
                : Resources.asCharSource(fileURL, Charsets.UTF_8).readLines();
        log.fine("found " + lines.size() + " lines");

        for (String line : lines) {

            // find start of data line section
            if (RegexUtils.matchFirstOccurance(line, dataLinePattern) != null) {
                WaterReport wr = null;
                log.fine("parsing line[" + lineNumber + "]=" + line);
                wr = parseDataLine(line);
                //log.fine("wr=" + wr);

                /*
                 * if (locationCoords.containsKey(wr.getName())) { List<String> coords =
                 * Splitter.on(',').splitToList(locationCoords.get(wr.getName())); wr.setLon(new
                 * BigDecimal(coords.get(0))); wr.setLat(new BigDecimal(coords.get(1))); } else { log.fine(
                 * "==> cannot find coords for " + wr.getName()); }
                 */

                if (wr != null && wr.getName() != null) {
                    log.fine("adding wr=" + wr);
                    boolean added = results.add(wr);
                    if (!added) {
                        results.remove(wr);
                        results.add(wr);
                    }
                } else {
                    log.finer("did not add wr for line " + lineNumber);
                    /*                  if (RegexUtils.matchFirstOccurance(line, passsageLinePattern) != null) {
                                         // some data sections have a passage section header
                                         log.fine("found passage section header at line " + lineNumber);
                                      }
                                      else {
                                         // end of data section
                                         // TODO how to detect the end of a section?
                                         //inData = false;
                                         log.fine("end of data at line " + lineNumber);
                                      }*/
                }
            } else {
                log.finest("skipping line " + lineNumber);
            }

            lineNumber++;
        }
    } catch (IOException e) {
        log.severe(e.getLocalizedMessage());
    }

    return results;
}

From source file:com.willwinder.ugp.tools.GcodeTilerTopComponent.java

private void generateAndLoadGcode(File file) {
    try {/*from  ww  w  .  j a v a2  s  .  co  m*/
        if (this.outputFile == null) {
            try (PrintWriter writer = new PrintWriter(new FileWriter(file))) {
                double padding = SwingHelpers.getDouble(this.padding);
                double stepX = padding + GcodeTilerTopComponent.xWidth;
                double stepY = padding + GcodeTilerTopComponent.yWidth;

                // loop over offsets and call generateOneTile a bunch
                for (int x = 0; x < SwingHelpers.getInt(this.numCopiesX); x++) {
                    for (int y = 0; y < SwingHelpers.getInt(this.numCopiesY); y++) {
                        this.generateOneTile((x * stepX), (y * stepY), writer);
                    }
                }
            }
        }
        backend.setGcodeFile(file);
    } catch (IOException e) {
        GUIHelpers.displayErrorDialog(ERROR_GENERATING + e.getLocalizedMessage());
    } catch (Exception e) {
        GUIHelpers.displayErrorDialog(ERROR_LOADING + e.getLocalizedMessage());
    }
}

From source file:it.geosolutions.geoserver.rest.publisher.GeoserverRESTImageMosaicTest.java

@Test
public void testCreateDeleteImageMosaicDatastore() throws MalformedURLException, UnsupportedEncodingException {
    if (!enabled()) {
        return;/*from ww w. j  a va2  s .c  om*/
    }
    deleteAll();

    final String wsName = "geosolutions";
    final String coverageStoreName = "resttestImageMosaic";

    final GSImageMosaicEncoder coverageEncoder = new GSImageMosaicEncoder();
    /*
     * unused in mosaic creation
     * this is only useful if you want to modify an existing coverage:
     * publisher.configureCoverage(ce, wsname, csname);
     * or create a new one from an existing store:
     * publisher.createCoverage(ce, wsname, csname);
     */
    //        coverageEncoder.setName("time_geotiff");

    coverageEncoder.setAllowMultithreading(true);
    coverageEncoder.setBackgroundValues("");
    coverageEncoder.setFilter("");
    coverageEncoder.setInputTransparentColor("");
    coverageEncoder.setLatLonBoundingBox(-180, -90, 180, 90, "EPSG:4326");
    coverageEncoder.setMaxAllowedTiles(6000);
    coverageEncoder.setNativeBoundingBox(-180, -90, 180, 90, "EPSG:4326");
    coverageEncoder.setOutputTransparentColor("");
    coverageEncoder.setProjectionPolicy(ProjectionPolicy.REPROJECT_TO_DECLARED);
    coverageEncoder.setSRS("EPSG:4326");
    coverageEncoder.setSUGGESTED_TILE_SIZE("256,256");
    coverageEncoder.setUSE_JAI_IMAGEREAD(true);

    GSVersionDecoder v = reader.getGeoserverVersion();
    if (v.compareTo(GSVersionDecoder.VERSION.v24) >= 0) {
        GSCoverageDimensionEncoder gsCoverageDimensionEncoder = new GSCoverageDimensionEncoder("GRAY_INDEX",
                "GridSampleDimension[-Infinity,Infinity]", "-inf", "inf", "dobson units", "REAL_32BITS");
        coverageEncoder.addCoverageDimensionInfo(gsCoverageDimensionEncoder);
    }

    // activate time
    final GSDimensionInfoEncoder time = new GSDimensionInfoEncoder(true);
    time.setPresentation(Presentation.LIST);
    // set time metadata
    coverageEncoder.setMetadata("time", time);
    // not active elevation
    coverageEncoder.setMetadata("elevation", new GSDimensionInfoEncoder());

    assertTrue(publisher.createWorkspace(wsName));

    LOGGER.info(coverageEncoder.toString());

    final String styleName = "raster";
    File sldFile;
    try {
        sldFile = new ClassPathResource("testdata/raster.sld").getFile();
        // insert style
        assertTrue(publisher.publishStyle(sldFile));
    } catch (IOException e1) {
        assertFalse(e1.getLocalizedMessage(), Boolean.FALSE);
        e1.printStackTrace();
    }

    GSLayerEncoder layerEncoder = new GSLayerEncoder();

    layerEncoder.setDefaultStyle(styleName);
    LOGGER.info(layerEncoder.toString());
    // creation test
    RESTCoverageStore coverageStore = null;
    try {
        final File mosaicFile = new ClassPathResource("testdata/time_geotiff/").getFile();

        if (!publisher.publishExternalMosaic(wsName, coverageStoreName, mosaicFile, coverageEncoder,
                layerEncoder)) {
            fail();
        }
        coverageStore = reader.getCoverageStore(wsName, coverageStoreName);

        if (coverageStore == null) {
            LOGGER.error("*** coveragestore " + coverageStoreName + " has not been created.");
            fail("*** coveragestore " + coverageStoreName + " has not been created.");
        }

    } catch (FileNotFoundException e) {
        e.printStackTrace();
        fail(e.getLocalizedMessage());
    } catch (IOException e) {
        e.printStackTrace();
        fail(e.getLocalizedMessage());
    }
    // Get a Granule
    String coverageName = "time_geotiff";
    RESTStructuredCoverageGranulesList granules = reader.getGranules(wsName, coverageStoreName, coverageName,
            null, null, null);
    String granuleId = granules.get(0).getFid();
    // Test Granule Exists
    assertTrue(reader.existsGranule(wsName, coverageStoreName, coverageName, granuleId));
    // test a Granule does not exists
    assertFalse(reader.existsGranule(wsName, coverageStoreName, coverageName,
            granuleId.substring(0, granuleId.indexOf(".")) + "." + granules.size() + 1));

    // removing recursively coveragestore
    boolean removed = publisher.removeCoverageStore(coverageStore.getWorkspaceName(), coverageStore.getName(),
            true);
    if (!removed) {
        LOGGER.error("*** CoverageStore " + coverageStoreName + " has not been removed.");
        fail("*** CoverageStore " + coverageStoreName + " has not been removed.");
    }

    assertTrue(publisher.removeStyle(styleName));
    assertTrue(publisher.removeWorkspace(wsName));
}