diff options
author | Elliott Hughes <enh@google.com> | 2014-04-28 19:29:57 -0700 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2014-04-28 19:33:01 -0700 |
commit | 41d8acb87dd1b722cf54e4c64e72c6a13688a849 (patch) | |
tree | f2661bc608049af579e562fc82df7ed3c7660529 | |
parent | ab8f6767cfec18b3390f4081413dbbbbdf2308a3 (diff) | |
download | libcore-41d8acb87dd1b722cf54e4c64e72c6a13688a849.zip libcore-41d8acb87dd1b722cf54e4c64e72c6a13688a849.tar.gz libcore-41d8acb87dd1b722cf54e4c64e72c6a13688a849.tar.bz2 |
Move ErrnoException into android.system.
Change-Id: Id22bebb6aadeff0729f430fce3f702d974a23efc
-rw-r--r-- | luni/src/main/java/android/system/ErrnoException.java | 44 | ||||
-rw-r--r-- | luni/src/main/java/libcore/io/ErrnoException.java | 65 | ||||
-rw-r--r-- | luni/src/main/java/libcore/io/IoBridge.java | 1 | ||||
-rw-r--r-- | luni/src/main/java/libcore/io/IoUtils.java | 1 |
4 files changed, 43 insertions, 68 deletions
diff --git a/luni/src/main/java/android/system/ErrnoException.java b/luni/src/main/java/android/system/ErrnoException.java index 5114bec..b434df8 100644 --- a/luni/src/main/java/android/system/ErrnoException.java +++ b/luni/src/main/java/android/system/ErrnoException.java @@ -16,15 +16,53 @@ package android.system; +import java.io.IOException; +import java.net.SocketException; +import libcore.io.Libcore; + /** + * A checked exception thrown when {@link Os} methods fail. This exception contains the native + * errno value, for comparison against the constants in {@link OsConstants}, should sophisticated + * callers need to adjust their behavior based on the exact failure. + * * @hide */ -public final class ErrnoException extends libcore.io.ErrnoException { +public final class ErrnoException extends Exception { + private final String functionName; + public final int errno; + public ErrnoException(String functionName, int errno) { - super(functionName, errno); + this.functionName = functionName; + this.errno = errno; } public ErrnoException(String functionName, int errno, Throwable cause) { - super(functionName, errno, cause); + super(cause); + this.functionName = functionName; + this.errno = errno; + } + + /** + * Converts the stashed function name and errno value to a human-readable string. + * We do this here rather than in the constructor so that callers only pay for + * this if they need it. + */ + @Override public String getMessage() { + String errnoName = OsConstants.errnoName(errno); + if (errnoName == null) { + errnoName = "errno " + errno; + } + String description = Libcore.os.strerror(errno); + return functionName + " failed: " + errnoName + " (" + description + ")"; + } + + public IOException rethrowAsIOException() throws IOException { + IOException newException = new IOException(getMessage()); + newException.initCause(this); + throw newException; + } + + public SocketException rethrowAsSocketException() throws SocketException { + throw new SocketException(getMessage(), this); } } diff --git a/luni/src/main/java/libcore/io/ErrnoException.java b/luni/src/main/java/libcore/io/ErrnoException.java deleted file mode 100644 index 2a8c1c2..0000000 --- a/luni/src/main/java/libcore/io/ErrnoException.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (C) 2011 The Android Open Source Project - * - * Licensed 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 libcore.io; - -import java.io.IOException; -import java.net.SocketException; - -/** - * An unchecked exception thrown when {@link Os} methods fail. This exception contains the native - * errno value, for comparison against the constants in {@link OsConstants}, should sophisticated - * callers need to adjust their behavior based on the exact failure. - */ -public /* not final for android.system.ErrnoException */ class ErrnoException extends Exception { - private final String functionName; - public final int errno; - - public ErrnoException(String functionName, int errno) { - this.functionName = functionName; - this.errno = errno; - } - - public ErrnoException(String functionName, int errno, Throwable cause) { - super(cause); - this.functionName = functionName; - this.errno = errno; - } - - /** - * Converts the stashed function name and errno value to a human-readable string. - * We do this here rather than in the constructor so that callers only pay for - * this if they need it. - */ - @Override public String getMessage() { - String errnoName = OsConstants.errnoName(errno); - if (errnoName == null) { - errnoName = "errno " + errno; - } - String description = Libcore.os.strerror(errno); - return functionName + " failed: " + errnoName + " (" + description + ")"; - } - - public IOException rethrowAsIOException() throws IOException { - IOException newException = new IOException(getMessage()); - newException.initCause(this); - throw newException; - } - - public SocketException rethrowAsSocketException() throws SocketException { - throw new SocketException(getMessage(), this); - } -} diff --git a/luni/src/main/java/libcore/io/IoBridge.java b/luni/src/main/java/libcore/io/IoBridge.java index 1e2ed7d..acc8d4f 100644 --- a/luni/src/main/java/libcore/io/IoBridge.java +++ b/luni/src/main/java/libcore/io/IoBridge.java @@ -16,6 +16,7 @@ package libcore.io; +import android.system.ErrnoException; import android.system.StructGroupReq; import android.system.StructGroupSourceReq; import android.system.StructLinger; diff --git a/luni/src/main/java/libcore/io/IoUtils.java b/luni/src/main/java/libcore/io/IoUtils.java index d0c4ffe..5a19f17 100644 --- a/luni/src/main/java/libcore/io/IoUtils.java +++ b/luni/src/main/java/libcore/io/IoUtils.java @@ -16,6 +16,7 @@ package libcore.io; +import android.system.ErrnoException; import android.system.StructStat; import java.io.File; import java.io.FileDescriptor; |