List of usage examples for java.io FileNotFoundException FileNotFoundException
public FileNotFoundException(String s)
FileNotFoundException
with the specified detail message. From source file:com.healthmarketscience.jackcess.impl.CompoundOleUtil.java
/** * Gets a DocumentEntry from compound storage based on a fully qualified, * encoded entry name.//from w ww . j a v a 2 s . co m * * @param entryName fully qualified, encoded entry name * @param dir root directory of the compound storage * * @return the relevant DocumentEntry * @throws FileNotFoundException if the entry does not exist * @throws IOException if some other io error occurs */ public static DocumentEntry getDocumentEntry(String entryName, DirectoryEntry dir) throws IOException { // split entry name into individual components and decode them List<String> entryNames = new ArrayList<String>(); for (String str : entryName.split(ENTRY_SEPARATOR)) { if (str.length() == 0) { continue; } entryNames.add(decodeEntryName(str)); } DocumentEntry entry = null; Iterator<String> iter = entryNames.iterator(); while (iter.hasNext()) { org.apache.poi.poifs.filesystem.Entry tmpEntry = dir.getEntry(iter.next()); if (tmpEntry instanceof DirectoryEntry) { dir = (DirectoryEntry) tmpEntry; } else if (!iter.hasNext() && (tmpEntry instanceof DocumentEntry)) { entry = (DocumentEntry) tmpEntry; } else { break; } } if (entry == null) { throw new FileNotFoundException("Could not find document " + entryName); } return entry; }
From source file:net.ovres.tuxcourser.TarStreamCourseInput.java
/** * Create a stream corresponding to the given file. * This stream should be closed when it is not needed * any more.//from www . ja v a 2 s.c om * * This file should be in the main directory, but this * is not validated. * * @returns stream corresponding to the given file. */ public InputStream getInputStream(String filename) throws FileNotFoundException, IOException { String altFilename = filename.replaceAll(".rgb$", ".png"); // First, get a stream we can use... InputStream in = new FileInputStream(source); // Next, decompress it if possible... in = new UncompressedInputStream(in); // Now the tar file... TarArchiveInputStream tar = new TarArchiveInputStream(in); ArchiveEntry entry = null; ArchiveEntry e; e = tar.getNextEntry(); while (entry == null && e != null) { if ((e.getName().endsWith(filename) || e.getName().endsWith(altFilename)) && e.getName().indexOf(".xvpics") == -1) { entry = e; } else { e = tar.getNextEntry(); } } if (entry == null) { tar.close(); throw new FileNotFoundException("File not found in " + source + ": " + filename); } logger.fine("Using: " + entry.getName()); // We could just return tar at this point... // But it's a bit nicer to clean up the tar file // immediately, and return a byte array stream instead. int size = (int) (entry.getSize()); byte[] b = new byte[size]; int num = tar.read(b, 0, size); if (num < size) { logger.warning("Tried to read " + size + " bytes, got " + num); } ByteArrayInputStream intemp; intemp = new ByteArrayInputStream(b); // finally, clean up the various input streams tar.close(); in.close(); return intemp; }
From source file:projekat.rest_client.RestTemplateFactory.java
@Override public void afterPropertiesSet() { fillTypesForRestService();//from w ww . java 2 s . c o m //za potrebe testirnja if (rest_keystore == null || "".equals(rest_keystore)) { rest_keystore = "/etc/keystores/nst2.jks"; rest_keystore_password = "changeit"; res_host_port = "8443"; rest_hostname = "localhost"; } InputStream keyStoreInputStream = null; try { keyStoreInputStream = new FileInputStream(rest_keystore); if (keyStoreInputStream == null) { throw new FileNotFoundException(""); } final KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType()); try { trustStore.load(keyStoreInputStream, rest_keystore_password.toCharArray()); } finally { keyStoreInputStream.close(); } SSLContext sslcontext = SSLContexts.custom() .loadTrustMaterial(trustStore, new TrustSelfSignedStrategy()).build(); // Allow TLSv1 protocol only SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslcontext, new String[] { "TLSv1" }, null, SSLConnectionSocketFactory.getDefaultHostnameVerifier()); CloseableHttpClient httpClient = HttpClients.custom().setSSLSocketFactory(sslsf).build(); auth = new HttpComponentsClientHttpRequestFactoryBasicAuth( new HttpHost(rest_hostname, Integer.parseInt(res_host_port), "https"), httpClient); auth.setConnectTimeout(60000); auth.setReadTimeout(180000); restTemplate = new RestTemplate(auth); } catch (KeyStoreException | IOException | NoSuchAlgorithmException | CertificateException | KeyManagementException ex) { Logger.getLogger(RestTemplateFactory.class.getName()).log(Level.SEVERE, null, ex); } finally { try { keyStoreInputStream.close(); } catch (Exception ex) { Logger.getLogger(RestTemplateFactory.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:net.javacoding.queue.DiskQueue.java
/** Create a new {@link DiskQueue} which creates its temporary files in a * given directory, with a given prefix, and reuse any prexisting backing * files as directed.//from ww w. j av a2 s.co m * * @param dir the directory in which to create the data files * @param prefix * @param reuse whether to reuse any existing backing files * @throws IOException if we cannot create an appropriate file */ public DiskQueue(File dir, String prefix, boolean reuse) throws IOException { if (dir == null || prefix == null) { throw new FileNotFoundException("null arguments not accepted"); } length = 0; this.prefix = prefix; this.scratchDir = dir; this.reuse = reuse; // test minimally if supplied disk paths are sensible if (dir.exists() == false) { if (dir.mkdirs() == false) { throw new FileNotFoundException("unable to create scratch directory"); } } // TODO: test more extensively, given lazy disk use, if queue // will be be viable? }
From source file:com.redhat.ipaas.api.v1.rest.ReadApiClientData.java
/** * * @param fileName// w w w . j a va 2s. c o m * @return * @throws JsonParseException * @throws JsonMappingException * @throws IOException */ public List<ModelData> readDataFromFile(String fileName) throws JsonParseException, JsonMappingException, IOException { InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(fileName); // System.out.println(1 + " " + Thread.currentThread().getContextClassLoader().getResourceAsStream("deployment.json")); // System.out.println(1 + " " + Thread.currentThread().getContextClassLoader().getResourceAsStream("/deployment.json")); // System.out.println(2 + " " + Thread.currentThread().getContextClassLoader().getResourceAsStream("com/redhat/ipaas/rest/deployment.json")); // System.out.println(3 + " " + Thread.currentThread().getContextClassLoader().getResourceAsStream("/com/redhat/ipaas/rest/deployment.json")); // System.out.println(4 + " " + this.getClass().getResourceAsStream("deployment.json")); // System.out.println(4 + " " + this.getClass().getResourceAsStream("/deployment.json")); // System.out.println(5 + " " + this.getClass().getResourceAsStream("com/redhat/ipaas/rest/deployment.json")); // System.out.println(6 + " " + this.getClass().getResourceAsStream("/com/redhat/ipaas/rest/deployment.json")); // System.out.println(7 + " " + ClassLoader.getSystemClassLoader().getResourceAsStream("deployment.json")); // System.out.println(8 + " " + ClassLoader.getSystemClassLoader().getResourceAsStream("com/redhat/ipaas/rest/deployment.json")); // System.out.println(9 + " " + ClassLoader.getSystemClassLoader().getResourceAsStream("/com/redhat/ipaas/rest/deployment.json")); // System.out.println(10 + " " + this.getClass().getClassLoader().getResourceAsStream("deployment.json")); // System.out.println(10 + " " + this.getClass().getClassLoader().getResourceAsStream("/deployment.json")); // System.out.println(11 + " " + this.getClass().getClassLoader().getResourceAsStream("com/redhat/ipaas/rest/deployment.json")); // System.out.println(12 + " " + this.getClass().getClassLoader().getResourceAsStream("/com/redhat/ipaas/rest/deployment.json")); //InputStream is = this.getClass().getClassLoader().getResourceAsStream(fileName); if (is == null) throw new FileNotFoundException("Cannot find file " + fileName + " on classpath"); ObjectMapper mapper = new ObjectMapper(); return mapper.readValue(is, new TypeReference<List<ModelData>>() { }); }
From source file:edu.cornell.mannlib.vitro.webapp.config.RevisionInfoSetup.java
private BufferedReader openRevisionInfoReader(ServletContext context) throws FileNotFoundException { InputStream stream = context.getResourceAsStream(RESOURCE_PATH); if (stream == null) { throw new FileNotFoundException("Can't find a resource in the webapp at '" + RESOURCE_PATH + "'."); } else {//from w w w. j a v a 2s . c om return new BufferedReader(new InputStreamReader(stream)); } }
From source file:com.aliyun.odps.ship.common.Util.java
public static void checkSession(String sid) throws FileNotFoundException { if (sid == null) { return;//from w w w. j a v a 2 s .c o m } File f = new File(getSessionDir(sid)); if (!f.exists()) { throw new FileNotFoundException(Constants.ERROR_INDICATOR + "session '" + sid + "' not found"); } }
From source file:fr.cedrik.util.ExtendedProperties.java
/** * Loads the given file from the filesystem or the classpath. * * @see Properties#load(InputStream)/*from w w w .j a v a 2s .c o m*/ */ public void load(String file) throws IOException { InputStream in = null; // load from filesystem try { in = new FileInputStream(new File(file)); } catch (FileNotFoundException ignore) { } if (in != null) { try { load(in); // } catch (IOException e) { // throw new IllegalStateException("Error while loading file from filesystem: " + file, e); } finally { IOUtils.closeQuietly(in); } } else { if (Thread.currentThread().getContextClassLoader() != null) { in = Thread.currentThread().getContextClassLoader().getResourceAsStream(file); } if (in == null) { in = this.getClass().getResourceAsStream(file); } if (in != null) { // load from classpath try { load(in); // } catch (IOException e) { // throw new IllegalStateException("Error while loadind file from classpath: " + file, e); } finally { IOUtils.closeQuietly(in); } } else { // error throw new FileNotFoundException("Can not find file neither in filesystem nor classpath: " + file); } } }
From source file:org.jboss.windup.WindupReportEngine.java
/** * <p>/* ww w .ja v a 2 s. co m*/ * Generates a report for the given input to the given output * </p> * * @param input * generate a report from this input * @param output * generate the report to this location * * @throws IOException * this can happen when doing file stuff */ public void generateReport(File input, File output) throws IOException { if (!input.exists()) { throw new FileNotFoundException("Nothing exists at the given path: " + input); } /* if output specified use that * else create directory at same level as input with -doc appended */ File actualOutput; if (output != null) { actualOutput = output; } else { String outputPathLoc = StringUtils.substringBeforeLast(input.getAbsolutePath(), "."); outputPathLoc += "-" + StringUtils.substringAfterLast(input.getAbsolutePath(), ".") + "-doc"; //create output path... actualOutput = new File(outputPathLoc); if (LOG.isInfoEnabled()) { LOG.info("Creating output path: " + actualOutput.getAbsolutePath()); LOG.info(" - To overwrite this in the future, use the -output parameter."); } } //generate the meta ArchiveMeta meta = this.metaEngine.getArchiveMeta(input, actualOutput); if (LOG.isDebugEnabled()) { LOG.debug("Generate report for meta generated for '" + input + "' to '" + actualOutput + "'"); } //generate the report reportEngine.process(meta, actualOutput); }
From source file:mesclasses.model.FileConfigurationManager.java
public static void autoDetect() throws FileNotFoundException { System.out.println("Auto dtection de la configuration"); CUSTOM_INSTALL_FILE = new File("../mesclasses_install.properties"); try {//from w ww . j a v a 2 s. c o m if (!CUSTOM_INSTALL_FILE.exists()) { CUSTOM_INSTALL_FILE.createNewFile(); } else { readCustomProperties(CUSTOM_INSTALL_FILE); } } catch (IOException e) { System.out.println(e); } System.out.println("Dtection des paths de stockage"); String workingDirectory; String customStoragePath = customProperties.getProperty(STORAGE_PATH_PROP); if (customStoragePath == null) { System.out.println("Pas de configuration customise"); workingDirectory = getDefaultLocalDirectory(); customProperties.setProperty(STORAGE_PATH_PROP, workingDirectory); writeCustomProperties(CUSTOM_INSTALL_FILE); } else { workingDirectory = customStoragePath; } if (workingDirectory == null) { throw new FileNotFoundException("No default configuration directory found"); } setUserHome(workingDirectory); }