Search in sources :

Example 21 with FileNotFoundException

use of java.io.FileNotFoundException in project hadoop by apache.

the class Shell method getQualifiedBinInner.

/**
   * Inner logic of {@link #getQualifiedBin(String)}, accessible
   * for tests.
   * @param hadoopHomeDir home directory (assumed to be valid)
   * @param executable executable
   * @return path to the binary
   * @throws FileNotFoundException if the executable was not found/valid
   */
static File getQualifiedBinInner(File hadoopHomeDir, String executable) throws FileNotFoundException {
    String binDirText = "Hadoop bin directory ";
    File bin = new File(hadoopHomeDir, "bin");
    if (!bin.exists()) {
        throw new FileNotFoundException(addOsText(binDirText + E_DOES_NOT_EXIST + ": " + bin));
    }
    if (!bin.isDirectory()) {
        throw new FileNotFoundException(addOsText(binDirText + E_NOT_DIRECTORY + ": " + bin));
    }
    File exeFile = new File(bin, executable);
    if (!exeFile.exists()) {
        throw new FileNotFoundException(addOsText(E_NO_EXECUTABLE + ": " + exeFile));
    }
    if (!exeFile.isFile()) {
        throw new FileNotFoundException(addOsText(E_NOT_EXECUTABLE_FILE + ": " + exeFile));
    }
    try {
        return exeFile.getCanonicalFile();
    } catch (IOException e) {
        // so if it does, it gets converted to a FNFE and rethrown
        throw fileNotFoundException(e.toString(), e);
    }
}
Also used : FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) InterruptedIOException(java.io.InterruptedIOException) File(java.io.File)

Example 22 with FileNotFoundException

use of java.io.FileNotFoundException in project hadoop by apache.

the class GenericOptionsParser method expandWildcard.

private void expandWildcard(List<String> finalPaths, Path path, FileSystem fs) throws IOException {
    FileStatus status = fs.getFileStatus(path);
    if (!status.isDirectory()) {
        throw new FileNotFoundException(path + " is not a directory.");
    }
    // get all the jars in the directory
    List<Path> jars = FileUtil.getJarsInDirectory(path.toString(), fs.equals(FileSystem.getLocal(conf)));
    if (jars.isEmpty()) {
        LOG.warn(path + " does not have jars in it. It will be ignored.");
    } else {
        for (Path jar : jars) {
            finalPaths.add(jar.makeQualified(fs.getUri(), fs.getWorkingDirectory()).toString());
        }
    }
}
Also used : Path(org.apache.hadoop.fs.Path) FileStatus(org.apache.hadoop.fs.FileStatus) FileNotFoundException(java.io.FileNotFoundException)

Example 23 with FileNotFoundException

use of java.io.FileNotFoundException in project hadoop by apache.

the class SysInfoLinux method readDiskBlockInformation.

/**
   * Read /sys/block/diskName/queue/hw_sector_size file, parse and calculate
   * sector size for a specific disk.
   * @return sector size of specified disk, or defSector
   */
int readDiskBlockInformation(String diskName, int defSector) {
    assert perDiskSectorSize != null && diskName != null;
    String procfsDiskSectorFile = "/sys/block/" + diskName + "/queue/hw_sector_size";
    BufferedReader in;
    try {
        in = new BufferedReader(new InputStreamReader(new FileInputStream(procfsDiskSectorFile), Charset.forName("UTF-8")));
    } catch (FileNotFoundException f) {
        return defSector;
    }
    Matcher mat;
    try {
        String str = in.readLine();
        while (str != null) {
            mat = PROCFS_DISKSECTORFILE_FORMAT.matcher(str);
            if (mat.find()) {
                String secSize = mat.group(1);
                if (secSize != null) {
                    return Integer.parseInt(secSize);
                }
            }
            str = in.readLine();
        }
        return defSector;
    } catch (IOException | NumberFormatException e) {
        LOG.warn("Error reading the stream " + procfsDiskSectorFile, e);
        return defSector;
    } finally {
        // Close the streams
        try {
            in.close();
        } catch (IOException e) {
            LOG.warn("Error closing the stream " + procfsDiskSectorFile, e);
        }
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) Matcher(java.util.regex.Matcher) BufferedReader(java.io.BufferedReader) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream)

Example 24 with FileNotFoundException

use of java.io.FileNotFoundException in project flink by apache.

the class BlobServer method getURL.

/**
	 * Method which retrieves the URL of a file associated with a blob key. The blob server looks
	 * the blob key up in its local storage. If the file exists, then the URL is returned. If the
	 * file does not exist, then a FileNotFoundException is thrown.
	 *
	 * @param requiredBlob blob key associated with the requested file
	 * @return URL of the file
	 * @throws IOException
	 */
@Override
public URL getURL(BlobKey requiredBlob) throws IOException {
    checkArgument(requiredBlob != null, "BLOB key cannot be null.");
    final File localFile = BlobUtils.getStorageLocation(storageDir, requiredBlob);
    if (localFile.exists()) {
        return localFile.toURI().toURL();
    } else {
        try {
            // Try the blob store
            blobStore.get(requiredBlob, localFile);
        } catch (Exception e) {
            throw new IOException("Failed to copy from blob store.", e);
        }
        if (localFile.exists()) {
            return localFile.toURI().toURL();
        } else {
            throw new FileNotFoundException("Local file " + localFile + " does not exist " + "and failed to copy from blob store.");
        }
    }
}
Also used : FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) File(java.io.File) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 25 with FileNotFoundException

use of java.io.FileNotFoundException in project flink by apache.

the class DataSinkTaskTest method testSortingDataSinkTask.

@Test
@SuppressWarnings("unchecked")
public void testSortingDataSinkTask() {
    int keyCnt = 100;
    int valCnt = 20;
    double memoryFraction = 1.0;
    super.initEnvironment(MEMORY_MANAGER_SIZE, NETWORK_BUFFER_SIZE);
    super.addInput(new UniformRecordGenerator(keyCnt, valCnt, true), 0);
    DataSinkTask<Record> testTask = new DataSinkTask<>();
    // set sorting
    super.getTaskConfig().setInputLocalStrategy(0, LocalStrategy.SORT);
    super.getTaskConfig().setInputComparator(new RecordComparatorFactory(new int[] { 1 }, (new Class[] { IntValue.class })), 0);
    super.getTaskConfig().setRelativeMemoryInput(0, memoryFraction);
    super.getTaskConfig().setFilehandlesInput(0, 8);
    super.getTaskConfig().setSpillingThresholdInput(0, 0.8f);
    super.registerFileOutputTask(testTask, MockOutputFormat.class, new File(tempTestPath).toURI().toString());
    try {
        testTask.invoke();
    } catch (Exception e) {
        LOG.debug("Exception while invoking the test task.", e);
        Assert.fail("Invoke method caused exception.");
    }
    File tempTestFile = new File(this.tempTestPath);
    Assert.assertTrue("Temp output file does not exist", tempTestFile.exists());
    FileReader fr = null;
    BufferedReader br = null;
    try {
        fr = new FileReader(tempTestFile);
        br = new BufferedReader(fr);
        Set<Integer> keys = new HashSet<>();
        int curVal = -1;
        while (br.ready()) {
            String line = br.readLine();
            Integer key = Integer.parseInt(line.substring(0, line.indexOf("_")));
            Integer val = Integer.parseInt(line.substring(line.indexOf("_") + 1, line.length()));
            // check that values are in correct order
            Assert.assertTrue("Values not in ascending order", val >= curVal);
            // next value hit
            if (val > curVal) {
                if (curVal != -1) {
                    // check that we saw 100 distinct keys for this values
                    Assert.assertTrue("Keys missing for value", keys.size() == 100);
                }
                // empty keys set
                keys.clear();
                // update current value
                curVal = val;
            }
            Assert.assertTrue("Duplicate key for value", keys.add(key));
        }
    } catch (FileNotFoundException e) {
        Assert.fail("Out file got lost...");
    } catch (IOException ioe) {
        Assert.fail("Caught IOE while reading out file");
    } finally {
        if (br != null) {
            try {
                br.close();
            } catch (Throwable t) {
            }
        }
        if (fr != null) {
            try {
                fr.close();
            } catch (Throwable t) {
            }
        }
    }
}
Also used : RecordComparatorFactory(org.apache.flink.runtime.testutils.recordutils.RecordComparatorFactory) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) BufferedReader(java.io.BufferedReader) Record(org.apache.flink.types.Record) FileReader(java.io.FileReader) UniformRecordGenerator(org.apache.flink.runtime.operators.testutils.UniformRecordGenerator) File(java.io.File) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

FileNotFoundException (java.io.FileNotFoundException)3218 IOException (java.io.IOException)1836 File (java.io.File)1277 FileInputStream (java.io.FileInputStream)814 FileOutputStream (java.io.FileOutputStream)492 InputStream (java.io.InputStream)466 BufferedReader (java.io.BufferedReader)262 FileReader (java.io.FileReader)230 ArrayList (java.util.ArrayList)205 Path (org.apache.hadoop.fs.Path)202 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)189 InputStreamReader (java.io.InputStreamReader)171 Test (org.junit.Test)171 XmlPullParser (org.xmlpull.v1.XmlPullParser)166 BufferedInputStream (java.io.BufferedInputStream)138 ParcelFileDescriptor (android.os.ParcelFileDescriptor)131 Properties (java.util.Properties)120 URL (java.net.URL)119 FileStatus (org.apache.hadoop.fs.FileStatus)119 RandomAccessFile (java.io.RandomAccessFile)101