Example usage for java.io FileNotFoundException FileNotFoundException

List of usage examples for java.io FileNotFoundException FileNotFoundException

Introduction

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

Prototype

public FileNotFoundException(String s) 

Source Link

Document

Constructs a FileNotFoundException with the specified detail message.

Usage

From source file:fm.last.moji.local.LocalMojiFile.java

@Override
public void rename(String newKey) throws IOException {
    if (!file.exists()) {
        throw new FileNotFoundException(file.getCanonicalPath());
    }//from w  ww  .  ja  v a2s  .c  o m
    File destination = new File(baseDir, namingStrategy.newFileName(domain, newKey, storageClass));
    file.renameTo(destination);
    file = destination;
    key = newKey;
}

From source file:eu.cloud4soa.soa.jaxrs.test.ApplicationDeploymentTest.java

public void deployApplication() throws FileNotFoundException {
    //        final String BASE_URI = "http://localhost:8080/frontend-dashboard-0.0.1-SNAPSHOT/services/REST/ApplicationDeploymentRS/deployApplication";
    final String BASE_URI = "http://localhost:8080/cloud4soa.soa/services/REST/ApplicationDeploymentRS/deployApplication";

    WebClient client = WebClient.create(BASE_URI);
    client.type("multipart/mixed").accept(MediaType.TEXT_PLAIN);
    //        ContentDisposition cd = new ContentDisposition("attachment;filename=image.jpg");
    //        Attachment att = new Attachment("root", imageInputStream, cd);

    //        ApplicationDeployment applicationDeploymentRS = (ApplicationDeployment) JAXRSClientFactory.create("http://localhost:8080/books", ApplicationDeployment.class);
    //        WebClient.client(applicationDeploymentRS).type("multipart/mixed");

    URL fileURL = this.getClass().getClassLoader().getResource("SimpleWar.war");
    if (fileURL == null)
        throw new FileNotFoundException("SimpleWar.war");

    ByteArrayOutputStream bas = new ByteArrayOutputStream();

    File file = new File(fileURL.getPath());
    file.length();/*ww w. j  a  va 2 s  . c  o m*/
    FileInputStream fis = new FileInputStream(file);
    BufferedInputStream bis = new BufferedInputStream(fis);
    DataInputStream dis = new DataInputStream(bis);

    //Calculate digest from InputStream
    //        InputStream tempIs = new FileInputStream(file);
    String tempFileDigest = null;
    try {
        FileInputStream tempFis = new FileInputStream(file);
        tempFileDigest = DigestUtils.sha256Hex(tempFis);
    } catch (IOException ex) {
        Logger.getLogger(ApplicationDeploymentTest.class.getName()).log(Level.SEVERE, null, ex);
    }

    //        JSONObject applicationInstanceJsonObj=new JSONObject();
    //        try {
    //            applicationInstanceJsonObj.put("acronym","App1");
    //            applicationInstanceJsonObj.put("applicationcode","001");
    //            applicationInstanceJsonObj.put("programminglanguage","Java");
    //        } catch (JSONException ex) {
    //            ex.printStackTrace();
    //        }
    //
    //        System.out.println(applicationInstanceJsonObj);

    JSONObject applicationInstanceJsonObj = new JSONObject();
    try {
        applicationInstanceJsonObj.put("acronym", "SimpleWar");
        applicationInstanceJsonObj.put("archiveFileName", "app");
        applicationInstanceJsonObj.put("archiveExtensionName", ".war");
        applicationInstanceJsonObj.put("digest", tempFileDigest);
        applicationInstanceJsonObj.put("sizeQuantity", file.length());
        applicationInstanceJsonObj.put("version", "2");
        //            applicationInstanceJsonObj.put("","");
    } catch (JSONException ex) {
        Logger.getLogger(ApplicationDeploymentTest.class.getName()).log(Level.SEVERE, null, ex);
    }

    System.out.println(applicationInstanceJsonObj);

    JSONObject paaSInstanceJsonObj = new JSONObject();
    try {
        //            paaSInstanceJsonObj.put("providerTitle","CloudBees");
        paaSInstanceJsonObj.put("providerTitle", "Beanstalk");
    } catch (JSONException ex) {
        Logger.getLogger(ApplicationDeploymentTest.class.getName()).log(Level.SEVERE, null, ex);
    }

    System.out.println(paaSInstanceJsonObj);

    ProviderFactory.getSharedInstance().registerUserProvider(new JSONProvider());
    // POST the request
    //        Response response = applicationDeploymentRS.deployApplication(dis, applicationInstanceJsonObj, paaSInstanceJsonObj);
    Attachment att1 = new Attachment("applicationInstance", "application/json",
            applicationInstanceJsonObj.toString());
    Attachment att2 = new Attachment("paaSInstance", "application/json", paaSInstanceJsonObj.toString());
    Attachment att3 = new Attachment("applicationArchive", "application/octet-stream", dis);
    List<Attachment> listAttch = new LinkedList<Attachment>();
    listAttch.add(att1);
    listAttch.add(att2);
    listAttch.add(att3);
    Response response = client.post(new MultipartBody(listAttch));
    if (Response.Status.fromStatusCode(response.getStatus()) == Response.Status.ACCEPTED)
        try {
            System.out.println(
                    "Response Status : " + IOUtils.readStringFromStream((InputStream) response.getEntity()));
        } catch (IOException ex) {
            Logger.getLogger(ApplicationDeploymentTest.class.getName()).log(Level.SEVERE, null, ex);
        }

    try {
        fis.close();
        bis.close();
        dis.close();
    } catch (IOException ex) {
        Logger.getLogger(ApplicationDeploymentTest.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:gov.nasa.ensemble.common.io.FileUtilities.java

/**
 * Strictly find the file in the plugin. If the file does not exist, an exception is thrown.
 * //from   www.j  a  v  a  2s  .  c  om
 * An alternative to this method is to use FileLocator.openStream, (preferred) or to call FileUtilities.copyToMetadata and then use paths relative to the metadata.
 * 
 * @param bundle
 * @param filename
 * @return File
 * @throws IOException
 * @deprecated use FileLocator.openStream(bundle, new Path(filename), null) instead
 */
@Deprecated
public static File findFileInPluginBundle(Bundle bundle, String filename) throws IOException {
    Path relativePath = new Path(filename);
    URL pluginRelativeURL = FileLocator.find(bundle, relativePath, null);
    if (pluginRelativeURL == null) {
        throw new FileNotFoundException(
                "File not found: " + filename + " in bundle " + bundle.getSymbolicName());
    }
    URL fileURL = FileLocator.resolve(pluginRelativeURL);
    File file = new File(fileURL.getFile());
    if (file.exists()) {
        return file;
    }
    InputStream inputStream = FileLocator.openStream(bundle, relativePath, false);
    if (inputStream == null) {
        throw new FileNotFoundException(
                "File not found: " + filename + " in bundle " + bundle.getSymbolicName());
    }
    file = createTempFile("bundleFile", "");
    FileOutputStream outputStream = new FileOutputStream(file);
    try {
        byte[] buffer = new byte[1024 * 1024];
        while (true) {
            int len = inputStream.read(buffer);
            if (len <= 0) {
                break;
            }
            outputStream.write(buffer, 0, len);
        }
    } finally {
        inputStream.close();
        outputStream.close();
    }
    return file;
}

From source file:com.vaadin.sass.testcases.scss.AbstractDirectoryScanningSassTests.java

private File getSassLangResourceFile(String resourceName) throws IOException, URISyntaxException {
    String base = "/scss/";
    String fullResourceName = base + resourceName;
    URL res = getResourceURL(fullResourceName);
    if (res == null) {
        throw new FileNotFoundException(
                "Resource " + resourceName + " not found (tried " + fullResourceName + ")");
    }/*from www .  j a  v  a  2 s . c o  m*/
    return new File(res.toURI());
}

From source file:com.git.original.common.config.XMLFileConfigDocument.java

protected ConfigNode doLoad(String configFilePath) throws Exception {
    InputStream in = null;//  w w  w  .j  ava  2  s.  c  om
    try {
        File confFile = new File(configFilePath);
        if (!confFile.isAbsolute()) {
            confFile = new File(this.getHmailHome(), configFilePath);
        }
        if (!confFile.exists()) {
            throw new FileNotFoundException("path:" + confFile);
        }

        String currentDigest = confFile.lastModified() + ";" + confFile.length();
        if (currentDigest.equals(this.configFileDigest)) {
            // ??, ?
            return null;
        }

        in = new FileInputStream(confFile);

        SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
        NodeBuilder nb = new NodeBuilder();
        parser.parse(in, nb);
        ConfigNode result = nb.getRootNode();

        if (result != null) {
            try {
                this.dbVersion = result.getAttribute(CONF_DOC_ATTRIBUTE_DB_VERSION);
            } catch (Exception ex) {
                this.dbVersion = null;
            }

            try {
                String str = result.getAttribute(CONF_DOC_ATTRIBUTE_IGNORE_DB);
                if (StringUtils.isEmpty(str)) {
                    this.ignoreDb = false;
                } else {
                    this.ignoreDb = Boolean.parseBoolean(str);
                }
            } catch (Exception ex) {
                this.ignoreDb = false;
            }

            try {
                String tmp = result.getAttribute(CONF_DOC_ATTRIBUTE_SCAN_PERIOD);
                if (StringUtils.isEmpty(tmp)) {
                    this.scanMillis = null;
                } else {
                    this.scanMillis = ConfigNode.textToNumericMillis(tmp.trim());
                }
            } catch (Exception ex) {
                this.scanMillis = null;
            }
        }

        LOG.debug("Load config from local dir success, file:{}", configFilePath);
        return result;
    } finally {
        if (in != null) {
            try {
                in.close();
            } catch (IOException e) {
                // ignore exception
            }
        }
    }
}

From source file:com.cedarsoft.serialization.serializers.jackson.registry.DirBasedObjectsAccess.java

@Nonnull
public File getDirectory(@Nonnull String id) throws FileNotFoundException {
    File directory = getDirInternal(id);
    if (!directory.exists()) {
        throw new FileNotFoundException("No dir found for <" + id + "> at " + directory.getAbsolutePath());
    }//from   w w w . j  a  v  a2  s . c om
    return directory;
}

From source file:jp.ac.u.tokyo.m.resource.ResourceLoadUtil.java

/**
 * This method read Properties in the same package. <br>
 * If the file does not exist, throws exception. <br>
 * <br>/*from   w  ww . j  av a 2  s  .  c o m*/
 * aFileName ????? Properties ???? <br>
 * ?????? <br>
 */
public static Properties loadNecessaryPackagePrivateProperties(Class<?> aClass, String aFileName) {
    try {
        return loadProperties(aClass, aFileName, aClass.getResourceAsStream(aFileName));
    } catch (NullPointerException e) {
        throw new RuntimeException(new FileNotFoundException(aClass.getPackage() + "." + aFileName));
    }
}

From source file:com.stacksync.desktop.util.FileUtil.java

public static List<File> getRecursiveFileList(File root, boolean includeDirectories)
        throws FileNotFoundException {
    if (!root.isDirectory() || !root.canRead() || !root.exists()) {
        throw new FileNotFoundException("Invalid directory " + root);
    }//from w  w  w  .  j  a v a2s . c  o m

    List<File> result = getRecursiveFileListNoSort(root, includeDirectories);
    Collections.sort(result);

    return result;
}

From source file:at.bitfire.ical4android.AndroidTask.java

public Task getTask() throws FileNotFoundException, CalendarStorageException {
    if (task != null)
        return task;

    try {/*from ww w.j av a 2 s .c  om*/
        task = new Task();
        @Cleanup
        final Cursor cursor = taskList.provider.client.query(taskSyncURI(), null, null, null, null);
        if (cursor != null && cursor.moveToFirst()) {
            ContentValues values = new ContentValues(cursor.getColumnCount());
            DatabaseUtils.cursorRowToContentValues(cursor, values);
            populateTask(values);
        } else
            throw new FileNotFoundException("Couldn't load details of task #" + id);
        return task;
    } catch (RemoteException e) {
        throw new CalendarStorageException("Couldn't read locally stored event", e);
    } catch (ParseException e) {
        throw new CalendarStorageException("Couldn't parse locally stored event", e);
    }
}

From source file:edu.odu.cs.cs350.yellow1.file.FileMover.java

/**
 * Call this method once before any operations to
 * @return true if setup was complete/*from  w  ww .j  a va  2s. co m*/
 * @throws FileNotFoundException
 */
public boolean setUp() throws FileNotFoundException {
    if (!origin.exists()) {
        logger.error("FileMover: The Origin direcory does not exists path= " + origin.getAbsolutePath());
        throw new FileNotFoundException(
                "FileMover: The Origin direcory does not exists path= " + origin.getAbsolutePath());
    }
    if (!target.exists()) {
        logger.error("FileMover: The target file does not exists path= " + target.getAbsolutePath());
        throw new FileNotFoundException(
                "FileMover: The target file does not exists path= " + target.getAbsolutePath());
    }
    try {
        restoreTarget = Files.toByteArray(target);
    } catch (IOException e) {
        logger.error(e.getMessage());
        return false;
    }
    return true;
}