List of usage examples for java.nio.file NoSuchFileException NoSuchFileException
public NoSuchFileException(String file, String other, String reason)
From source file:edu.rit.flick.AbstractFlickFile.java
private void defaultDeflationInflationVerification() throws Exception { // Verify the input file exists if (!fileIn.exists()) throw new NoSuchFileException(fileIn.getPath(), null, FILE_NOT_FOUND_EXCEPTION_MESSAGE); // Verify the output file does not exist if (fileOut.exists()) { // Since file does exist: // Verify the force is on if (!configuration.getFlag(FORCE_FLAG)) throw new FileAlreadyExistsException(fileIn.getPath(), fileOut.getPath(), CANT_OVERWRITE_EXISTING_FILE_WITHOT_FORCE_FLAG); // Verify the output file is not a directory if (fileOut.isDirectory()) throw new FileAlreadyExistsException(FILE_ALREADY_EXISTS_AS_DIRECTORY_EXCEPTION); FileUtils.deleteQuietly(fileOut); }//from w ww .j av a2 s.c o m // Subclass's verification deflationInflationVerification(); }
From source file:de.tiqsolutions.hdfs.HadoopFileSystemProvider.java
static void rethrowRemoteException(RemoteException e, Path p1, Path p2) throws IOException { switch (e.getClassName()) { case "org.apache.hadoop.fs.PathIsNotEmptyDirectoryException": throw new DirectoryNotEmptyException(p1.toString()); case "org.apache.hadoop.fs.PathExistsException": case "org.apache.hadoop.fs.FileAlreadyExistsException": throw new FileAlreadyExistsException(Objects.toString(p1), Objects.toString(p2), e.getLocalizedMessage()); case "org.apache.hadoop.fs.PathPermissionException": case "org.apache.hadoop.fs.PathAccessDeniedException": throw new AccessDeniedException(Objects.toString(p1), Objects.toString(p2), e.getLocalizedMessage()); case "org.apache.hadoop.fs.ParentNotDirectoryException": case "org.apache.hadoop.fs.DirectoryListingStartAfterNotFoundException": case "org.apache.hadoop.fs.PathIsNotDirectoryException": throw new NotDirectoryException(Objects.toString(p1)); case "org.apache.hadoop.fs.PathIsDirectoryException": case "org.apache.hadoop.fs.InvalidPathException": case "org.apache.hadoop.fs.PathNotFoundException": throw new NoSuchFileException(Objects.toString(p1), Objects.toString(p2), e.getLocalizedMessage()); case "org.apache.hadoop.fs.UnresolvedLinkException": throw new NotLinkException(Objects.toString(p1), Objects.toString(p2), e.getLocalizedMessage()); case "org.apache.hadoop.fs.PathIOException": case "org.apache.hadoop.fs.ChecksumException": case "org.apache.hadoop.fs.InvalidRequestException": case "org.apache.hadoop.fs.UnsupportedFileSystemException": case "org.apache.hadoop.fs.ZeroCopyUnavailableException": }/*from www . ja va2 s. c o m*/ throw new IOException(e.getLocalizedMessage(), e); }
From source file:edu.rit.flick.util.FlickTest.java
private final void testForLosslessness() throws IOException, InterruptedException { Flick.main(VERBOSE_FLAG, originalFile.getPath()); Unflick.main(VERBOSE_FLAG, flickedFile.getPath(), unflickedFile.getPath()); if (!originalFile.exists()) { /*/* w w w .j a v a2s. c o m*/ * By falling in here, we assume the test failed because the file * given as input was not found. Equally so, the flicked file will * not be found by the unflicker since no flicking would have been * able to occur. */ final String expectedUsageStatement = String.format("%s%n%s%n", new NoSuchFileException(originalFile.getPath(), null, AbstractFlickFile.FILE_NOT_FOUND_EXCEPTION_MESSAGE).getMessage().trim(), new NoSuchFileException(flickedFile.getPath(), null, AbstractFlickFile.FILE_NOT_FOUND_EXCEPTION_MESSAGE).getMessage().trim()); final Object[] errorStack = errContent.toString().split("\n"); final int eSl = errorStack.length; final String actualUsageStatement = String.format("%s\n%s\n", Arrays.copyOfRange(errorStack, eSl - 2, eSl)); assertEquals(expectedUsageStatement, actualUsageStatement); return; } final FileInputStream origFIS = new FileInputStream(originalFile); ByteBufferInputStream orig = ByteBufferInputStream.map(origFIS.getChannel()); final FileInputStream comAndDecomFIS = new FileInputStream(unflickedFile); ByteBufferInputStream comAndDecom = ByteBufferInputStream.map(comAndDecomFIS.getChannel()); if (!FileUtils.contentEquals(originalFile, unflickedFile)) { long position = 0; while (orig.available() > 0) { position++; final int o = orig.read(); final int c = comAndDecom.read(); assertEquals(format(FILES_DO_NOT_MATCH_ERROR_FORMAT, originalFile, unflickedFile, position), (char) o + "", (char) c + ""); } assertEquals(orig.available(), comAndDecom.available()); origFIS.close(); orig.close(); comAndDecomFIS.close(); comAndDecom.close(); orig = null; comAndDecom = null; } }
From source file:org.modelio.vbasic.net.ApacheUriConnection.java
/** * Builds and throws a {@link FileSystemException} from {@link #res}. * <p>/*from w w w. java2s.co m*/ * Adds as cause another exception whose message is the entity content. This may be the HTML message sent by the server. * @throws java.nio.file.FileSystemException the built exception */ @objid("4e25ec1d-3711-45cc-b742-0c77edf5e414") private void handleConnectionFailure() throws FileSystemException { StatusLine statusLine = this.res.getStatusLine(); String reason = statusLine.getReasonPhrase(); Exception base = null; try { String s = EntityUtils.toString(this.res.getEntity()); if (s != null) base = new HttpResponseException(statusLine.getStatusCode(), s); } catch (IOException e) { base = e; } FileSystemException error; int statusCode = statusLine.getStatusCode(); if (statusCode == HttpStatus.SC_FORBIDDEN) { error = new AccessDeniedException(this.uri.toString(), null, reason); } else if (statusCode == HttpStatus.SC_UNAUTHORIZED || statusCode == HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED) { error = new UriAuthenticationException(this.uri.toString(), reason); } else if (statusCode == HttpStatus.SC_NOT_FOUND) { error = new NoSuchFileException(this.uri.toString(), null, reason); } else { error = new FileSystemException(this.uri.toString(), null, reason); } if (base != null) error.initCause(base); throw error; }
From source file:org.sakuli.utils.ResourceHelper.java
/** * Resolves a resource from the Classpath. * * @param classDef a instance of {@link Class} * @param classPathResource resource string like e.g. "/filename.file". * @param exceptionMessage custom exception message, if file couldn't resolved. * @return a {@link Path} object of the classpath resource. * @throws NoSuchFileException/*from www . j av a 2 s . c om*/ */ public static Path getClasspathResource(Class<?> classDef, String classPathResource, String exceptionMessage) throws NoSuchFileException { try { return Paths.get(classDef.getResource(classPathResource).toURI()); } catch (FileSystemNotFoundException | URISyntaxException | NullPointerException e) { NoSuchFileException exc = new NoSuchFileException(classPathResource, null, exceptionMessage); exc.addSuppressed(e); throw exc; } }