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:com.formkiq.core.util.Resources.java

/**
 * Gets a file from classpath as bytes./*from  ww w  . j a  va2s  .  c o  m*/
 * @param file {@link String}
 * @return {@link String}
 * @throws IOException IOException
 */
public static String getResourceAsString(final String file) throws IOException {
    InputStream is = getResourceAsInputStream(file);

    if (is == null) {
        throw new FileNotFoundException(file);
    }

    try {
        byte[] bytes = IOUtils.toByteArray(is);
        String s = Strings.toString(bytes);
        return s;
    } finally {
        IOUtils.closeQuietly(is);
    }
}

From source file:io.syndesis.dao.init.ReadApiClientData.java

/**
 *
 * @param fileName//w w  w  . j  av a2 s .c o m
 * @return
 * @throws JsonParseException
 * @throws JsonMappingException
 * @throws IOException
 */
public List<ModelData<?>> readDataFromFile(String fileName)
        throws JsonParseException, JsonMappingException, IOException {
    try (InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(fileName)) {
        if (is == null) {
            throw new FileNotFoundException("Cannot find file " + fileName + " on classpath");
        }
        String jsonText = findAndReplaceTokens(from(is), System.getenv());
        return Json.mapper().readValue(jsonText, MODEL_DATA_TYPE);
    }
}

From source file:com.log4ic.compressor.utils.MemcachedUtils.java

public static void setConfigFile(File file) throws FileNotFoundException {
    if (file.exists() && file.isFile()) {
        CONFIG_FILE_PATH = file.getPath();
    } else {//from  www  .  j a v a2 s  . c  om
        throw new FileNotFoundException("??");
    }
}

From source file:com.amazonaws.services.iot.demo.danbo.rpi.Servo.java

public void run() {
    try {//  w  w  w. jav a  2 s  . c  o m
        log.debug("starting execution of thread: " + threadName);
        // calls the servoblaster command to move the servo according to the
        // selected angle
        try {
            String servoBlasterDevice = "/dev/servoblaster";
            File servoBlasterDev = new File(servoBlasterDevice);
            if (!servoBlasterDev.exists()) {
                throw new FileNotFoundException("Servoblaster not found at " + servoBlasterDevice
                        + ". Please check https://github.com/richardghirst/PiBits/tree/master/ServoBlaster for details.");
            }
            FileWriter writer = new FileWriter(servoBlasterDev);
            StringBuilder b = new StringBuilder();
            b.append("0").append('=').append(Integer.toString(angle + 150)).append('\n');
            try {
                writer.write(b.toString());
                writer.flush();
            } catch (IOException e) {
                try {
                    writer.close();
                } catch (IOException ignore) {
                }
            }
            try {
                writer.write(b.toString());
                writer.flush();
            } catch (IOException e) {
                throw new RuntimeException("Failed to write to /dev/servoblaster device", e);
            }
        } catch (Exception e) {
            System.err.println(String.format("Could not execute the servoblaster command"));
            e.printStackTrace();
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        log.debug("finishing execution of thread: " + threadName);
    }
}

From source file:com.qwazr.webapps.transaction.StaticManager.java

File findStatic(ApplicationContext context, String requestPath) throws URISyntaxException, IOException {
    // First we try to find the root directory using configuration mapping
    String staticPath = context.findStatic(requestPath);
    if (staticPath == null)
        return null;
    File staticFile = staticPath.startsWith("/") ? new File(staticPath) : new File(dataDir, staticPath);
    if (!staticFile.exists())
        throw new FileNotFoundException("File not found");
    if (!staticFile.isFile())
        throw new FileNotFoundException("File not found");
    return staticFile;
}

From source file:edu.usf.cutr.obascs.utils.CommandLineUtil.java

public static String getInputPath(CommandLine cmd) throws FileNotFoundException {
    String filePath;/*from  w  w w .j av a2  s  .  c  om*/
    if (cmd.hasOption(GeneralConstants.CL_OPTION_INPUT_PATH)) {
        filePath = cmd.getOptionValue(GeneralConstants.CL_OPTION_INPUT_PATH);
    } else {
        throw new FileNotFoundException("Agency mapping file not found.");
    }
    return filePath;
}

From source file:com.acmerocket.ywiki.RootResource.java

@GET
@Path("{path:(.+)?}") // use a regex to capture full path with '/'. https://docs.oracle.com/javaee/7/api/javax/ws/rs/Path.html
public Response get(@PathParam("path") String path) throws IOException {
    String fullPath = ROOT + path;

    LOG.trace("got request: '{}' => {}", path, fullPath);

    byte[] entity = this.readAll(fullPath);
    if (entity != null) {
        return Response.ok().entity(entity).build();
    } else {/*from ww  w  .j  a v a 2  s . c om*/
        throw new FileNotFoundException(path);
    }
}

From source file:org.openflamingo.uploader.util.HdfsUtils.java

/**
 *  ?   ?  ??./* w ww.  j a  v a2  s. c o m*/
 *
 * @param source ?? 
 * @param target ?? 
 * @param fs     Hadoop FileSystem
 */
public static void move(String source, String target, FileSystem fs) throws Exception {
    Path srcPath = new Path(source);
    Path[] srcs = FileUtil.stat2Paths(fs.globStatus(srcPath), srcPath);
    Path dst = new Path(target);
    if (srcs.length > 1 && !fs.getFileStatus(dst).isDir()) {
        throw new FileSystemException("When moving multiple files, destination should be a directory.");
    }
    for (int i = 0; i < srcs.length; i++) {
        if (!fs.rename(srcs[i], dst)) {
            FileStatus srcFstatus = null;
            FileStatus dstFstatus = null;
            try {
                srcFstatus = fs.getFileStatus(srcs[i]);
            } catch (FileNotFoundException e) {
                throw new FileNotFoundException(srcs[i] + ": No such file or directory");
            }
            try {
                dstFstatus = fs.getFileStatus(dst);
            } catch (IOException e) {
                // Nothing
            }
            if ((srcFstatus != null) && (dstFstatus != null)) {
                if (srcFstatus.isDir() && !dstFstatus.isDir()) {
                    throw new FileSystemException(
                            "cannot overwrite non directory " + dst + " with directory " + srcs[i]);
                }
            }
            throw new FileSystemException("Failed to rename " + srcs[i] + " to " + dst);
        }
    }
}

From source file:com.liferay.ide.core.util.FileListing.java

/**
 * Directory is valid if it exists, does not represent a file, and can be read.
 *//* w w w .jav a2  s . c  om*/
private static void _validateDirectory(File aDirectory) throws FileNotFoundException {
    if (aDirectory == null) {
        throw new IllegalArgumentException("Directory should not be null.");
    }

    if (!aDirectory.exists()) {
        throw new FileNotFoundException("Directory does not exist: " + aDirectory);
    }

    if (!aDirectory.isDirectory()) {
        throw new IllegalArgumentException("Is not a directory: " + aDirectory);
    }

    if (!aDirectory.canRead()) {
        throw new IllegalArgumentException("Directory cannot be read: " + aDirectory);
    }
}

From source file:com.galenframework.suite.actions.GalenPageActionProperties.java

@Override
public void execute(TestReport report, Browser browser, GalenPageTest pageTest,
        ValidationListener validationListener) throws Exception {
    if (files != null) {
        for (String filePath : files) {
            File file = new File(filePath);
            if (!file.exists()) {
                throw new FileNotFoundException("File does not exist: " + filePath);
            } else if (!file.isFile()) {
                throw new FileNotFoundException("Not a file: " + filePath);
            }/*from  w w w.  jav  a  2 s.  co  m*/
            TestSession.current().getProperties().load(new FileReader(file));
        }
    }
}