org.apache.hadoop.fs.PathExistsException Java Examples
The following examples show how to use
org.apache.hadoop.fs.PathExistsException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CommandWithDestination.java From hadoop with Apache License 2.0 | 6 votes |
@Override protected void processArguments(LinkedList<PathData> args) throws IOException { // if more than one arg, the destination must be a directory // if one arg, the dst must not exist or must be a directory if (args.size() > 1) { if (!dst.exists) { throw new PathNotFoundException(dst.toString()); } if (!dst.stat.isDirectory()) { throw new PathIsNotDirectoryException(dst.toString()); } } else if (dst.exists) { if (!dst.stat.isDirectory() && !overwrite) { throw new PathExistsException(dst.toString()); } } else if (!dst.parentExists()) { throw new PathNotFoundException(dst.toString()); } super.processArguments(args); }
Example #2
Source File: CommandWithDestination.java From hadoop with Apache License 2.0 | 6 votes |
/** * Copies the stream contents to a temporary file. If the copy is * successful, the temporary file will be renamed to the real path, * else the temporary file will be deleted. * @param in the input stream for the copy * @param target where to store the contents of the stream * @throws IOException if copy fails */ protected void copyStreamToTarget(InputStream in, PathData target) throws IOException { if (target.exists && (target.stat.isDirectory() || !overwrite)) { throw new PathExistsException(target.toString()); } TargetFileSystem targetFs = new TargetFileSystem(target.fs); try { PathData tempTarget = target.suffix("._COPYING_"); targetFs.setWriteChecksum(writeChecksum); targetFs.writeStreamToFile(in, tempTarget, lazyPersist); targetFs.rename(tempTarget, target); } finally { targetFs.close(); // last ditch effort to ensure temp file is removed } }
Example #3
Source File: CommandWithDestination.java From big-c with Apache License 2.0 | 6 votes |
@Override protected void processArguments(LinkedList<PathData> args) throws IOException { // if more than one arg, the destination must be a directory // if one arg, the dst must not exist or must be a directory if (args.size() > 1) { if (!dst.exists) { throw new PathNotFoundException(dst.toString()); } if (!dst.stat.isDirectory()) { throw new PathIsNotDirectoryException(dst.toString()); } } else if (dst.exists) { if (!dst.stat.isDirectory() && !overwrite) { throw new PathExistsException(dst.toString()); } } else if (!dst.parentExists()) { throw new PathNotFoundException(dst.toString()); } super.processArguments(args); }
Example #4
Source File: CommandWithDestination.java From big-c with Apache License 2.0 | 6 votes |
/** * Copies the stream contents to a temporary file. If the copy is * successful, the temporary file will be renamed to the real path, * else the temporary file will be deleted. * @param in the input stream for the copy * @param target where to store the contents of the stream * @throws IOException if copy fails */ protected void copyStreamToTarget(InputStream in, PathData target) throws IOException { if (target.exists && (target.stat.isDirectory() || !overwrite)) { throw new PathExistsException(target.toString()); } TargetFileSystem targetFs = new TargetFileSystem(target.fs); try { PathData tempTarget = target.suffix("._COPYING_"); targetFs.setWriteChecksum(writeChecksum); targetFs.writeStreamToFile(in, tempTarget, lazyPersist); targetFs.rename(tempTarget, target); } finally { targetFs.close(); // last ditch effort to ensure temp file is removed } }
Example #5
Source File: MoveCommands.java From hadoop with Apache License 2.0 | 5 votes |
@Override protected void processPath(PathData src, PathData target) throws IOException { // unlike copy, don't merge existing dirs during move if (target.exists && target.stat.isDirectory()) { throw new PathExistsException(target.toString()); } super.processPath(src, target); }
Example #6
Source File: MoveCommands.java From hadoop with Apache License 2.0 | 5 votes |
@Override protected void processPath(PathData src, PathData target) throws IOException { if (!src.fs.getUri().equals(target.fs.getUri())) { throw new PathIOException(src.toString(), "Does not match target filesystem"); } if (target.exists) { throw new PathExistsException(target.toString()); } if (!target.fs.rename(src.path, target.path)) { // we have no way to know the actual error... throw new PathIOException(src.toString()); } }
Example #7
Source File: Mkdir.java From hadoop with Apache License 2.0 | 5 votes |
@Override protected void processPath(PathData item) throws IOException { if (item.stat.isDirectory()) { if (!createParents) { throw new PathExistsException(item.toString()); } } else { throw new PathIsNotDirectoryException(item.toString()); } }
Example #8
Source File: MoveCommands.java From big-c with Apache License 2.0 | 5 votes |
@Override protected void processPath(PathData src, PathData target) throws IOException { // unlike copy, don't merge existing dirs during move if (target.exists && target.stat.isDirectory()) { throw new PathExistsException(target.toString()); } super.processPath(src, target); }
Example #9
Source File: MoveCommands.java From big-c with Apache License 2.0 | 5 votes |
@Override protected void processPath(PathData src, PathData target) throws IOException { if (!src.fs.getUri().equals(target.fs.getUri())) { throw new PathIOException(src.toString(), "Does not match target filesystem"); } if (target.exists) { throw new PathExistsException(target.toString()); } if (!target.fs.rename(src.path, target.path)) { // we have no way to know the actual error... throw new PathIOException(src.toString()); } }
Example #10
Source File: Mkdir.java From big-c with Apache License 2.0 | 5 votes |
@Override protected void processPath(PathData item) throws IOException { if (item.stat.isDirectory()) { if (!createParents) { throw new PathExistsException(item.toString()); } } else { throw new PathIsNotDirectoryException(item.toString()); } }
Example #11
Source File: HadoopIgfsSecondaryFileSystemDelegateImpl.java From ignite with Apache License 2.0 | 5 votes |
/** * Cast IO exception to IGFS exception. * * @param msg Error message. * @param e IO exception. * @return IGFS exception. */ public static IgfsException cast(String msg, IOException e) { if (e instanceof FileNotFoundException) return new IgfsPathNotFoundException(e); else if (e instanceof ParentNotDirectoryException) return new IgfsParentNotDirectoryException(msg, e); else if (e instanceof PathIsNotEmptyDirectoryException) return new IgfsDirectoryNotEmptyException(e); else if (e instanceof PathExistsException) return new IgfsPathAlreadyExistsException(msg, e); else return new IgfsException(msg, e); }
Example #12
Source File: HadoopIgfs20FileSystemAbstractSelfTest.java From ignite with Apache License 2.0 | 5 votes |
/** @throws Exception If failed. */ @Test public void testCreateCheckOverwrite() throws Exception { Path fsHome = new Path(primaryFsUri); Path dir = new Path(fsHome, "/someDir1/someDir2/someDir3"); final Path file = new Path(dir, "someFile"); FSDataOutputStream out = fs.create(file, EnumSet.noneOf(CreateFlag.class), Options.CreateOpts.perms(FsPermission.getDefault())); out.close(); // Check intermediate directory permissions. assertEquals(FsPermission.getDefault(), fs.getFileStatus(dir).getPermission()); assertEquals(FsPermission.getDefault(), fs.getFileStatus(dir.getParent()).getPermission()); assertEquals(FsPermission.getDefault(), fs.getFileStatus(dir.getParent().getParent()).getPermission()); GridTestUtils.assertThrows(log, new Callable<Object>() { @Override public Object call() throws Exception { return fs.create(file, EnumSet.noneOf(CreateFlag.class), Options.CreateOpts.perms(FsPermission.getDefault())); } }, PathExistsException.class, null); // Overwrite should be successful. FSDataOutputStream out1 = fs.create(file, EnumSet.of(CreateFlag.OVERWRITE), Options.CreateOpts.perms(FsPermission.getDefault())); out1.close(); }
Example #13
Source File: IgniteHadoopFileSystemAbstractSelfTest.java From ignite with Apache License 2.0 | 5 votes |
/** @throws Exception If failed. */ @SuppressWarnings("deprecation") @Test public void testCreateCheckOverwrite() throws Exception { Path fsHome = new Path(primaryFsUri); Path dir = new Path(fsHome, "/someDir1/someDir2/someDir3"); final Path file = new Path(dir, "someFile"); FSDataOutputStream out = fs.create(file, FsPermission.getDefault(), false, 64 * 1024, fs.getDefaultReplication(), fs.getDefaultBlockSize(), null); out.close(); // Check intermediate directory permissions. assertEquals(FsPermission.getDefault(), fs.getFileStatus(dir).getPermission()); assertEquals(FsPermission.getDefault(), fs.getFileStatus(dir.getParent()).getPermission()); assertEquals(FsPermission.getDefault(), fs.getFileStatus(dir.getParent().getParent()).getPermission()); GridTestUtils.assertThrows(log, new Callable<Object>() { @Override public Object call() throws Exception { return fs.create(file, FsPermission.getDefault(), false, 1024, (short)1, 2048, null); } }, PathExistsException.class, null); // Overwrite should be successful. FSDataOutputStream out1 = fs.create(file, true); out1.close(); }