HADOOP-9093. Merge change r1413960 from trunk.
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-2@1413985 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
e192a00f15
commit
5b7d4c8c6c
|
@ -83,6 +83,9 @@ Release 2.0.3-alpha - Unreleased
|
|||
|
||||
HADOOP-9035. Generalize setup of LoginContext (daryn via bobby)
|
||||
|
||||
HADOOP-9093. Move all the Exception in PathExceptions to o.a.h.fs package.
|
||||
(suresh)
|
||||
|
||||
OPTIMIZATIONS
|
||||
|
||||
HADOOP-8866. SampleQuantiles#query is O(N^2) instead of O(N). (Andrew Wang
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.hadoop.fs;
|
||||
|
||||
/** EACCES */
|
||||
public class PathAccessDeniedException extends PathIOException {
|
||||
static final long serialVersionUID = 0L;
|
||||
/** @param path for the exception */
|
||||
public PathAccessDeniedException(String path) {
|
||||
super(path, "Permission denied");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.hadoop.fs;
|
||||
|
||||
/**
|
||||
* Exception corresponding to File Exists - EEXISTS
|
||||
*/
|
||||
public class PathExistsException extends PathIOException {
|
||||
static final long serialVersionUID = 0L;
|
||||
/** @param path for the exception */
|
||||
public PathExistsException(String path) {
|
||||
super(path, "File exists");
|
||||
}
|
||||
|
||||
protected PathExistsException(String path, String error) {
|
||||
super(path, error);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,117 @@
|
|||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.hadoop.fs;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Exceptions based on standard posix/linux style exceptions for path related
|
||||
* errors. Returns an exception with the format "path: standard error string".
|
||||
*
|
||||
* This exception corresponds to Error Input/ouput(EIO)
|
||||
*/
|
||||
public class PathIOException extends IOException {
|
||||
static final long serialVersionUID = 0L;
|
||||
private static final String EIO = "Input/output error";
|
||||
// NOTE: this really should be a Path, but a Path is buggy and won't
|
||||
// return the exact string used to construct the path, and it mangles
|
||||
// uris with no authority
|
||||
private String operation;
|
||||
private String path;
|
||||
private String targetPath;
|
||||
|
||||
/**
|
||||
* Constructor a generic I/O error exception
|
||||
* @param path for the exception
|
||||
*/
|
||||
public PathIOException(String path) {
|
||||
this(path, EIO, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends the text of a Throwable to the default error message
|
||||
* @param path for the exception
|
||||
* @param cause a throwable to extract the error message
|
||||
*/
|
||||
public PathIOException(String path, Throwable cause) {
|
||||
this(path, EIO, cause);
|
||||
}
|
||||
|
||||
/**
|
||||
* Avoid using this method. Use a subclass of PathIOException if
|
||||
* possible.
|
||||
* @param path for the exception
|
||||
* @param error custom string to use an the error text
|
||||
*/
|
||||
public PathIOException(String path, String error) {
|
||||
this(path, error, null);
|
||||
}
|
||||
|
||||
protected PathIOException(String path, String error, Throwable cause) {
|
||||
super(error, cause);
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
/** Format:
|
||||
* cmd: {operation} `path' {to `target'}: error string
|
||||
*/
|
||||
@Override
|
||||
public String getMessage() {
|
||||
StringBuilder message = new StringBuilder();
|
||||
if (operation != null) {
|
||||
message.append(operation + " ");
|
||||
}
|
||||
message.append(formatPath(path));
|
||||
if (targetPath != null) {
|
||||
message.append(" to " + formatPath(targetPath));
|
||||
}
|
||||
message.append(": " + super.getMessage());
|
||||
if (getCause() != null) {
|
||||
message.append(": " + getCause().getMessage());
|
||||
}
|
||||
return message.toString();
|
||||
}
|
||||
|
||||
/** @return Path that generated the exception */
|
||||
public Path getPath() { return new Path(path); }
|
||||
|
||||
/** @return Path if the operation involved copying or moving, else null */
|
||||
public Path getTargetPath() {
|
||||
return (targetPath != null) ? new Path(targetPath) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Optional operation that will preface the path
|
||||
* @param operation a string
|
||||
*/
|
||||
public void setOperation(String operation) {
|
||||
this.operation = operation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Optional path if the exception involved two paths, ex. a copy operation
|
||||
* @param targetPath the of the operation
|
||||
*/
|
||||
public void setTargetPath(String targetPath) {
|
||||
this.targetPath = targetPath;
|
||||
}
|
||||
|
||||
private String formatPath(String path) {
|
||||
return "`" + path + "'";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.hadoop.fs;
|
||||
|
||||
/** EISDIR */
|
||||
public class PathIsDirectoryException extends PathExistsException {
|
||||
static final long serialVersionUID = 0L;
|
||||
/** @param path for the exception */
|
||||
public PathIsDirectoryException(String path) {
|
||||
super(path, "Is a directory");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.hadoop.fs;
|
||||
|
||||
/** ENOTDIR */
|
||||
public class PathIsNotDirectoryException extends PathExistsException {
|
||||
static final long serialVersionUID = 0L;
|
||||
/** @param path for the exception */
|
||||
public PathIsNotDirectoryException(String path) {
|
||||
super(path, "Is not a directory");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.hadoop.fs;
|
||||
|
||||
/** Generated by rm commands */
|
||||
public class PathIsNotEmptyDirectoryException extends PathExistsException {
|
||||
/** @param path for the exception */
|
||||
public PathIsNotEmptyDirectoryException(String path) {
|
||||
super(path, "Directory is not empty");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.hadoop.fs;
|
||||
|
||||
/**
|
||||
* Exception corresponding to Permission denied - ENOENT
|
||||
*/
|
||||
public class PathNotFoundException extends PathIOException {
|
||||
static final long serialVersionUID = 0L;
|
||||
/** @param path for the exception */
|
||||
public PathNotFoundException(String path) {
|
||||
super(path, "No such file or directory");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.hadoop.fs;
|
||||
|
||||
/** ENOTSUP */
|
||||
public class PathOperationException extends PathExistsException {
|
||||
static final long serialVersionUID = 0L;
|
||||
/** @param path for the exception */
|
||||
public PathOperationException(String path) {
|
||||
super(path, "Operation not supported");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.hadoop.fs;
|
||||
|
||||
/**
|
||||
* Exception corresponding to Operation Not Permitted - EPERM
|
||||
*/
|
||||
public class PathPermissionException extends PathIOException {
|
||||
static final long serialVersionUID = 0L;
|
||||
/** @param path for the exception */
|
||||
public PathPermissionException(String path) {
|
||||
super(path, "Operation not permitted");
|
||||
}
|
||||
}
|
|
@ -33,7 +33,7 @@ import org.apache.hadoop.classification.InterfaceStability;
|
|||
import org.apache.hadoop.conf.Configuration;
|
||||
import org.apache.hadoop.conf.Configured;
|
||||
import org.apache.hadoop.fs.Path;
|
||||
import org.apache.hadoop.fs.shell.PathExceptions.PathNotFoundException;
|
||||
import org.apache.hadoop.fs.PathNotFoundException;
|
||||
import org.apache.hadoop.util.StringUtils;
|
||||
|
||||
/**
|
||||
|
|
|
@ -27,12 +27,12 @@ import org.apache.hadoop.fs.FSDataOutputStream;
|
|||
import org.apache.hadoop.fs.FileSystem;
|
||||
import org.apache.hadoop.fs.FilterFileSystem;
|
||||
import org.apache.hadoop.fs.Path;
|
||||
import org.apache.hadoop.fs.shell.PathExceptions.PathExistsException;
|
||||
import org.apache.hadoop.fs.shell.PathExceptions.PathIOException;
|
||||
import org.apache.hadoop.fs.shell.PathExceptions.PathIsDirectoryException;
|
||||
import org.apache.hadoop.fs.shell.PathExceptions.PathIsNotDirectoryException;
|
||||
import org.apache.hadoop.fs.shell.PathExceptions.PathNotFoundException;
|
||||
import org.apache.hadoop.fs.shell.PathExceptions.PathOperationException;
|
||||
import org.apache.hadoop.fs.PathExistsException;
|
||||
import org.apache.hadoop.fs.PathIOException;
|
||||
import org.apache.hadoop.fs.PathIsDirectoryException;
|
||||
import org.apache.hadoop.fs.PathIsNotDirectoryException;
|
||||
import org.apache.hadoop.fs.PathNotFoundException;
|
||||
import org.apache.hadoop.fs.PathOperationException;
|
||||
import org.apache.hadoop.io.IOUtils;
|
||||
|
||||
/**
|
||||
|
|
|
@ -27,7 +27,7 @@ import org.apache.hadoop.classification.InterfaceAudience;
|
|||
import org.apache.hadoop.classification.InterfaceStability;
|
||||
import org.apache.hadoop.fs.FSDataInputStream;
|
||||
import org.apache.hadoop.fs.FSDataOutputStream;
|
||||
import org.apache.hadoop.fs.shell.PathExceptions.PathIsDirectoryException;
|
||||
import org.apache.hadoop.fs.PathIsDirectoryException;
|
||||
import org.apache.hadoop.io.IOUtils;
|
||||
|
||||
/** Various commands for copy files */
|
||||
|
|
|
@ -24,11 +24,11 @@ import java.util.LinkedList;
|
|||
|
||||
import org.apache.hadoop.classification.InterfaceAudience;
|
||||
import org.apache.hadoop.classification.InterfaceStability;
|
||||
import org.apache.hadoop.fs.PathIOException;
|
||||
import org.apache.hadoop.fs.PathIsDirectoryException;
|
||||
import org.apache.hadoop.fs.PathIsNotDirectoryException;
|
||||
import org.apache.hadoop.fs.PathIsNotEmptyDirectoryException;
|
||||
import org.apache.hadoop.fs.Trash;
|
||||
import org.apache.hadoop.fs.shell.PathExceptions.PathIOException;
|
||||
import org.apache.hadoop.fs.shell.PathExceptions.PathIsDirectoryException;
|
||||
import org.apache.hadoop.fs.shell.PathExceptions.PathIsNotDirectoryException;
|
||||
import org.apache.hadoop.fs.shell.PathExceptions.PathIsNotEmptyDirectoryException;
|
||||
|
||||
/**
|
||||
* Classes that delete paths
|
||||
|
|
|
@ -38,7 +38,7 @@ import org.apache.hadoop.conf.Configuration;
|
|||
import org.apache.hadoop.fs.FSDataInputStream;
|
||||
import org.apache.hadoop.fs.FileStatus;
|
||||
import org.apache.hadoop.fs.Path;
|
||||
import org.apache.hadoop.fs.shell.PathExceptions.PathIsDirectoryException;
|
||||
import org.apache.hadoop.fs.PathIsDirectoryException;
|
||||
import org.apache.hadoop.io.DataInputBuffer;
|
||||
import org.apache.hadoop.io.DataOutputBuffer;
|
||||
import org.apache.hadoop.io.IOUtils;
|
||||
|
|
|
@ -24,10 +24,10 @@ import java.util.LinkedList;
|
|||
import org.apache.hadoop.classification.InterfaceAudience;
|
||||
import org.apache.hadoop.classification.InterfaceStability;
|
||||
import org.apache.hadoop.fs.Path;
|
||||
import org.apache.hadoop.fs.shell.PathExceptions.PathExistsException;
|
||||
import org.apache.hadoop.fs.shell.PathExceptions.PathIOException;
|
||||
import org.apache.hadoop.fs.shell.PathExceptions.PathIsNotDirectoryException;
|
||||
import org.apache.hadoop.fs.shell.PathExceptions.PathNotFoundException;
|
||||
import org.apache.hadoop.fs.PathExistsException;
|
||||
import org.apache.hadoop.fs.PathIOException;
|
||||
import org.apache.hadoop.fs.PathIsNotDirectoryException;
|
||||
import org.apache.hadoop.fs.PathNotFoundException;
|
||||
|
||||
/**
|
||||
* Create the given dir
|
||||
|
|
|
@ -23,8 +23,8 @@ import java.util.LinkedList;
|
|||
|
||||
import org.apache.hadoop.classification.InterfaceAudience;
|
||||
import org.apache.hadoop.classification.InterfaceStability;
|
||||
import org.apache.hadoop.fs.PathIOException;
|
||||
import org.apache.hadoop.fs.shell.CopyCommands.CopyFromLocal;
|
||||
import org.apache.hadoop.fs.shell.PathExceptions.PathIOException;
|
||||
|
||||
/** Various commands for moving files */
|
||||
@InterfaceAudience.Private
|
||||
|
|
|
@ -32,10 +32,10 @@ import org.apache.hadoop.fs.FileStatus;
|
|||
import org.apache.hadoop.fs.FileSystem;
|
||||
import org.apache.hadoop.fs.LocalFileSystem;
|
||||
import org.apache.hadoop.fs.Path;
|
||||
import org.apache.hadoop.fs.shell.PathExceptions.PathIOException;
|
||||
import org.apache.hadoop.fs.shell.PathExceptions.PathIsDirectoryException;
|
||||
import org.apache.hadoop.fs.shell.PathExceptions.PathIsNotDirectoryException;
|
||||
import org.apache.hadoop.fs.shell.PathExceptions.PathNotFoundException;
|
||||
import org.apache.hadoop.fs.PathIOException;
|
||||
import org.apache.hadoop.fs.PathIsDirectoryException;
|
||||
import org.apache.hadoop.fs.PathIsNotDirectoryException;
|
||||
import org.apache.hadoop.fs.PathNotFoundException;
|
||||
|
||||
/**
|
||||
* Encapsulates a Path (path), its FileStatus (stat), and its FileSystem (fs).
|
||||
|
|
|
@ -1,203 +0,0 @@
|
|||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.hadoop.fs.shell;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.hadoop.classification.InterfaceAudience;
|
||||
import org.apache.hadoop.classification.InterfaceStability;
|
||||
import org.apache.hadoop.fs.Path;
|
||||
|
||||
/**
|
||||
* Standardized posix/linux style exceptions for path related errors.
|
||||
* Returns an IOException with the format "path: standard error string".
|
||||
*/
|
||||
@InterfaceAudience.Private
|
||||
@InterfaceStability.Unstable
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class PathExceptions {
|
||||
|
||||
/** EIO */
|
||||
public static class PathIOException extends IOException {
|
||||
static final long serialVersionUID = 0L;
|
||||
private static final String EIO = "Input/output error";
|
||||
// NOTE: this really should be a Path, but a Path is buggy and won't
|
||||
// return the exact string used to construct the path, and it mangles
|
||||
// uris with no authority
|
||||
private String operation;
|
||||
private String path;
|
||||
private String targetPath;
|
||||
|
||||
/**
|
||||
* Constructor a generic I/O error exception
|
||||
* @param path for the exception
|
||||
*/
|
||||
public PathIOException(String path) {
|
||||
this(path, EIO, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends the text of a Throwable to the default error message
|
||||
* @param path for the exception
|
||||
* @param cause a throwable to extract the error message
|
||||
*/
|
||||
public PathIOException(String path, Throwable cause) {
|
||||
this(path, EIO, cause);
|
||||
}
|
||||
|
||||
/**
|
||||
* Avoid using this method. Use a subclass of PathIOException if
|
||||
* possible.
|
||||
* @param path for the exception
|
||||
* @param error custom string to use an the error text
|
||||
*/
|
||||
public PathIOException(String path, String error) {
|
||||
this(path, error, null);
|
||||
}
|
||||
|
||||
protected PathIOException(String path, String error, Throwable cause) {
|
||||
super(error, cause);
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
/** Format:
|
||||
* cmd: {operation} `path' {to `target'}: error string
|
||||
*/
|
||||
@Override
|
||||
public String getMessage() {
|
||||
StringBuilder message = new StringBuilder();
|
||||
if (operation != null) {
|
||||
message.append(operation + " ");
|
||||
}
|
||||
message.append(formatPath(path));
|
||||
if (targetPath != null) {
|
||||
message.append(" to " + formatPath(targetPath));
|
||||
}
|
||||
message.append(": " + super.getMessage());
|
||||
if (getCause() != null) {
|
||||
message.append(": " + getCause().getMessage());
|
||||
}
|
||||
return message.toString();
|
||||
}
|
||||
|
||||
/** @return Path that generated the exception */
|
||||
public Path getPath() { return new Path(path); }
|
||||
|
||||
/** @return Path if the operation involved copying or moving, else null */
|
||||
public Path getTargetPath() {
|
||||
return (targetPath != null) ? new Path(targetPath) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Optional operation that will preface the path
|
||||
* @param operation a string
|
||||
*/
|
||||
public void setOperation(String operation) {
|
||||
this.operation = operation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Optional path if the exception involved two paths, ex. a copy operation
|
||||
* @param targetPath the of the operation
|
||||
*/
|
||||
public void setTargetPath(String targetPath) {
|
||||
this.targetPath = targetPath;
|
||||
}
|
||||
|
||||
private String formatPath(String path) {
|
||||
return "`" + path + "'";
|
||||
}
|
||||
}
|
||||
|
||||
/** ENOENT */
|
||||
public static class PathNotFoundException extends PathIOException {
|
||||
static final long serialVersionUID = 0L;
|
||||
/** @param path for the exception */
|
||||
public PathNotFoundException(String path) {
|
||||
super(path, "No such file or directory");
|
||||
}
|
||||
}
|
||||
|
||||
/** EEXISTS */
|
||||
public static class PathExistsException extends PathIOException {
|
||||
static final long serialVersionUID = 0L;
|
||||
/** @param path for the exception */
|
||||
public PathExistsException(String path) {
|
||||
super(path, "File exists");
|
||||
}
|
||||
|
||||
protected PathExistsException(String path, String error) {
|
||||
super(path, error);
|
||||
}
|
||||
}
|
||||
|
||||
/** EISDIR */
|
||||
public static class PathIsDirectoryException extends PathExistsException {
|
||||
static final long serialVersionUID = 0L;
|
||||
/** @param path for the exception */
|
||||
public PathIsDirectoryException(String path) {
|
||||
super(path, "Is a directory");
|
||||
}
|
||||
}
|
||||
|
||||
/** ENOTDIR */
|
||||
public static class PathIsNotDirectoryException extends PathExistsException {
|
||||
static final long serialVersionUID = 0L;
|
||||
/** @param path for the exception */
|
||||
public PathIsNotDirectoryException(String path) {
|
||||
super(path, "Is not a directory");
|
||||
}
|
||||
}
|
||||
|
||||
/** Generated by rm commands */
|
||||
public static class PathIsNotEmptyDirectoryException extends PathExistsException {
|
||||
/** @param path for the exception */
|
||||
public PathIsNotEmptyDirectoryException(String path) {
|
||||
super(path, "Directory is not empty");
|
||||
}
|
||||
}
|
||||
|
||||
/** EACCES */
|
||||
public static class PathAccessDeniedException extends PathIOException {
|
||||
static final long serialVersionUID = 0L;
|
||||
/** @param path for the exception */
|
||||
public PathAccessDeniedException(String path) {
|
||||
super(path, "Permission denied");
|
||||
}
|
||||
}
|
||||
|
||||
/** EPERM */
|
||||
public static class PathPermissionException extends PathIOException {
|
||||
static final long serialVersionUID = 0L;
|
||||
/** @param path for the exception */
|
||||
public PathPermissionException(String path) {
|
||||
super(path, "Operation not permitted");
|
||||
}
|
||||
}
|
||||
|
||||
/** ENOTSUP */
|
||||
public static class PathOperationException extends PathExistsException {
|
||||
static final long serialVersionUID = 0L;
|
||||
/** @param path for the exception */
|
||||
public PathOperationException(String path) {
|
||||
super(path, "Operation not supported");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -25,7 +25,7 @@ import java.util.List;
|
|||
import org.apache.hadoop.classification.InterfaceAudience;
|
||||
import org.apache.hadoop.classification.InterfaceStability;
|
||||
import org.apache.hadoop.fs.BlockLocation;
|
||||
import org.apache.hadoop.fs.shell.PathExceptions.PathIOException;
|
||||
import org.apache.hadoop.fs.PathIOException;
|
||||
|
||||
/**
|
||||
* Modifies the replication factor
|
||||
|
|
|
@ -25,7 +25,7 @@ import java.util.List;
|
|||
import org.apache.hadoop.classification.InterfaceAudience;
|
||||
import org.apache.hadoop.classification.InterfaceStability;
|
||||
import org.apache.hadoop.fs.FSDataInputStream;
|
||||
import org.apache.hadoop.fs.shell.PathExceptions.PathIsDirectoryException;
|
||||
import org.apache.hadoop.fs.PathIsDirectoryException;
|
||||
import org.apache.hadoop.io.IOUtils;
|
||||
|
||||
/**
|
||||
|
|
|
@ -23,7 +23,6 @@ import java.util.LinkedList;
|
|||
|
||||
import org.apache.hadoop.classification.InterfaceAudience;
|
||||
import org.apache.hadoop.classification.InterfaceStability;
|
||||
import org.apache.hadoop.fs.shell.PathExceptions.PathNotFoundException;
|
||||
|
||||
/**
|
||||
* Perform shell-like file tests
|
||||
|
|
|
@ -23,9 +23,9 @@ import java.util.LinkedList;
|
|||
|
||||
import org.apache.hadoop.classification.InterfaceAudience;
|
||||
import org.apache.hadoop.classification.InterfaceStability;
|
||||
import org.apache.hadoop.fs.shell.PathExceptions.PathIOException;
|
||||
import org.apache.hadoop.fs.shell.PathExceptions.PathIsDirectoryException;
|
||||
import org.apache.hadoop.fs.shell.PathExceptions.PathNotFoundException;
|
||||
import org.apache.hadoop.fs.PathIOException;
|
||||
import org.apache.hadoop.fs.PathIsDirectoryException;
|
||||
import org.apache.hadoop.fs.PathNotFoundException;
|
||||
|
||||
/**
|
||||
* Unix touch like commands
|
||||
|
|
|
@ -23,7 +23,7 @@ import static org.junit.Assert.assertEquals;
|
|||
import java.io.IOException;
|
||||
|
||||
import org.apache.hadoop.fs.Path;
|
||||
import org.apache.hadoop.fs.shell.PathExceptions.PathIOException;
|
||||
import org.apache.hadoop.fs.PathIOException;
|
||||
import org.junit.Test;
|
||||
|
||||
public class TestPathExceptions {
|
||||
|
|
Loading…
Reference in New Issue