Example usage for org.apache.commons.io FilenameUtils getBaseName

List of usage examples for org.apache.commons.io FilenameUtils getBaseName

Introduction

In this page you can find the example usage for org.apache.commons.io FilenameUtils getBaseName.

Prototype

public static String getBaseName(String filename) 

Source Link

Document

Gets the base name, minus the full path and extension, from a full filename.

Usage

From source file:MSUmpire.DIA.RTAlignedPepIonMapping.java

private void GenerateRTMapPNG(XYSeriesCollection xySeriesCollection, XYSeries series, float R2)
        throws IOException {
    new File(Workfolder + "/RT_Mapping/").mkdir();
    String pngfile = Workfolder + "/RT_Mapping/"
            + FilenameUtils.getBaseName(LCMSA.mzXMLFileName).substring(0,
                    Math.min(120, FilenameUtils.getBaseName(LCMSA.mzXMLFileName).length() - 1))
            + "_" + FilenameUtils.getBaseName(LCMSB.mzXMLFileName).substring(0,
                    Math.min(120, FilenameUtils.getBaseName(LCMSB.mzXMLFileName).length() - 1))
            + "_RT.png";

    XYSeries smoothline = new XYSeries("RT fitting curve");
    for (XYZData data : regression.PredictYList) {
        smoothline.add(data.getX(), data.getY());
    }//from w  w w .j a va2  s  . c  o  m
    xySeriesCollection.addSeries(smoothline);
    xySeriesCollection.addSeries(series);
    JFreeChart chart = ChartFactory.createScatterPlot("Retention time mapping: R2=" + R2,
            "RT:" + FilenameUtils.getBaseName(LCMSA.mzXMLFileName),
            "RT:" + FilenameUtils.getBaseName(LCMSB.mzXMLFileName), xySeriesCollection,
            PlotOrientation.VERTICAL, true, true, false);
    XYPlot xyPlot = (XYPlot) chart.getPlot();
    xyPlot.setDomainCrosshairVisible(true);
    xyPlot.setRangeCrosshairVisible(true);

    XYItemRenderer renderer = xyPlot.getRenderer();
    renderer.setSeriesPaint(1, Color.blue);
    renderer.setSeriesPaint(0, Color.BLACK);
    renderer.setSeriesShape(1, new Ellipse2D.Double(0, 0, 3, 3));
    renderer.setSeriesStroke(1, new BasicStroke(3.0f));
    renderer.setSeriesStroke(0, new BasicStroke(3.0f));
    xyPlot.setBackgroundPaint(Color.white);
    ChartUtilities.saveChartAsPNG(new File(pngfile), chart, 1000, 600);
}

From source file:net.chris54721.infinitycubed.workers.PackLoader.java

@Override
public void run() {
    try {/*from   w  ww  . j a  v  a 2s  .  c  om*/
        LogHelper.info("Loading and updating modpacks");
        String publicJson = Utils.toString(new URL(Reference.FILES_URL + "public.json"));
        Type stringIntMap = new TypeToken<LinkedHashMap<String, Integer>>() {
        }.getType();
        LinkedHashMap<String, Integer> publicObjects = Reference.DEFAULT_GSON.fromJson(publicJson,
                stringIntMap);
        File localJson = new File(Resources.getFolder(Reference.PACKS_FOLDER), "public.json");
        List<String> updatePacks = new ArrayList<String>();
        if (localJson.isFile()) {
            String localPublicJson = Files.toString(localJson, Charsets.UTF_8);
            LinkedHashMap<String, Integer> localPublicObjects = Reference.DEFAULT_GSON.fromJson(localPublicJson,
                    stringIntMap);
            for (String pack : publicObjects.keySet()) {
                if (!localPublicObjects.containsKey(pack)
                        || !localPublicObjects.get(pack).equals(publicObjects.get(pack))) {
                    updatePacks.add(pack);
                }
            }
        } else
            updatePacks.addAll(publicObjects.keySet());
        Files.write(publicJson, localJson, Charsets.UTF_8);
        if (updatePacks.size() > 0) {
            for (String pack : updatePacks) {
                LogHelper.info("Updating JSON file for modpack " + pack);
                URL packJsonURL = Resources.getUrl(Resources.ResourceType.PACK_JSON, pack + ".json");
                File packJsonFile = Resources.getFile(Resources.ResourceType.PACK_JSON, pack + ".json");
                if (packJsonFile.isFile())
                    packJsonFile.delete();
                Downloadable packJsonDownloadable = new Downloadable(packJsonURL, packJsonFile);
                if (!packJsonDownloadable.download())
                    LogHelper.error("Failed updating JSON for modpack " + pack);
            }
        }
        Collection<File> packJsons = FileUtils.listFiles(Resources.getFolder(Reference.DATA_FOLDER),
                new String[] { "json" }, false);
        for (File packJsonFile : packJsons)
            loadPack(FilenameUtils.getBaseName(packJsonFile.getName()));
    } catch (Exception e) {
        LogHelper.fatal("Failed updating and loading public packs", e);
    }
}

From source file:de.fau.cs.osr.hddiff.perfsuite.HDDiffTestUtils.java

public Wom3Document parse(File inputFile, ExpansionCallback callback) throws Exception {
    String fileTitle = FilenameUtils.getBaseName(inputFile.getName());

    PageId pageId = getWtWom3Toolbox().makePageId(fileTitle);

    Wom3Document wom = getWtWom3Toolbox().wmToWom(inputFile, pageId, callback, "UTF8").womDoc;

    // We will modify this document in possibly illegal ways later
    wom.setStrictErrorChecking(false);//  w ww .j  a  v  a  2  s . c o m

    return wom;
}

From source file:codes.thischwa.c5c.impl.JarFilemanagerMessageResolver.java

@Override
public void setServletContext(ServletContext servletContext) {
    ObjectMapper mapper = new ObjectMapper();
    try {/*from  www .  ja v a2  s  . c o  m*/
        if (JarPathResolver.insideJar(getMessagesFolderPath())) {
            CodeSource src = JarFilemanagerMessageResolver.class.getProtectionDomain().getCodeSource();
            URI uri = src.getLocation().toURI();
            logger.info("Message folder is inside jar: {}", uri);

            try (FileSystem jarFS = FileSystems.newFileSystem(uri, new HashMap<String, String>())) {
                if (jarFS.getRootDirectories().iterator().hasNext()) {
                    Path rootDirectory = jarFS.getRootDirectories().iterator().next();

                    Path langFolder = rootDirectory.resolve(getMessagesFolderPath());
                    if (langFolder != null) {
                        try (DirectoryStream<Path> langFolderStream = Files.newDirectoryStream(langFolder,
                                JS_FILE_MASK)) {
                            for (Path langFile : langFolderStream) {
                                String lang = langFile.getFileName().toString();
                                InputStream is = Files.newInputStream(langFile);
                                Map<String, String> langData = mapper.readValue(is,
                                        new TypeReference<HashMap<String, String>>() {
                                        });
                                collectLangData(lang, langData);
                            }
                        }
                    } else {
                        throw new RuntimeException("Folder in jar " + langFolder + " does not exists.");
                    }
                }
            }
        } else {
            File messageFolder = JarPathResolver.getFolder(getMessagesFolderPath());
            logger.info("Message folder resolved to: {}", messageFolder);

            if (messageFolder == null || !messageFolder.exists()) {
                throw new RuntimeException("Folder " + getMessagesFolderPath() + " does not exist");
            }

            for (File file : messageFolder.listFiles(jsFilter)) {
                String lang = FilenameUtils.getBaseName(file.getName());
                Map<String, String> langData = mapper.readValue(file,
                        new TypeReference<HashMap<String, String>>() {
                        });
                collectLangData(lang, langData);
            }
        }
    } catch (URISyntaxException | IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:ijfx.explorer.datamodel.wrappers.ImageRecordIconizer.java

public ImageRecordIconizer(Context context, ImageRecord imageRecord, int imageId) {

    this(context, imageRecord);
    series = true;//w w  w . jav a2 s.  c om
    this.imageId = imageId;
    set.putGeneric(MetaData.SERIE, imageId);

    String baseName = FilenameUtils.getBaseName(imageRecord.getFile().getName());
    String saveName = String.format(SERIE_SAVE_FORMAT, baseName, imageId + 1);
    set.putGeneric(MetaData.FILE_NAME,
            String.format(SERIE_NAME_FORMAT, imageRecord.getFile().getName(), imageId + 1));
    set.putGeneric(MetaData.SAVE_NAME, saveName);
}

From source file:com.frostwire.android.gui.transfers.YouTubeDownload.java

YouTubeDownload(TransferManager manager, YouTubeCrawledSearchResult sr) {
    this.manager = manager;
    this.sr = sr;
    this.downloadType = buildDownloadType(sr);
    this.size = sr.getSize();

    String filename = sr.getFilename();

    File savePath = SystemPaths.getTorrentData();

    ensureDirectoryExits(savePath);//from   w w w  . jav  a2s  .  c o m
    ensureDirectoryExits(SystemPaths.getTemp());

    completeFile = buildFile(savePath, filename);
    tempVideo = buildTempFile(FilenameUtils.getBaseName(filename), "video");
    tempAudio = buildTempFile(FilenameUtils.getBaseName(filename), "audio");

    bytesReceived = 0;
    dateCreated = new Date();

    httpClientListener = new HttpDownloadListenerImpl();

    httpClient = HttpClientFactory.newInstance();
    httpClient.setListener(httpClientListener);

    if (SystemUtils.isCurrentMountAlmostFull()) {
        this.status = STATUS_ERROR_DISK_FULL;
    }
}

From source file:com.textocat.textokit.io.brat.BratCollectionReader.java

@Override
public void initialize(UimaContext ctx) throws ResourceInitializationException {
    super.initialize(ctx);
    // initialize mappingFactory
    mappingFactory = InitializableFactory.create(ctx, mappingFactoryClassName, BratUimaMappingFactory.class);
    // make bratDocIter
    File[] annFiles = bratCollectionDir
            .listFiles((FileFilter) FileFilterUtils.suffixFileFilter(BratDocument.ANN_FILE_SUFFIX));
    List<BratDocument> bratDocs = Lists.newArrayListWithExpectedSize(annFiles.length);
    for (File annFile : annFiles) {
        String docBaseName = FilenameUtils.getBaseName(annFile.getPath());
        BratDocument bratDoc = new BratDocument(bratCollectionDir, docBaseName);
        if (bratDoc.exists()) {
            bratDocs.add(bratDoc);/* w  w  w.  ja v a 2s .c o  m*/
        } else {
            throw new IllegalStateException(String.format("Missing txt file for %s", annFile));
        }
    }
    totalDocsNum = bratDocs.size();
    bratDocIter = bratDocs.iterator();
}

From source file:MSUmpire.Utility.ExportTable.java

private void ProteinLevelExport(int TopNPep, int TopNFrag, float Freq) throws IOException {
    FileWriter proWriter = new FileWriter(WorkFolder + "ProtSummary_" + DateTimeTag.GetTag() + ".xls");
    FileWriter pepWriter = new FileWriter(WorkFolder + "PeptideSummary_" + DateTimeTag.GetTag() + ".xls");
    FileWriter NOWriter = new FileWriter(WorkFolder + "IDNoSummary_" + DateTimeTag.GetTag() + ".xls");
    FileWriter fragWriter = new FileWriter(WorkFolder + "FragSummary_" + DateTimeTag.GetTag() + ".xls");
    //Fragment Summary//////////////////////////////////////////
    for (LCMSID IDsummary : FileList) {
        HashMap<String, FragmentPeak> FragMap = IDSummaryFragments
                .get(FilenameUtils.getBaseName(IDsummary.mzXMLFileName));
        if (FragMap == null) {
            Logger.getRootLogger().error(
                    "Cannot find fragment map for " + FilenameUtils.getBaseName(IDsummary.mzXMLFileName));
            Logger.getRootLogger().debug("Printing all fragment maps");
            for (String key : FragMap.keySet()) {
                Logger.getRootLogger().debug(key);
            }//from  ww w.  j av a2s.  co m
        }
        for (String key : CombineProtID.ProteinList.keySet()) {
            if (IDsummary.ProteinList.containsKey(key)) {
                ProtID protein = IDsummary.ProteinList.get(key);
                for (PepIonID pep : protein.PeptideID.values()) {
                    for (FragmentPeak frag : pep.FragmentPeaks) {
                        final String mapkey =
                                // key + ";" + pep.GetKey() + ";" + frag.IonType;
                                key + ";" + pep.GetKey() + ";" + frag.IonType + ";+" + frag.Charge;
                        //                            ProteinFragMap.putIfAbsent(mapkey, frag.FragMZ);// needs Java 8
                        if (!ProteinFragMap.containsKey(mapkey))
                            ProteinFragMap.put(mapkey, frag.FragMZ);
                        frag.Prob1 = pep.MaxProbability;
                        frag.Prob2 = pep.TargetedProbability();
                        frag.RT = pep.PeakRT;
                        FragMap.put(mapkey, frag);
                    }
                }
            }
        }
    }

    NOWriter.write(
            "File\tNo. Proteins\tNo. peptide ions (Spec-centric)\tNo. peptide ions (Pep-centric)\tNo. proein assoc. ions\n");

    //ProteinSummary/////////////
    proWriter.write("Protein Key\t");
    proWriter.write("Selected_peptides\t");
    for (LCMSID IDSummary : FileList) {
        NOWriter.write(FilenameUtils.getBaseName(IDSummary.mzXMLFileName) + "\t" + IDSummary.ProteinList.size()
                + "\t" + IDSummary.GetPepIonList().size() + "\t" + IDSummary.GetMappedPepIonList().size() + "\t"
                + IDSummary.AssignedPepIonList.size() + "\n");
        String file = FilenameUtils.getBaseName(IDSummary.mzXMLFileName);
        proWriter.write(file + "_Prob\t" + file + "_Peptides\t" + file + "_PSMs\t" + file + "_MS1_iBAQ\t" + file
                + "_Top" + TopNPep + "pep/Top" + TopNFrag + "fra ,Freq>" + Freq + "\t");
    }
    proWriter.write("\n");

    NOWriter.close();
    if (CombineProtID != null) {
        for (String key : CombineProtID.ProteinList.keySet()) {
            proWriter.write(key + "\t");
            for (final LCMSID IDsummary : FileList) {
                if (IDsummary.ProteinList.containsKey(key)) {
                    final ProtID protein = IDsummary.ProteinList.get(key);
                    proWriter.write(String.join("|", fragselection.TopPeps.get(protein.getAccNo())));
                    break;
                }
            }
            proWriter.write("\t");
            for (LCMSID IDsummary : FileList) {
                if (IDsummary.ProteinList.containsKey(key)) {
                    ProtID protein = IDsummary.ProteinList.get(key);
                    proWriter.write(protein.Probability + "\t" + protein.PeptideID.size() + "\t"
                            + protein.GetSpectralCount() + "\t" + protein.GetAbundanceByMS1_IBAQ() + "\t"
                            + protein.GetAbundanceByTopCorrFragAcrossSample(
                                    fragselection.TopPeps.get(protein.getAccNo()), fragselection.TopFrags)
                            + "\t");
                } else {
                    proWriter.write("\t\t\t\t\t");
                }
            }
            proWriter.write("\n");
        }
        proWriter.close();
    }

    fragWriter.write("Fragment Key\tProtein\tPeptide\tFragment\tFragMz\t");
    for (LCMSID IDSummary : FileList) {
        String file = FilenameUtils.getBaseName(IDSummary.mzXMLFileName);
        fragWriter.write(file + "_RT\t" + file + "_Spec_Centric_Prob\t" + file + "_Pep_Centric_Prob\t" + file
                + "_Intensity\t" + file + "_Corr\t" + file + "_PPM\t");
    }
    fragWriter.write("\n");
    for (final Map.Entry<String, Float> ent : new java.util.TreeMap<>(ProteinFragMap).entrySet()) {
        final String key = ent.getKey();
        fragWriter.write(key + "\t" + key.split(";")[0] + "\t" + key.split(";")[1] + "\t" + key.split(";")[2]
                + key.split(";")[3] + "\t" + ent.getValue() + "\t");
        for (LCMSID IDSummary : FileList) {
            if (IDSummaryFragments.get(FilenameUtils.getBaseName(IDSummary.mzXMLFileName)).containsKey(key)) {
                FragmentPeak fragmentPeak = IDSummaryFragments
                        .get(FilenameUtils.getBaseName(IDSummary.mzXMLFileName)).get(key);
                fragWriter.write(fragmentPeak.RT + "\t" + fragmentPeak.Prob1 + "\t" + fragmentPeak.Prob2 + "\t"
                        + fragmentPeak.intensity + "\t" + fragmentPeak.corr + "\t" + fragmentPeak.ppm + "\t");
            } else {
                fragWriter.write("\t\t\t\t\t\t");
            }
        }
        fragWriter.write("\n");
    }
    fragWriter.close();

    ////PepSummary///////////////////////////////////
    for (LCMSID IDsummary : FileList) {
        HashMap<String, FragmentPeak> FragMap = new HashMap<>();
        IDSummaryFragments.put(FilenameUtils.getBaseName(IDsummary.mzXMLFileName), FragMap);

        for (String key : IDsummary.GetPepIonList().keySet()) {
            if (!IdentifiedPepMap.contains(key)) {
                IdentifiedPepMap.add(key);
            }
        }
        for (String key : IDsummary.GetMappedPepIonList().keySet()) {
            if (!IdentifiedPepMap.contains(key)) {
                IdentifiedPepMap.add(key);
            }
        }
    }

    pepWriter.write("Peptide Key\tSequence\tModSeq\tProteins\tmz\tCharge\tMaxProb\t");
    pepWriter.write("Selected_fragments\t");
    for (LCMSID IDSummary : FileList) {
        String file = FilenameUtils.getBaseName(IDSummary.mzXMLFileName);
        pepWriter.write(file + "_Spec_Centric_Prob\t" + file + "_Pep_Centric_Prob\t" + file + "_PSMs\t" + file
                + "_RT\t" + file + "_MS1\t" + file + "_Top" + TopNFrag + "fra\t");
    }
    pepWriter.write("\n");

    for (String key : IdentifiedPepMap) {
        pepWriter.write(key + "\t");
        float maxprob = 0f;
        boolean output = false;
        for (LCMSID IDSummary : FileList) {
            if (IDSummary.GetPepIonList().containsKey(key)) {
                PepIonID peptide = IDSummary.GetPepIonList().get(key);
                if (!output) {
                    pepWriter.write(
                            peptide.Sequence + "\t" + peptide.ModSequence + "\t" + peptide.ParentProteins()
                                    + "\t" + peptide.ObservedMz + "\t" + peptide.Charge + "\t");
                    output = true;
                }
                if (peptide.MaxProbability > maxprob) {
                    maxprob = peptide.MaxProbability;
                }
            }
            if (IDSummary.GetMappedPepIonList().containsKey(key)) {
                PepIonID peptide = IDSummary.GetMappedPepIonList().get(key);
                if (!output) {
                    pepWriter.write(
                            peptide.Sequence + "\t" + peptide.ModSequence + "\t" + peptide.ParentProteins()
                                    + "\t" + peptide.ObservedMz + "\t" + peptide.Charge + "\t");
                    output = true;
                }
                if (peptide.TargetedProbability() > maxprob) {
                    maxprob = peptide.TargetedProbability();
                }
            }
        }
        pepWriter.write(maxprob + "\t");

        for (final LCMSID IDSummary : FileList) {
            if (IDSummary.GetPepIonList().containsKey(key)) {
                final PepIonID peptide = IDSummary.GetPepIonList().get(key);
                pepWriter.write(String.join("|", fragselection.TopFrags.get(peptide.GetKey())));
                break;
            } else if (IDSummary.GetMappedPepIonList().containsKey(key)) {
                final PepIonID peptide = IDSummary.GetMappedPepIonList().get(key);
                pepWriter.write(String.join("|", fragselection.TopFrags.get(peptide.GetKey())));
                break;
            } else {
            }
        }
        pepWriter.write("\t");

        for (LCMSID IDSummary : FileList) {
            if (IDSummary.GetPepIonList().containsKey(key)) {
                PepIonID peptide = IDSummary.GetPepIonList().get(key);
                pepWriter.write(peptide.MaxProbability + "\t-1\t" + peptide.GetSpectralCount() + "\t"
                        + peptide.PeakRT + "\t" + peptide.PeakHeight[0] + "\t"
                        + peptide.GetPepAbundanceByTopCorrFragAcrossSample(
                                fragselection.TopFrags.get(peptide.GetKey()))
                        + "\t");
            } else if (IDSummary.GetMappedPepIonList().containsKey(key)) {
                PepIonID peptide = IDSummary.GetMappedPepIonList().get(key);
                pepWriter.write("-1\t" + peptide.TargetedProbability() + "\t" + peptide.GetSpectralCount()
                        + "\t" + peptide.PeakRT + "\t" + peptide.PeakHeight[0] + "\t"
                        + peptide.GetPepAbundanceByTopCorrFragAcrossSample(
                                fragselection.TopFrags.get(peptide.GetKey()))
                        + "\t");
            } else {
                pepWriter.write("\t\t\t\t\t\t");
            }
        }
        pepWriter.write("\n");
    }
    pepWriter.close();
}

From source file:MSUmpire.BaseDataStructure.InstrumentParameter.java

public static InstrumentParameter ReadParametersSerialization(String filepath) {
    if (!new File(FilenameUtils.getFullPath(filepath) + FilenameUtils.getBaseName(filepath) + "_params.ser")
            .exists()) {//from w  ww . j a v  a 2  s .  c o m
        return null;
    }
    try {
        Logger.getRootLogger().info("Reading parameters from file:" + FilenameUtils.getFullPath(filepath)
                + FilenameUtils.getBaseName(filepath) + "_params.ser...");

        FileInputStream fileIn = new FileInputStream(
                FilenameUtils.getFullPath(filepath) + FilenameUtils.getBaseName(filepath) + "_params.ser");
        ObjectInputStream in = new ObjectInputStream(fileIn);
        InstrumentParameter params = (InstrumentParameter) in.readObject();
        in.close();
        fileIn.close();
        return params;

    } catch (Exception ex) {
        Logger.getRootLogger().error(ExceptionUtils.getStackTrace(ex));
        return null;
    }
}

From source file:com.mycompany.mytubeaws.UploadServlet.java

/**
 * Handles the HTTP <code>POST</code> method.
 *
 * @param request servlet request//from w  w w  . java 2s.c om
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    String result = "";
    String fileName = null;

    boolean uploaded = false;

    // configures upload settings
    DiskFileItemFactory factory = new DiskFileItemFactory(); // sets memory threshold - beyond which files are stored in disk
    factory.setSizeThreshold(1024 * 1024 * 3); // 3mb
    factory.setRepository(new File(System.getProperty("java.io.tmpdir"))); // sets temporary location to store files

    ServletFileUpload upload = new ServletFileUpload(factory);
    upload.setFileSizeMax(1024 * 1024 * 40); // sets maximum size of upload file
    upload.setSizeMax(1024 * 1024 * 50); // sets maximum size of request (include file + form data)

    try {
        List<FileItem> formItems = upload.parseRequest(request); // parses the request's content to extract file data

        if (formItems != null && formItems.size() > 0) // iterates over form's fields
        {
            for (FileItem item : formItems) // processes only fields that are not form fields
            {
                if (!item.isFormField()) {
                    fileName = item.getName();
                    UUID id = UUID.randomUUID();
                    fileName = FilenameUtils.getBaseName(fileName) + "_ID-" + id.toString() + "."
                            + FilenameUtils.getExtension(fileName);

                    File file = File.createTempFile("aws-java-sdk-upload", "");
                    item.write(file); // write form item to file (?)

                    if (file.length() == 0)
                        throw new RuntimeException("No file selected or empty file uploaded.");

                    try {
                        s3.putObject(new PutObjectRequest(bucketName, fileName, file));
                        result += "File uploaded successfully; ";
                        uploaded = true;
                    } catch (AmazonServiceException ase) {
                        System.out.println("Caught an AmazonServiceException, which means your request made it "
                                + "to Amazon S3, but was rejected with an error response for some reason.");
                        System.out.println("Error Message:    " + ase.getMessage());
                        System.out.println("HTTP Status Code: " + ase.getStatusCode());
                        System.out.println("AWS Error Code:   " + ase.getErrorCode());
                        System.out.println("Error Type:       " + ase.getErrorType());
                        System.out.println("Request ID:       " + ase.getRequestId());

                        result += "AmazonServiceException thrown; ";
                    } catch (AmazonClientException ace) {
                        System.out
                                .println("Caught an AmazonClientException, which means the client encountered "
                                        + "a serious internal problem while trying to communicate with S3, "
                                        + "such as not being able to access the network.");
                        System.out.println("Error Message: " + ace.getMessage());

                        result += "AmazonClientException thrown; ";
                    }

                    file.delete();
                }
            }
        }
    } catch (Exception ex) {
        result += "Generic exception: '" + ex.getMessage() + "'; ";
        ex.printStackTrace();
    }

    if (fileName != null && uploaded)
        result += "Generated file ID: " + fileName;

    System.out.println(result);

    request.setAttribute("resultText", result);
    request.getRequestDispatcher("/UploadResult.jsp").forward(request, response);
}