Example usage for java.io FileNotFoundException getMessage

List of usage examples for java.io FileNotFoundException getMessage

Introduction

In this page you can find the example usage for java.io FileNotFoundException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:com.aurel.track.admin.customize.category.report.ReportBL.java

public static Map<String, Object> getTemplateDescription(File templateFile) {
    File file = new File(templateFile, "description.xml");
    try {//from   w w  w.j a va2s .  c  o  m
        return getTemplateDescription(new FileInputStream(file));
    } catch (FileNotFoundException e) {
        LOGGER.error("getTemplateDescription error:" + e.getMessage());
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug(ExceptionUtils.getStackTrace(e));
        }
        return new HashMap<String, Object>();
    }
}

From source file:com.commsen.apropos.core.PropertiesManager.java

/**
 * Loads properties form {@value #dataFile} and fills {@link #rootPackages} and
 * {@value #allPackages}. This method is called only once - during class initialization (from a
 * static block)/*www  .  ja  v  a 2s.co  m*/
 */
private static void load() {
    if (dataFile.exists() && dataFile.isFile()) {
        FileInputStream dataStream = null;
        try {
            dataStream = new FileInputStream(dataFile);
            instance = (PropertiesManager) xStream.fromXML(dataStream);
        } catch (FileNotFoundException e) {
            throw new InternalError(e.getMessage());
        } finally {
            if (dataStream != null)
                try {
                    dataStream.close();
                } catch (IOException e) {
                    // oops failed to close stream
                }
        }
        for (PropertyPackage rootPackage : instance.rootPackages) {
            addToAllPackages(rootPackage);
        }
    }
}

From source file:com.trackplus.ddl.DataWriter.java

public static BufferedReader createBufferedReader(String fileName) throws DDLException {
    InputStreamReader inputStreamReader;
    try {/*  w w  w.  ja  v  a 2  s  . c  o m*/
        inputStreamReader = new InputStreamReader(new FileInputStream(fileName), "UTF-8");
    } catch (FileNotFoundException e) {
        throw new DDLException(e.getMessage(), e);
    } catch (UnsupportedEncodingException e) {
        throw new DDLException(e.getMessage(), e);
    }

    return new BufferedReader(inputStreamReader);
}

From source file:com.galactogolf.genericobjectmodel.levelloader.LevelSet.java

public static ArrayList<LevelSet> loadAllLevelSetsFromInternalStorage(Context context)
        throws LevelLoadingException {

    File levelsDir = context.getDir(GameConstants.LOCATION_OF_LEVELS_CREATED_BY_USER, Context.MODE_PRIVATE);
    File[] levelSetFiles = levelsDir.listFiles();
    ArrayList<LevelSet> levelSets = new ArrayList<LevelSet>();
    for (int i = 0; i < levelSetFiles.length; i++) {
        InputStream input;//w  w  w  .  j a v a 2  s  .  c om
        try {
            input = new FileInputStream(levelSetFiles[i]);
        } catch (FileNotFoundException e) {
            Log.e("File loading error", e.getMessage());
            throw new LevelLoadingException(e.getMessage());
        }
        StringBuilder sb = new StringBuilder();
        final char[] buffer = new char[500];
        Reader in = new InputStreamReader(input);
        int read;
        try {
            do {
                read = in.read(buffer, 0, buffer.length);
                if (read > 0) {
                    sb.append(buffer, 0, read);
                }
            } while (read >= 0);
        } catch (IOException e) {
            Log.e("File loading error", e.getMessage());
            throw new LevelLoadingException(e.getMessage());
        }
        String data = sb.toString();
        try {
            levelSets.add(JSONSerializer.fromLevelSetJSON(new JSONObject(data)));
        } catch (JSONException e) {
            Log.e("File loading error", e.getMessage());
            throw new LevelLoadingException(e.getMessage());
        }

    }
    return levelSets;

}

From source file:com.adobe.aem.demomachine.gui.AemDemoUtils.java

public static void collectInputStreams(File dir, List<FileInputStream> foundStreams, boolean includeSubFolders,
        boolean includeHiddenFiles) {

    File[] fileList = dir.listFiles();
    Arrays.sort(fileList, // Need in reproducible order
            new Comparator<File>() {
                public int compare(File f1, File f2) {
                    return f1.getName().compareTo(f2.getName());
                }// www .ja v a 2  s  .c  om
            });

    for (File f : fileList) {
        if (!includeHiddenFiles && f.getName().startsWith("."))
            continue;
        if (f.isDirectory() && !includeSubFolders)
            continue;
        if (f.isDirectory()) {
            collectInputStreams(f, foundStreams, includeSubFolders, includeHiddenFiles);
        } else {
            try {
                logger.debug(f.getAbsolutePath());
                foundStreams.add(new FileInputStream(f));
            } catch (FileNotFoundException e) {
                throw new AssertionError(e.getMessage() + ": file should never not be found!");
            }
        }
    }

}

From source file:com.CodeSeance.JSeance.CodeGenXML.XMLElements.Template.java

public static String run(File templateFile, File includesDir, File modelsDir, File targetDir,
        boolean ignoreReadOnlyOuputFiles, TemplateDependencies templateDependencies) {
    // Create a local logger for the static context
    Log log = com.CodeSeance.JSeance.CodeGenXML.Runtime.CreateLogger(Template.class);

    if (log.isInfoEnabled()) {
        log.info(String.format("Loading Template:[%s]", templateFile.toString()));
    }/*from  w  w w.j  av a  2  s. c  o  m*/

    // Load the default schema validator
    XMLLoader xmlLoader = XMLLoader.buildFromCodeTemplateSchema();

    // Loads the XML document
    Document document;
    try {
        InputStream inputStream = new FileInputStream(templateFile);
        document = xmlLoader.loadXML(inputStream);
    } catch (FileNotFoundException ex) {
        throw new RuntimeException(ExecutionError.INVALID_TEMPLATE_FILE.getMessage(templateFile.toString()),
                ex);
    } catch (SAXException ex) {
        throw new RuntimeException(
                ExecutionError.INVALID_TEMPLATE_XML.getMessage(templateFile.toString(), ex.getMessage()), ex);
    }

    // Load the object hierarchy from the XMLDocument
    Template template = new Template(document.getDocumentElement());

    if (log.isInfoEnabled()) {
        log.info("XMLSchema validated");
    }

    // Create a new ContextManager
    ContextManager contextManager = new ContextManager(includesDir, modelsDir, targetDir,
            ignoreReadOnlyOuputFiles, templateDependencies);

    try {
        // Enter and leave the context on the new template element
        template.onContextEnter(contextManager.getCurrentContext());
        template.onContextExit(contextManager.getCurrentContext());
    } finally {
        // dispose the context manager to release used resources
        contextManager.dispose();
    }

    return template.buffer.toString();
}

From source file:com.aurel.track.admin.customize.lists.BlobBL.java

/**
 * Download the icon content//from  w  w  w  .  j  ava2s  .  co m
 * 
 * @param iconBytes
 * @param request
 * @param reponse
 * @param fileName
 * @param inline
 */
public static void download(byte[] iconBytes, HttpServletRequest request, HttpServletResponse reponse,
        String fileName, boolean inline) {
    prepareResponse(request, reponse, fileName, Long.toString(iconBytes.length), inline);
    // open the file
    InputStream inputStream = null;
    OutputStream outputStream = null;
    try {
        // retrieve the file data
        inputStream = new BufferedInputStream(new ByteArrayInputStream(iconBytes));
        outputStream = reponse.getOutputStream();
        byte[] buffer = new byte[BUFFER_SIZE];
        int bytesRead = 0;
        while ((bytesRead = inputStream.read(buffer, 0, BUFFER_SIZE)) != -1) {
            outputStream.write(buffer, 0, bytesRead);
        }
    } catch (FileNotFoundException fnfe) {
        LOGGER.error("FileNotFoundException thrown " + fnfe.getMessage());
        LOGGER.debug(ExceptionUtils.getStackTrace(fnfe));
        return;
    } catch (Exception ioe) {
        LOGGER.error("Creating the input stream failed with  " + ioe.getMessage(), ioe);
        LOGGER.debug(ExceptionUtils.getStackTrace(ioe));
        return;
    } finally {
        // flush and close the streams
        if (inputStream != null) {
            try {
                inputStream.close();
            } catch (IOException e) {
            }
        }
        if (outputStream != null) {
            try {
                outputStream.flush();
                outputStream.close();
            } catch (IOException e) {
            }
        }
    }
}

From source file:net.minecraftforge.fml.common.asm.transformers.AccessTransformer.java

private static void processJar(File inFile, File outFile, AccessTransformer[] transformers) throws IOException {
    ZipInputStream inJar = null;/*from   ww w .ja v a 2  s. c o  m*/
    ZipOutputStream outJar = null;

    try {
        try {
            inJar = new ZipInputStream(new BufferedInputStream(new FileInputStream(inFile)));
        } catch (FileNotFoundException e) {
            throw new FileNotFoundException("Could not open input file: " + e.getMessage());
        }

        try {
            outJar = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(outFile)));
        } catch (FileNotFoundException e) {
            throw new FileNotFoundException("Could not open output file: " + e.getMessage());
        }

        ZipEntry entry;
        while ((entry = inJar.getNextEntry()) != null) {
            if (entry.isDirectory()) {
                outJar.putNextEntry(entry);
                continue;
            }

            byte[] data = new byte[4096];
            ByteArrayOutputStream entryBuffer = new ByteArrayOutputStream();

            int len;
            do {
                len = inJar.read(data);
                if (len > 0) {
                    entryBuffer.write(data, 0, len);
                }
            } while (len != -1);

            byte[] entryData = entryBuffer.toByteArray();

            String entryName = entry.getName();

            if (entryName.endsWith(".class") && !entryName.startsWith(".")) {
                ClassNode cls = new ClassNode();
                ClassReader rdr = new ClassReader(entryData);
                rdr.accept(cls, 0);
                String name = cls.name.replace('/', '.').replace('\\', '.');

                for (AccessTransformer trans : transformers) {
                    entryData = trans.transform(name, name, entryData);
                }
            }

            ZipEntry newEntry = new ZipEntry(entryName);
            outJar.putNextEntry(newEntry);
            outJar.write(entryData);
        }
    } finally {
        IOUtils.closeQuietly(outJar);
        IOUtils.closeQuietly(inJar);
    }
}

From source file:org.wso2.carbon.sample.http.Http.java

/**
 * Xml messages will be read from the given filepath and stored in the array list (messagesList)
 *
 * @param filePath Text file to be read/*from w  ww  .jav  a  2 s.  c  om*/
 */
private static void readMsg(String filePath) {
    try {
        String line;
        bufferedReader = new BufferedReader(new FileReader(filePath));
        while ((line = bufferedReader.readLine()) != null) {
            if ((line.equals(asterixLine.trim()) && !"".equals(message.toString().trim()))) {
                messagesList.add(message.toString());
                message = new StringBuffer("");
            } else {
                message = message.append(String.format("\n%s", line));
            }
        }
        if (!"".equals(message.toString().trim())) {
            messagesList.add(message.toString());
        }
    } catch (FileNotFoundException e) {
        log.error("Error in reading file " + filePath, e);
    } catch (IOException e) {
        log.error("Error in reading file " + filePath, e);
    } finally {
        try {
            if (bufferedReader != null) {
                bufferedReader.close();
            }
        } catch (IOException e) {
            log.error("Error occurred when closing the file : " + e.getMessage(), e);
        }
    }
}

From source file:es.tekniker.framework.ktek.commons.mng.db.CommonsLoadFile.java

public static List<String> readFile(String filename, boolean print) {
    List<String> data = new ArrayList<String>();

    BufferedReader br = null;//from w  ww  .  ja  v a  2s  .  c om
    String line = null;
    //StringBuilder sb = new StringBuilder();
    try {

        br = new BufferedReader(new FileReader(filename));

        line = br.readLine();
        if (line != null) {
            data.add(line);
            for (String retval : line.split(";")) {
                if (print)
                    System.out.print(retval + "  ");
            }
        }
        System.out.println();
        while (line != null) {
            //sb.append(line);
            //sb.append(System.lineSeparator());
            line = br.readLine();
            if (line != null) {
                if (line.equals("") == false)
                    data.add(line);

                for (String retval : line.split(";")) {
                    if (print)
                        System.out.print(retval + "  ");
                }
                if (print)
                    System.out.println();
            }
        }
        //           String everything = sb.toString();

    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        log.debug("FileNotFoundException " + filename + " " + e.getMessage());
        e.printStackTrace();
    } catch (IOException e) {
        log.debug("IOException " + filename + " " + e.getMessage());
        // TODO Auto-generated catch block
        e.printStackTrace();
    } finally {
        try {
            br.close();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();

            log.debug("IOException closing StringBuilder " + filename + " " + e.getMessage());
        }
    }

    return data;

}