Path: blob/master/src/java.base/share/classes/sun/nio/ch/IOStatus.java
41159 views
/*1* Copyright (c) 2002, 2019, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.nio.ch;2627import java.lang.annotation.Native;2829// Constants for reporting I/O status3031public final class IOStatus {3233private IOStatus() { }3435@Native public static final int EOF = -1; // End of file36@Native public static final int UNAVAILABLE = -2; // Nothing available (non-blocking)37@Native public static final int INTERRUPTED = -3; // System call interrupted38@Native public static final int UNSUPPORTED = -4; // Operation not supported39@Native public static final int THROWN = -5; // Exception thrown in JNI code40@Native public static final int UNSUPPORTED_CASE = -6; // This case not supported4142// The following two methods are for use in try/finally blocks where a43// status value needs to be normalized before being returned to the invoker44// but also checked for illegal negative values before the return45// completes, like so:46//47// int n = 0;48// try {49// begin();50// n = op(fd, buf, ...);51// return IOStatus.normalize(n); // Converts UNAVAILABLE to zero52// } finally {53// end(n > 0);54// assert IOStatus.check(n); // Checks other negative values55// }56//5758public static int normalize(int n) {59if (n == UNAVAILABLE)60return 0;61return n;62}6364public static boolean check(int n) {65return (n >= UNAVAILABLE);66}6768public static long normalize(long n) {69if (n == UNAVAILABLE)70return 0;71return n;72}7374public static boolean check(long n) {75return (n >= UNAVAILABLE);76}7778// Return true iff n is not one of the IOStatus values79public static boolean checkAll(long n) {80return ((n > EOF) || (n < UNSUPPORTED_CASE));81}8283/**84* Returns true if the error code is UNAVAILABLE or INTERRUPTED, the85* error codes to indicate that an I/O operation can be retried.86*/87static boolean okayToRetry(long n) {88return (n == IOStatus.UNAVAILABLE) || (n == IOStatus.INTERRUPTED);89}9091}929394