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.tools.compress.file.Extractor.java

public static void unZip(File inputZipFile, File outputDir) throws IOException, CompressorException {
    if (inputZipFile == null || outputDir == null) {
        throw new CompressorException("Unzip: with null parameters");
    }/*from  w w  w.  j a va 2 s. c  o  m*/

    if (!outputDir.exists()) {
        if (!outputDir.mkdirs()) {
            throw new CompressorException("Unzip: Unable to create directory structure: " + outputDir);
        }
    }

    final int BUFFER = Conf.getBufferSize();

    ZipInputStream zipInputStream = null;
    try {
        // Open Zip file for reading
        zipInputStream = new ZipInputStream(new FileInputStream(inputZipFile));
    } catch (FileNotFoundException fnf) {
        throw new CompressorException("Unzip: Unable to find the input zip file named: " + inputZipFile);
    }

    // extract file if not a directory
    BufferedInputStream bis = new BufferedInputStream(zipInputStream);
    // grab a zip file entry
    ZipEntry entry = null;
    while ((entry = zipInputStream.getNextEntry()) != null) {
        // Process each entry

        File currentFile = new File(outputDir, entry.getName());

        FileOutputStream fos = null;
        BufferedOutputStream dest = null;
        try {
            int currentByte;
            // establish buffer for writing file
            byte data[] = new byte[BUFFER];

            // write the current file to disk
            fos = new FileOutputStream(currentFile);
            dest = new BufferedOutputStream(fos, BUFFER);

            // read and write until last byte is encountered
            while ((currentByte = bis.read(data, 0, BUFFER)) != -1) {
                dest.write(data, 0, currentByte);
            }
        } catch (IOException ioe) {

        } finally {
            try {
                if (dest != null) {
                    dest.flush();
                    dest.close();
                }
                if (fos != null)
                    fos.close();
            } catch (IOException ioe) {
                throw new CompressorException(
                        "Unzip: unable to close the zipInputStream: " + ioe.getLocalizedMessage());
            }
        }
    }
    try {
        if (zipInputStream != null)
            zipInputStream.close();
    } catch (IOException ioe) {
        throw new CompressorException(
                "Unzip: unable to close the zipInputStream: " + ioe.getLocalizedMessage());
    }
    try {
        if (bis != null)
            bis.close();
    } catch (IOException ioe) {
        throw new CompressorException(
                "Unzip: unable to close the Buffered zipInputStream: " + ioe.getLocalizedMessage());
    }
}

From source file:ca.uvic.cs.tagsea.wizards.TagNetworkSender.java

public static synchronized void send(String xml, IProgressMonitor sendMonitor, int id)
        throws InvocationTargetException {
    sendMonitor.beginTask("Uploading Tags", 100);
    sendMonitor.subTask("Saving Temporary file...");
    File location = TagSEAPlugin.getDefault().getStateLocation().toFile();
    File temp = new File(location, "tagsea.temp.file.txt");
    if (temp.exists()) {
        String message = "Unable to send tags. Unable to create temporary file.";
        IOException ex = new IOException(message);
        throw (new InvocationTargetException(ex, message));
    }/*from w  w  w. j av a 2  s . c o  m*/
    try {
        FileWriter writer = new FileWriter(temp);
        writer.write(xml);
        writer.flush();
        writer.close();
    } catch (IOException e) {
        throw new InvocationTargetException(e);
    }
    sendMonitor.worked(5);
    sendMonitor.subTask("Uploading Tags...");
    String uploadScript = "http://stgild.cs.uvic.ca/cgi-bin/tagSEAUpload.cgi";
    PostMethod post = new PostMethod(uploadScript);

    String fileName = getToday() + ".txt";
    try {
        Part[] parts = { new StringPart("KIND", "tag"), new FilePart("MYLAR" + id, fileName, temp) };
        post.setRequestEntity(new MultipartRequestEntity(parts, post.getParams()));
        HttpClient client = new HttpClient();
        int status = client.executeMethod(post);
        String resp = getData(post.getResponseBodyAsStream());
        if (status != 200) {
            IOException ex = new IOException(resp);
            throw (ex);
        }
    } catch (IOException e) {
        throw new InvocationTargetException(e, e.getLocalizedMessage());
    } finally {
        sendMonitor.worked(90);
        sendMonitor.subTask("Deleting Temporary File");
        temp.delete();
        sendMonitor.done();
    }

}

From source file:it.geosolutions.geobatch.imagemosaic.ImageMosaicUpdater.java

/**
 * Method to backup granules that have been removed from the index.
 * /*  www  .j  av a 2  s .co  m*/
 * <P>
 * The provided backup dire must exist and be writable for the process.
 * 
 * @param filesToBackup {@link List} of files to backup, that is move to the backup directory
 * @param backUpDirectory target directory for the process
 * @return <code>false</code> in case we manage to move the files, <code>false</code> otherwise.
 */
static boolean backUpGranulesFiles(final List<File> filesToBackup, final File backUpDirectory) {

    //checks on dir
    if (backUpDirectory == null) {
        throw new IllegalArgumentException("Provided null back up directory");
    }
    if (!backUpDirectory.exists() || !backUpDirectory.isDirectory() || !backUpDirectory.canWrite()) {
        if (LOGGER.isErrorEnabled()) {
            LOGGER.error("Provided directory does not exist or it is not writable");
        }
        return false;
    }

    if (filesToBackup == null || filesToBackup.size() == 0) {
        if (LOGGER.isInfoEnabled()) {
            LOGGER.info("Provided list of files to backup is empty");
        }
        return true;
    }

    // now the magic
    boolean retValue = true;
    for (File granule : filesToBackup) {

        // move
        try {
            FileUtils.moveFileToDirectory(granule, backUpDirectory, false);
        } catch (IOException e) {
            if (LOGGER.isInfoEnabled()) {
                LOGGER.info(e.getLocalizedMessage(), e);
            }
            // if we fail we try to remove the afterwards
            retValue = false;
        }
    }
    return retValue;
}

From source file:probe.com.model.util.SwingToImageGenerator.java

private String generateEncodedImg(BufferedImage image) {
    String base64 = "";
    try {/*from   ww  w  . j a  v a2 s .c o m*/
        ImageEncoder in = ImageEncoderFactory.newInstance(ImageFormat.PNG, 0);
        byte[] imageData = in.encode(image);
        base64 = Base64.encodeBase64String(imageData);
        base64 = "data:image/png;base64," + base64;
        System.gc();
    } catch (IOException exp) {
        System.err.println(exp.getLocalizedMessage());
    }
    return base64;
}

From source file:net.infstudio.inflauncher.game.downloading.MinecraftDownloader.java

@Override
public boolean download() {
    String url = InfinityDownloader.mirrorManager.getFastestS3MirrorURL();
    String metaUrl = InfinityDownloader.mirrorManager.getFastestMetaMirrorURL();
    String librariesUrl = InfinityDownloader.mirrorManager.getFastestMavenMirrorURL();
    try {/*  ww  w . j  av  a 2 s .  co m*/
        FileUtils.copyURLToFile(new URL(url + "/Minecraft.Download/versions/" + minecraft.getJar() + ".json"),
                new File(minecraft.getJar() + ".json"));
    } catch (IOException e) {
        InfinityDownloader.logger.error(e.getLocalizedMessage(), e);
    }
    return false;
}

From source file:com.jomp16.swfripper.DownloadManager.java

@Override
public void run() {
    File file = new File(path);
    if (!file.exists()) {
        try {//from  ww w. j a  v a2  s  .c o  m
            Main.getLogging().writeLine("DownloadingFile", url);
            FileUtils.copyURLToFile(new URL(url), file);
            Main.getLogging().writeLine("DownloadedFile", url);
        } catch (IOException e) {
            System.err.println(e.getLocalizedMessage());
        }
    } else {
        try {
            Main.getLogging().writeLine("BypassingFile", url);
        } catch (IOException e) {
            System.err.println(e.getLocalizedMessage());
        }
    }
}

From source file:ru.codemine.pos.ui.windows.document.startbalances.listener.LoadFromFileSb.java

@Override
public void actionPerformed(ActionEvent e) {
    StartBalance sb = window.getDocument();

    WebFileChooser fileChooser = new WebFileChooser();
    fileChooser.setMultiSelectionEnabled(false);
    fileChooser.setGenerateThumbnails(false);
    if (fileChooser.showOpenDialog(window) == WebFileChooser.APPROVE_OPTION) {
        String filename = fileChooser.getSelectedFile().getAbsolutePath();

        try {//from   w w w  .j a  v a2  s. c o m
            window.getTableModel().setStartBalance(sbService.loadFromCsv(sb, filename));
        } catch (IOException ex) {
            WebOptionPane.showMessageDialog(window, ex.getLocalizedMessage(),
                    " ? ", WebOptionPane.ERROR_MESSAGE);
        }

        window.getTableModel().fireTableDataChanged();
    }

}

From source file:org.ktunaxa.referral.server.command.email.ValidateTemplateCommand.java

public void execute(ValidateTemplateRequest request, ValidateTemplateResponse response) throws Exception {
    final TaskDto task = request.getTask();
    if (null == task) {
        throw new GeomajasException(ExceptionCode.PARAMETER_MISSING, "task");
    }//from   www  .j  a v  a 2s .c o m
    final Map<String, String> attributes = request.getAttributes();
    if (null == attributes) {
        throw new GeomajasException(ExceptionCode.PARAMETER_MISSING, "attributes");
    }
    final String subject = request.getSubject();
    if (null == subject) {
        throw new GeomajasException(ExceptionCode.PARAMETER_MISSING, "subject");
    }
    final String body = request.getBody();
    if (null == body) {
        throw new GeomajasException(ExceptionCode.PARAMETER_MISSING, "body");
    }

    TemplateFiller filler = new TemplateFiller();
    Map<String, String> variables = new HashMap<String, String>();
    variables.putAll(task.getVariables());
    variables.putAll(attributes);
    try {
        filler.fillStringWithData(subject, variables);
        filler.fillStringWithData(body, variables);
        response.setValid(true);
    } catch (IOException e) {
        log.error(e.getLocalizedMessage(), e);
        response.setValid(false);
    } catch (TemplateException te) {
        log.debug(te.getMessage(), te);
        response.setValid(false);
        String[] split = te.getFTLInstructionStack().split("\\$\\{", 2);
        split = split[1].split("\\}", 2);
        response.setInvalidPlaceholder("${" + split[0] + "}");
    }
}

From source file:be.roots.taconic.pricingguide.job.RetryRequestJob.java

public List<Request> getUnsendRequests() {

    final File[] files = new File(requestRetryLocation).listFiles();
    final List<Request> result = new ArrayList<>();
    if (files != null) {
        for (File file : files) {
            if (file.isFile() && file.getName().endsWith(".txt")) {
                try {
                    final Request request = JsonUtil.asObject(FileUtils.readFileToString(file), Request.class);
                    result.add(request);
                    file.delete();/* w ww . ja va 2 s .  c  o  m*/
                } catch (IOException e) {
                    LOGGER.error(e.getLocalizedMessage(), e);
                }
            }
        }
    }

    return result;
}

From source file:ch.njol.skript.Updater.java

/**
 * Must set {@link #state} to {@link UpdateState#DOWNLOAD_IN_PROGRESS} prior to calling this
 * // www.j  a  v a 2 s  .  c  om
 * @param sender
 * @param isAutomatic
 */
static void download_i(final CommandSender sender, final boolean isAutomatic) {
    assert sender != null;
    stateLock.readLock().lock();
    try {
        if (state != UpdateState.DOWNLOAD_IN_PROGRESS)
            throw new IllegalStateException();
    } finally {
        stateLock.readLock().unlock();
    }
    Skript.info(sender, "" + m_downloading);
    //      boolean hasJar = false;
    //      ZipInputStream zip = null;
    InputStream in = null;
    try {
        final URLConnection conn = new URL(latest.get().downloadURL).openConnection();
        in = conn.getInputStream();
        assert in != null;
        FileUtils.save(in, new File(Bukkit.getUpdateFolderFile(), "Skript.jar"));
        //         zip = new ZipInputStream(conn.getInputStream());
        //         ZipEntry entry;
        ////         boolean hasAliases = false;
        //         while ((entry = zip.getNextEntry()) != null) {
        //            if (entry.getName().endsWith("Skript.jar")) {
        //               assert !hasJar;
        //               save(zip, new File(Bukkit.getUpdateFolderFile(), "Skript.jar"));
        //               hasJar = true;
        //            }// else if (entry.getName().endsWith("aliases.sk")) {
        ////               assert !hasAliases;
        ////               saveZipEntry(zip, new File(Skript.getInstance().getDataFolder(), "aliases-" + latest.get().version + ".sk"));
        ////               hasAliases = true;
        ////            }
        //            zip.closeEntry();
        //            if (hasJar)// && hasAliases)
        //               break;
        //         }
        if (isAutomatic)
            Skript.adminBroadcast("" + m_downloaded);
        else
            Skript.info(sender, "" + m_downloaded);
        stateLock.writeLock().lock();
        try {
            state = UpdateState.DOWNLOADED;
        } finally {
            stateLock.writeLock().unlock();
        }
    } catch (final IOException e) {
        stateLock.writeLock().lock();
        try {
            state = UpdateState.DOWNLOAD_ERROR;
            error.set(ExceptionUtils.toString(e));
            Skript.error(sender, m_download_error.toString());
        } finally {
            stateLock.writeLock().unlock();
        }
    } catch (final Exception e) {
        Skript.exception(e, "Error while downloading the latest version of Skript");
        stateLock.writeLock().lock();
        try {
            state = UpdateState.DOWNLOAD_ERROR;
            error.set(e.getClass().getSimpleName() + ": " + e.getLocalizedMessage());
        } finally {
            stateLock.writeLock().unlock();
        }
    } finally {
        if (in != null) {
            try {
                in.close();
            } catch (final IOException e) {
            }
        }
    }
}