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() 

Source Link

Document

Constructs a FileNotFoundException with null as its error detail message.

Usage

From source file:com.doplgangr.secrecy.filesystem.files.EncryptedFile.java

/**
 * Loads an existing encrypted file from the file system.
 *//* w  w  w.  j a  v  a  2  s .c  o  m*/
EncryptedFile(File file, Crypter crypter, EncryptedThumbnail encryptedThumbnail) throws FileNotFoundException {
    this.file = file;
    this.crypter = crypter;
    this.encryptedThumbnail = encryptedThumbnail;

    if (!file.exists()) {
        throw new FileNotFoundException();
    }
    try {
        decryptedFileName = crypter.getDecryptedFileName(file);
    } catch (Exception e) {
        //Ignored
    }

    fileExtension = FilenameUtils.getExtension(decryptedFileName);
    this.fileSize = humanReadableByteCount(file.length());
    timestamp = new Date(file.lastModified());
}

From source file:com.ibm.soatf.tool.ValidateTransferedValues.java

public static boolean validateValuesFromFile(File sqlScriptFile, File messageFile, Map<String, String> mappings)
        throws FileNotFoundException, ParseException, java.text.ParseException {
    if (sqlScriptFile == null || messageFile == null || !sqlScriptFile.exists() || !messageFile.exists()) {
        throw new FileNotFoundException();
    }//from  w w  w. ja v  a  2 s  . c  om

    ZqlParser zqlParser = new ZqlParser();
    zqlParser.addCustomFunction("TO_DATE", 2);

    zqlParser.initParser(new FileInputStream(sqlScriptFile));

    ZStatement zs = zqlParser.readStatement();
    System.out.println("Input statement: " + zs.toString());

    boolean valid = true;
    if (zs instanceof ZQuery) {

        System.out.println("Je to select statement");
    } else if (zs instanceof ZInsert) {
        System.out.println("Je to insert statement");
        ZInsert zi = (ZInsert) zs;
        int i = 0;
        Vector columns = zi.getColumns();
        Vector values = zi.getValues();

        Enumeration colEnum = columns.elements();
        Enumeration valEnum = values.elements();
        String dbColumnName = null;
        String dbValue = null;
        String messageElementName = null;
        String messageValue = null;

        Pattern pattern = Pattern.compile("'([^']+)'");

        while (colEnum.hasMoreElements()) {

            boolean dateCompare = false;
            dbColumnName = colEnum.nextElement().toString();
            if (mappings != null && mappings.containsKey(dbColumnName)) {
                messageElementName = mappings.get(dbColumnName);
                if (messageElementName == null || "".equals(messageElementName)) {
                    //null v toColumnName - neporovnavam
                    logger.debug("Skipping column " + dbColumnName);
                    valEnum.nextElement();
                    continue;
                }
            } else {
                messageElementName = constructXMLElementNameFromDBColumn(dbColumnName);
            }
            dbValue = valEnum.nextElement().toString();
            if (dbValue != null && dbValue.startsWith("TO_DATE"))
                dateCompare = true;
            Matcher matcher = pattern.matcher(dbValue);
            if (matcher.find()) {
                dbValue = matcher.group(1);
            }
            logger.debug("Comparing values for column " + dbColumnName + " and coresponding element "
                    + messageElementName);
            messageValue = getElementFromFile(messageElementName, messageFile, false);
            boolean differ = false;
            if (dateCompare) {
                final Date dbDate = DatabaseComponent.DATE_FORMAT.parse(dbValue);
                //TODO: timezone //Date xmlDate = DatatypeConverter.parseDate(messageValue).getTime();
                Date xmlDate = (messageValue == null || messageValue.length() < 19) ? null
                        : JmsComponent.DATE_FORMAT.parse(messageValue.substring(0, 19));
                differ ^= dbDate.equals(xmlDate);
            } else {
                if (dbValue == null) {
                    if (messageValue != null) {
                        differ = true;
                    } else {
                        differ = false;
                    }
                } else {
                    differ = !dbValue.equals(messageValue);
                }
            }
            if (differ) {
                logger.debug("values are different: " + dbValue + " <> " + messageValue);
                valid = false;
            } else {
                logger.debug("values are equal");
            }
        }

    }
    return valid;
}

From source file:msuresh.raftdistdb.RaftClient.java

public static void GetValue(String name, String key) throws FileNotFoundException {
    if (key == null || key.isEmpty()) {
        return;//from www.j  a v a 2 s.  c  o m
    }
    File configFile = new File(Constants.STATE_LOCATION + name + ".info");
    if (!configFile.exists() || configFile.isDirectory()) {
        FileNotFoundException ex = new FileNotFoundException();
        throw ex;
    }
    try {
        System.out.println("Getting key .. Hold on.");
        String content = new Scanner(configFile).useDelimiter("\\Z").next();
        JSONObject config = (JSONObject) (new JSONParser()).parse(content);
        Long numPart = (Long) config.get("countPartitions");
        Integer shardId = key.hashCode() % numPart.intValue();
        JSONArray memberJson = (JSONArray) config.get(shardId.toString());
        List<Address> members = new ArrayList<>();
        for (int i = 0; i < memberJson.size(); i++) {
            JSONObject obj = (JSONObject) memberJson.get(i);
            Long port = (Long) obj.get("port");
            String address = (String) obj.get("address");
            members.add(new Address(address, port.intValue()));
        }
        CopycatClient client = CopycatClient.builder(members).withTransport(new NettyTransport()).build();
        client.open().join();
        Object str = client.submit(new GetQuery(key)).get();
        System.out.println("For the key : " + key + ", the database returned the value : " + (String) str);
        client.close().join();
        while (client.isOpen()) {
            Thread.sleep(1000);
        }
    } catch (Exception ex) {
        System.out.println(ex.toString());
    }
}

From source file:CASUAL.communicationstools.heimdall.odin.Odin.java

public String[] getHeimdallFileParametersFromOdinFile(String tempFolder, File[] files)
        throws CorruptOdinFileException, FileNotFoundException {
    //Sorted set allows for only one instance of each file to exist
    SortedSet<File> set = new java.util.TreeSet<File>();

    //decompress Odin files into regular files and track them
    for (File file : files) {
        OdinFile o;/*from ww w .  ja va2s  .  c  o m*/
        try {
            o = new OdinFile(file);
            o.extractOdinContents(tempFolder);
            set.addAll(Arrays.asList(o.extractOdinContents(tempFolder)));
        } catch (IOException ex) {
            throw new FileNotFoundException();
        } catch (NoSuchAlgorithmException ex) {
            throw new CorruptOdinFileException("This computer cannot handle the file");
        } catch (CorruptOdinFileException ex) {
            throw new CorruptOdinFileException("The Archive is corrupt");
        } catch (ArchiveException ex) {
            throw new CorruptOdinFileException("The Archive is corrupt");
        }
    }

    //create list of --PARTITION filename for Heimdall
    ArrayList<String> list = new ArrayList<String>();
    for (File f : set) {
        String partname = pit.findEntryByFilename(f.getName()).getPartitionName();
        list.add("--" + partname);
        list.add(f.getAbsolutePath());
    }

    //return that list. 
    return list.toArray(new String[list.size()]);
}

From source file:com.idsmanager.eagleeye.net.IDsManagerMultiPartRequest.java

public void put(String key, File file, String contentType, String customFileName) throws FileNotFoundException {
    if (file == null || !file.exists()) {
        throw new FileNotFoundException();
    }/*from w w  w  . ja v a  2s. c  o m*/
    if (key != null) {
        fileParams.put(key, new FileWrapper(file, contentType, customFileName));
    }
}

From source file:edu.umd.cs.psl.config.ConfigManager.java

public void loadResource(String resource) throws FileNotFoundException, ConfigurationException {
    URL url;/*  w ww .j a  va2s  . co  m*/
    PropertiesConfiguration newConfig;

    try {
        url = new URL(resource);
    } catch (MalformedURLException ex) {
        url = Loader.getResource(resource);
    }
    if (url != null) {
        newConfig = new PropertiesConfiguration(url);
        masterConfig.append(newConfig);
    } else
        throw new FileNotFoundException();
}

From source file:fi.johannes.kata.ocr.utils.files.ExistingFileConnection.java

private void testExistence() throws FileNotFoundException {
    if (Files.exists(p))
        ;//  w ww . j  av a  2  s .  c o  m
    else {
        throw new FileNotFoundException();
    }
}

From source file:configurator.Configurator.java

/**
 * The main method for telnet configuring the network devices. Prepare data
 * and create thread for each device//w w  w .  j ava2  s  .  c o  m
 *
 * @param ipText - List of ip ranges, subnets and single ip
 * @param authData - authorization data for work on devices
 * @param models list of models for telnet configure
 */
void telnetWork(String ipText, AuthenticationData authData, List<String> models) {
    try {
        List<String> ipList = parseIp(ipText);
        ExecutorService exec = Executors.newCachedThreadPool();
        ipList.forEach((ip) -> {
            Snmp snmp = new Snmp(authData.getCommunity());
            String modelOid = mainProperites.getProperty("Identifier_Oid");
            String model = snmp.get(ip, modelOid).trim();
            if (models.contains(model)) {
                try {
                    String modelAddress = getAddressByModelName(model);
                    if (modelAddress != null) {
                        exec.execute(new TelnetConfigureThread(ip, authData, modelAddress));
                    } else {
                        throw new FileNotFoundException();
                    }
                } catch (FileNotFoundException ex) {
                    System.exit(0);
                }
            } else {
            }
        });
        exec.shutdown();
    } catch (Exception e) {
        System.out.println(e);
        //ip address is incorrect
    }
}

From source file:de.uzk.hki.da.metadata.XsltGenerator.java

/**
 * Instantiates a new xslt generator./* w w w.j a  v  a 2  s .c  o m*/
 *
 * @param xsltPath the xslt path to the edm mapping file
 * @param inputStream the input stream of the source metadata file
 * @throws FileNotFoundException 
 * @throws TransformerConfigurationException 
 */
public XsltGenerator(String xsltPath, InputStream inputStream)
        throws FileNotFoundException, TransformerConfigurationException {
    if (!new File(xsltPath).exists())
        throw new FileNotFoundException();

    try {
        String theString = IOUtils.toString(inputStream, "UTF-8");
        this.inputStream = new ByteArrayInputStream(theString.getBytes());

        xsltSource = new StreamSource(new FileInputStream(xsltPath));

        TransformerFactory transFact = TransformerFactory.newInstance(TRANSFORMER_FACTORY_CLASS, null);
        transFact.setErrorListener(new CutomErrorListener());

        transformer = null;
        transformer = transFact.newTransformer(xsltSource);
        transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
        transformer.setErrorListener(new CutomErrorListener());

    } catch (IOException e) {
        e.printStackTrace();
    }
}