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:net.mikaboshi.intra_mart.tools.log_stats.formatter.TemplateFileReportFormatter.java

/**
 * ?/*  w  w  w .j a v a  2s .  c  om*/
 * @param templateFile
 * @throws FileNotFoundException
 */
public void setTemplateFile(File templateFile) throws FileNotFoundException {

    if (!templateFile.exists() || !templateFile.isFile()) {
        throw new FileNotFoundException(templateFile.getPath());
    }

    this.templateFile = templateFile;
}

From source file:com.yoncabt.ebr.logger.db.BaseDBReportLogger.java

@Override
public byte[] getReportData(String uuid) throws IOException {
    String table = EBRConf.INSTANCE.getValue("report.dblogger.tableName", "log_reports");
    String sql = String.format("select report_data from %s where id = ?", table);
    try (EBRConnection con = dataSourceManager.get("dblogger", "--", "EBR", getClass().getSimpleName());
            PreparedStatement ps = con.prepareStatement(sql)) {
        ps.setString(1, uuid);/* www  .j av  a  2s .c  om*/
        try (ResultSet res = ps.executeQuery()) {
            if (res.next()) {
                return res.getBytes(1);
            }
        }
    } catch (SQLException ex) {
        throw new IOException(ex);
    }
    throw new FileNotFoundException(uuid);
}

From source file:com.dvlcube.cuber.utils.FileUtils.java

public static void copyFile(File srcFile, File destFile, boolean preserveFileDate) throws IOException {
    if (srcFile == null) {
        throw new NullPointerException("Source must not be null");
    }/*from   w w  w .ja  v a 2s .  c o  m*/
    if (destFile == null) {
        throw new NullPointerException("Destination must not be null");
    }
    if (srcFile.exists() == false) {
        throw new FileNotFoundException("Source '" + srcFile + "' does not exist");
    }
    if (srcFile.isDirectory()) {
        throw new IOException("Source '" + srcFile + "' exists but is a directory");
    }
    if (srcFile.getCanonicalPath().equals(destFile.getCanonicalPath())) {
        throw new IOException("Source '" + srcFile + "' and destination '" + destFile + "' are the same");
    }
    if (destFile.getParentFile() != null && destFile.getParentFile().exists() == false) {
        if (destFile.getParentFile().mkdirs() == false) {
            throw new IOException("Destination '" + destFile + "' directory cannot be created");
        }
    }
    if (destFile.exists() && destFile.canWrite() == false) {
        throw new IOException("Destination '" + destFile + "' exists but is read-only");
    }
    doCopyFile(srcFile, destFile, preserveFileDate);
}

From source file:ict.ocrabase.main.java.client.bulkload.LoadHFiles.java

/**
 * Walk the given directory for all HFiles, and return a Queue
 * containing all such files./* ww  w. j  a  v a  2 s  . c o  m*/
 */
private Deque<LoadQueueItem> discoverLoadQueue(Path hfofDir) throws IOException {
    FileSystem fs = hfofDir.getFileSystem(getConf());

    if (!fs.exists(hfofDir)) {
        throw new FileNotFoundException("HFileOutputFormat dir " + hfofDir + " not found");
    }

    FileStatus[] familyDirStatuses = fs.listStatus(hfofDir);
    if (familyDirStatuses == null) {
        throw new FileNotFoundException("No families found in " + hfofDir);
    }

    Deque<LoadQueueItem> ret = new LinkedList<LoadQueueItem>();
    for (FileStatus stat : familyDirStatuses) {
        if (!stat.isDir()) {
            LOG.warn("Skipping non-directory " + stat.getPath());
            continue;
        }
        Path familyDir = stat.getPath();
        // Skip _logs, etc
        if (familyDir.getName().startsWith("_"))
            continue;
        byte[] family = familyDir.getName().getBytes();
        Path[] hfiles = FileUtil.stat2Paths(fs.listStatus(familyDir));
        for (Path hfile : hfiles) {
            if (hfile.getName().startsWith("_"))
                continue;
            ret.add(new LoadQueueItem(family, hfile));
        }
    }
    return ret;
}

From source file:com.bstek.dorado.view.resolver.LibraryFileResolver.java

@Override
protected Resource doGetI18NResource(DoradoContext context, String resourcePrefix, String fileName,
        String localeSuffix) throws Exception, FileNotFoundException {
    Resource resource = doGetResourcesByFileName(context, resourcePrefix, fileName,
            localeSuffix + I18N_FILE_SUFFIX, true)[0];
    if (resource == null || !resource.exists()) {
        if (StringUtils.isNotEmpty(localeSuffix)) {
            resource = doGetResourcesByFileName(context, resourcePrefix, fileName, I18N_FILE_SUFFIX)[0];
            if (resource == null || !resource.exists()) {
                throw new FileNotFoundException("File [" + PathUtils.concatPath(resourcePrefix, fileName)
                        + localeSuffix + I18N_FILE_SUFFIX + "] or ["
                        + PathUtils.concatPath(resourcePrefix, fileName) + I18N_FILE_SUFFIX + "] not found.");
            }//w  w w. j ava 2  s . c om
        } else {
            throw new FileNotFoundException("File [" + PathUtils.concatPath(resourcePrefix, fileName)
                    + I18N_FILE_SUFFIX + "] not found.");
        }
    }
    return resource;
}

From source file:com.intel.cosbench.controller.service.COSBControllerService.java

@Override
public String resubmit(String id) throws IOException {
    XmlConfig config = SimpleWorkloadLoader.getWorkloadConfg(memRepo.getWorkload(id));
    if (config != null)
        return submit(config);
    LOGGER.debug("[ CT ] - workload {} resubmitted failed, has no workload config", id);
    throw new FileNotFoundException("configuration file for workload " + id);
}

From source file:com.ning.http.client.async.MultipartUploadTest.java

private File getClasspathFile(String file) throws FileNotFoundException {
    ClassLoader cl = null;/*from w  w w.java2 s. c o  m*/
    try {
        cl = Thread.currentThread().getContextClassLoader();
    } catch (Throwable ex) {
    }
    if (cl == null) {
        cl = MultipartUploadTest.class.getClassLoader();
    }
    URL resourceUrl = cl.getResource(file);

    try {
        return new File(new URI(resourceUrl.toString()).getSchemeSpecificPart());
    } catch (URISyntaxException e) {
        throw new FileNotFoundException(file);
    }
}

From source file:com.denimgroup.threadfix.webapp.controller.ToolsDownloadController.java

private String doDownload(HttpServletRequest request, HttpServletResponse response, String jarName) {

    String jarResource = JAR_DOWNLOAD_DIR + jarName;

    InputStream in = request.getServletContext().getResourceAsStream(jarResource);
    if (in == null) {
        exceptionLogService.storeExceptionLog(
                new ExceptionLog(new FileNotFoundException("File not found for download: " + jarResource)));
        return index();
    }//from  www  . j  ava2 s.co m

    try {
        ServletOutputStream out = response.getOutputStream();
        int jarSize = request.getServletContext().getResource(jarResource).openConnection().getContentLength();

        if (jarName.endsWith(".jar"))
            response.setContentType("application/java-archive");
        else
            response.setContentType("application/octet-stream");
        ;
        response.setContentLength(jarSize);
        response.addHeader("Content-Disposition", "attachment; filename=\"" + jarName + "\"");

        IOUtils.copy(in, out);
        in.close();
        out.flush();
        out.close();
    } catch (IOException ioe) {
        exceptionLogService.storeExceptionLog(new ExceptionLog(ioe));
        return index();
    }
    return null;
}

From source file:com.pactera.edg.am.metamanager.extractor.control.impl.ExtractorServiceImpl.java

/**
 * ?//from  www .  j  a v  a 2  s. c  o m
 * 
 * @param incrementAnalyzer
 * @throws Throwable
 */
private boolean multiExtract() throws Throwable {
    File dsDirectorys = new File(AdapterExtractorContext.getInstance().getDsDirectory());
    if (!dsDirectorys.exists()) {
        // ?,
        AdapterExtractorContext.addExtractorLog(ExtractorLogLevel.ERROR,
                "???:" + AdapterExtractorContext.getInstance().getDsDirectory());
        throw new FileNotFoundException(
                "???:" + AdapterExtractorContext.getInstance().getDsDirectory());
    }

    return multiExtract(dsDirectorys);
}

From source file:cn.zhuqi.mavenssh.web.util.FtpUtil.java

/**
 * Downloads the file from the FTP server.
 *
 * @param ftpFileName server file name (with absolute path)
 * @param localFile local file to download into
 * @throws IOException on I/O errors// w  ww .  ja  va2 s. co  m
 */
public void download(String ftpFileName, File localFile) throws IOException {
    // Download.
    OutputStream out = null;
    try {
        // Use passive mode to pass firewalls.
        ftp.enterLocalPassiveMode();

        // Get file info.
        FTPFile[] fileInfoArray = ftp.listFiles(ftpFileName);
        if (fileInfoArray == null) {
            throw new FileNotFoundException("File " + ftpFileName + " was not found on FTP server.");
        }

        // Check file size.
        FTPFile fileInfo = fileInfoArray[0];
        long size = fileInfo.getSize();
        if (size > Integer.MAX_VALUE) {
            throw new IOException("File " + ftpFileName + " is too large.");
        }

        // Download file.
        out = new BufferedOutputStream(new FileOutputStream(localFile));
        if (!ftp.retrieveFile(ftpFileName, out)) {
            throw new IOException(
                    "Error loading file " + ftpFileName + " from FTP server. Check FTP permissions and path.");
        }

        out.flush();
    } finally {
        if (out != null) {
            try {
                out.close();
            } catch (IOException ex) {
            }
        }
    }
}