List of usage examples for java.io FileNotFoundException getMessage
public String getMessage()
From source file:com.lenovo.tensorhusky.common.utils.ProcfsBasedProcessTree.java
/** * Update memory related information//from www . ja v a2 s . com * * @param pInfo * @param procfsDir */ private static void constructProcessSMAPInfo(ProcessTreeSmapMemInfo pInfo, String procfsDir) { BufferedReader in = null; InputStreamReader fReader = null; try { File pidDir = new File(procfsDir, pInfo.getPid()); File file = new File(pidDir, SMAPS); if (!file.exists()) { return; } fReader = new InputStreamReader(new FileInputStream(file), Charset.forName("UTF-8")); in = new BufferedReader(fReader); ProcessSmapMemoryInfo memoryMappingInfo = null; List<String> lines = IOUtils.readLines(in); for (String line : lines) { line = line.trim(); try { Matcher address = ADDRESS_PATTERN.matcher(line); if (address.find()) { memoryMappingInfo = new ProcessSmapMemoryInfo(line); memoryMappingInfo.setPermission(address.group(4)); pInfo.getMemoryInfoList().add(memoryMappingInfo); continue; } Matcher memInfo = MEM_INFO_PATTERN.matcher(line); if (memInfo.find()) { String key = memInfo.group(1).trim(); String value = memInfo.group(2).replace(KB, "").trim(); if (LOG.isDebugEnabled()) { LOG.debug("MemInfo : " + key + " : Value : " + value); } memoryMappingInfo.setMemInfo(key, value); } } catch (Throwable t) { LOG.warn("Error parsing smaps line : " + line + "; " + t.getMessage()); } } } catch (FileNotFoundException f) { LOG.error(f.getMessage()); } catch (IOException e) { LOG.error(e.getMessage()); } catch (Throwable t) { LOG.error(t.getMessage()); } finally { IOUtils.closeQuietly(in); } }
From source file:com.websqrd.catbot.setting.CatbotSettings.java
private static int setUseRepo0(String useId, Element root) { Element ele = root.getChild("repository"); ele.setText(useId);/*from ww w . ja v a 2s . c om*/ String catbotConfigFileDir = getKey(catbotConfigFilename); XMLOutputter xmlOut = new XMLOutputter(); FileOutputStream fos = null; try { fos = new FileOutputStream(new File(catbotConfigFileDir)); xmlOut.output(root.getDocument(), fos); } catch (FileNotFoundException e) { logger.error(e.getMessage(), e); return 3; } catch (IOException e) { logger.error(e.getMessage(), e); return 3; } finally { try { fos.close(); } catch (IOException e) { logger.error(e.getMessage(), e); } } return 0; }
From source file:com.websqrd.catbot.setting.CatbotSettings.java
private static int updateRepo0(String id, Element root, String key, String value) { List fields = root.getChildren("entry"); String repoFilename = "repository_" + id + ".xml"; String repoConfigFileDir = getKey(repoFilename); boolean isExists = false; for (int i = 0; i < fields.size(); i++) { Element el = (Element) fields.get(i); if (key.equalsIgnoreCase(el.getAttributeValue("key"))) { isExists = true;/*w w w . j a v a 2 s .c om*/ el.setText(value); logger.debug("el key = {}, value = {}", key, value); } } if (isExists == false) {//?? . root.getChildren().add(new Element("entry").setAttribute("key", key).setText(value)); logger.debug("append new el key = {}, value = {}", key, value); } XMLOutputter xmlOut = new XMLOutputter(); FileOutputStream fos = null; try { fos = new FileOutputStream(new File(repoConfigFileDir)); xmlOut.output(root.getDocument(), fos); } catch (FileNotFoundException e) { logger.error(e.getMessage(), e); return 3; } catch (IOException e) { logger.error(e.getMessage(), e); return 3; } finally { try { fos.close(); } catch (IOException e) { logger.error(e.getMessage(), e); } } return 0; }
From source file:edu.du.penrose.systems.fedoraApp.util.MetsBatchFileSplitter.java
/** * Split a file with multiple METS sections into separate files each containing * a single METS record. The input file must contain one or more multiple * <mets></mets> elements (sections). if true a OBJID must exist in every <mets> * element, this will become the file name. Otherwise a unique file name is * generated. Return true if the <batch update="true"> is set in the batch file other * wise return false (defaults to new file being ingested ). * //from w ww . j av a 2 s. c o m * @see edu.du.penrose.systems.fedoraApp.batchIngest.bus.BatchIngestThreadManager#setBatchSetStatus(String, String) * @param threadStatus this object receives status updates while splitting the file. * @param inFile file to split * @param metsNewDirectory directory containing METS for new objects. * @param metsUpdatesDirectory directory containing METS for existing objects. * @param nameFileFromOBJID if true a OBJID must exist in every <mets> element, this will become the file name. Otherwise a unique file name is * generated * @param checkValidDiscoveryID if true check that the OBJID contains a valid discovery ID * * @throws Exception on any IO error. */ static public void splitMetsBatchFile(BatchIngestOptions ingestOptions, ThreadStatusMsg threadStatus, File inFile, String metsNewDirectory, String metsUpdatesDirectory, boolean nameFileFromOBJID) throws FatalException { String metsDirectory = null; // will get set to either the new directory or the updates directory. String batchCreationDate = null; StringBuffer batchDescription = null; boolean isUpdate = false; ingestDataType dataType = ingestDataType.ALL; FileInputStream batchFileInputStream; try { batchFileInputStream = new FileInputStream(inFile); } catch (FileNotFoundException e) { throw new FatalException(e.getMessage()); } DataInputStream batchFileDataInputStream = new DataInputStream(batchFileInputStream); BufferedReader batchFileBufferedReader = new BufferedReader( new InputStreamReader(batchFileDataInputStream)); File outFile = null; FileOutputStream metsFileOutputStream = null; BufferedWriter metsBufferedWriter = null; String oneLine = null; String documentType = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; int fileCount = 0; boolean isBatchFile = false; try { boolean done = false; while (batchFileBufferedReader.ready() && !done) { oneLine = batchFileBufferedReader.readLine(); if (oneLine.contains("<?xml version")) { documentType = oneLine; } if (oneLine.contains(BATCH_ELEMENT) || oneLine.contains(BATCH_ELEMENT_MARKER)) { isBatchFile = true; if (oneLine.contains("version=" + QUOTE + 2 + QUOTE) || oneLine.contains("version=" + APOST + 2 + APOST)) { splitMetsBatchFile_version_2(ingestOptions, threadStatus, inFile, metsNewDirectory, metsUpdatesDirectory, nameFileFromOBJID, null, null, null, null); done = true; } else { splitMetsBatchFile_version_1(ingestOptions, threadStatus, inFile, metsNewDirectory, metsUpdatesDirectory, nameFileFromOBJID); done = true; } } } // while } catch (NullPointerException e) { String errorMsg = "Unable to split files, Permature end of file: Corrupt:" + inFile.toString() + " ?"; throw new FatalException(errorMsg); } catch (Exception e) { String errorMsg = "Unable to split files: " + e.getMessage(); logger.fatal(errorMsg); throw new FatalException(errorMsg); } finally { try { if (batchFileBufferedReader != null) { batchFileBufferedReader.close(); } if (metsBufferedWriter != null) { metsBufferedWriter.close(); } if (!isBatchFile) { throw new FatalException("ERROR: missing <batch> element!"); } } catch (IOException e) { throw new FatalException(e.getMessage()); } } }
From source file:com.pcms.temp.generate.MarkeWrite.java
public void save(String savePath, String templateName, String templateEncoding, Map<?, ?> root) { String path = savePath + "/" + templateName + ".html"; FileUtil.delete(path);//w ww .j ava 2s . c o m try { File file = FileUtil.createFile(path); Writer out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file))); this.processTemplate(templateName, templateEncoding, root, out); } catch (FileNotFoundException ex) { _log.error(ex.getMessage()); } catch (IOException ex) { _log.error(ex.getMessage()); } }
From source file:org.zilverline.extractors.TestRTFExtractor.java
public void testGetContentAsInputStream() { try {//from www .ja va 2s . com RTFExtractor tex = new RTFExtractor(); InputStream is = new FileInputStream("test\\data\\test.rtf"); String txt = tex.getContent(is); assertNotNull(txt); log.debug(txt.trim()); assertTrue(txt.length() > 0); assertTrue(txt.trim().startsWith("This is a sample of some RTF text.")); assertTrue(StringUtils.countOccurrencesOf(txt, "underlined") > 0); } catch (FileNotFoundException e) { fail(e.getMessage()); } }
From source file:org.zilverline.extractors.TestTextExtractor.java
public void testGetContentAsInputStream() { try {/*ww w. jav a 2s .co m*/ TextExtractor tex = new TextExtractor(); InputStream is = new FileInputStream("test\\data\\readme"); String txt = tex.getContent(is); assertNotNull(txt); log.debug(txt); assertTrue(txt.length() > 0); assertTrue(txt.startsWith("Dit is een test in een TEXT document.")); assertTrue(StringUtils.countOccurrencesOf(txt, "test") > 0); } catch (FileNotFoundException e) { fail(e.getMessage()); } }
From source file:org.zilverline.extractors.TestPDFExtractor.java
public void testGetContentAsInputStream() { try {//from w w w . jav a 2 s .c o m PDFExtractor tex = new PDFExtractor(); InputStream is = new FileInputStream("test\\data\\test.pdf"); String txt = tex.getContent(is); assertNotNull(txt); log.debug(txt.trim()); assertTrue(txt.length() > 0); assertTrue(txt.trim().startsWith("Dit is een test in een PDF document.")); assertTrue(StringUtils.countOccurrencesOf(txt, "test") > 0); } catch (FileNotFoundException e) { fail(e.getMessage()); } }
From source file:org.zilverline.extractors.TestPowerPointExtractor.java
public void testGetContentAsInputStream() { try {//from ww w. java 2 s .c o m PowerPointExtractor tex = new PowerPointExtractor(); InputStream is = new FileInputStream("test\\data\\test.ppt"); String txt = tex.getContent(is); assertNotNull(txt); log.debug(txt.trim()); assertTrue(txt.length() > 0); assertTrue(txt.trim().startsWith("Test Dit is een test in een powerpoint document.")); assertTrue(StringUtils.countOccurrencesOf(txt, "test") > 0); } catch (FileNotFoundException e) { fail(e.getMessage()); } }
From source file:org.zilverline.extractors.TestWordExtractor.java
public void testGetContentAsInputStream() { try {/* w w w . ja v a2 s . c o m*/ WordExtractor tex = new WordExtractor(); InputStream is = new FileInputStream("test\\data\\test.doc"); String txt = tex.getContent(is); assertNotNull(txt); log.debug(txt.trim()); assertTrue(txt.length() > 0); assertTrue(txt.trim().startsWith("Dit is een test in een WORD document.")); assertTrue(StringUtils.countOccurrencesOf(txt, "test") > 0); } catch (FileNotFoundException e) { fail(e.getMessage()); } }