Search in sources :

Example 56 with EOFException

use of java.io.EOFException in project UltimateAndroid by cymcsg.

the class DiskLruCache method readJournal.

private void readJournal() throws IOException {
    StrictLineReader reader = new StrictLineReader(new FileInputStream(journalFile), Util.US_ASCII);
    try {
        String magic = reader.readLine();
        String version = reader.readLine();
        String appVersionString = reader.readLine();
        String valueCountString = reader.readLine();
        String blank = reader.readLine();
        if (!MAGIC.equals(magic) || !VERSION_1.equals(version) || !Integer.toString(appVersion).equals(appVersionString) || !Integer.toString(valueCount).equals(valueCountString) || !"".equals(blank)) {
            throw new IOException("unexpected journal header: [" + magic + ", " + version + ", " + valueCountString + ", " + blank + "]");
        }
        int lineCount = 0;
        while (true) {
            try {
                readJournalLine(reader.readLine());
                lineCount++;
            } catch (EOFException endOfJournal) {
                break;
            }
        }
        redundantOpCount = lineCount - lruEntries.size();
    } finally {
        Util.closeQuietly(reader);
    }
}
Also used : EOFException(java.io.EOFException) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream)

Example 57 with EOFException

use of java.io.EOFException in project android_frameworks_base by DirtyUnicorns.

the class OMAConstants method deserializeString.

public static String deserializeString(InputStream in) throws IOException {
    StringBuilder prefix = new StringBuilder();
    for (; ; ) {
        byte b = (byte) in.read();
        if (b == '.')
            return null;
        else if (b == ':')
            break;
        else if (b > ' ')
            prefix.append((char) b);
    }
    int length = Integer.parseInt(prefix.toString(), 16);
    byte[] octets = new byte[length];
    int offset = 0;
    while (offset < octets.length) {
        int amount = in.read(octets, offset, octets.length - offset);
        if (amount <= 0)
            throw new EOFException();
        offset += amount;
    }
    return new String(octets, StandardCharsets.UTF_8);
}
Also used : EOFException(java.io.EOFException)

Example 58 with EOFException

use of java.io.EOFException in project android_frameworks_base by DirtyUnicorns.

the class BlobBackupHelper method readOldState.

// Internal implementation
/*
     * State on-disk format:
     * [Int]    : overall blob version number
     * [Int=N] : number of keys represented in the state blob
     * N* :
     *     [String] key
     *     [Long]   blob checksum, calculated after compression
     */
@SuppressWarnings("resource")
private ArrayMap<String, Long> readOldState(ParcelFileDescriptor oldStateFd) {
    final ArrayMap<String, Long> state = new ArrayMap<String, Long>();
    FileInputStream fis = new FileInputStream(oldStateFd.getFileDescriptor());
    DataInputStream in = new DataInputStream(fis);
    try {
        int version = in.readInt();
        if (version <= mCurrentBlobVersion) {
            final int numKeys = in.readInt();
            if (DEBUG) {
                Log.i(TAG, "  " + numKeys + " keys in state record");
            }
            for (int i = 0; i < numKeys; i++) {
                String key = in.readUTF();
                long checksum = in.readLong();
                if (DEBUG) {
                    Log.i(TAG, "  key '" + key + "' checksum is " + checksum);
                }
                state.put(key, checksum);
            }
        } else {
            Log.w(TAG, "Prior state from unrecognized version " + version);
        }
    } catch (EOFException e) {
        // is truncated we just treat it the same way.
        if (DEBUG) {
            Log.i(TAG, "Hit EOF reading prior state");
        }
        state.clear();
    } catch (Exception e) {
        Log.e(TAG, "Error examining prior backup state " + e.getMessage());
        state.clear();
    }
    return state;
}
Also used : EOFException(java.io.EOFException) ArrayMap(android.util.ArrayMap) DataInputStream(java.io.DataInputStream) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) EOFException(java.io.EOFException)

Example 59 with EOFException

use of java.io.EOFException in project android_frameworks_base by DirtyUnicorns.

the class IpConfigStore method readIpAndProxyConfigurations.

public SparseArray<IpConfiguration> readIpAndProxyConfigurations(String filePath) {
    SparseArray<IpConfiguration> networks = new SparseArray<IpConfiguration>();
    DataInputStream in = null;
    try {
        in = new DataInputStream(new BufferedInputStream(new FileInputStream(filePath)));
        int version = in.readInt();
        if (version != 2 && version != 1) {
            loge("Bad version on IP configuration file, ignore read");
            return null;
        }
        while (true) {
            int id = -1;
            // Default is DHCP with no proxy
            IpAssignment ipAssignment = IpAssignment.DHCP;
            ProxySettings proxySettings = ProxySettings.NONE;
            StaticIpConfiguration staticIpConfiguration = new StaticIpConfiguration();
            String proxyHost = null;
            String pacFileUrl = null;
            int proxyPort = -1;
            String exclusionList = null;
            String key;
            do {
                key = in.readUTF();
                try {
                    if (key.equals(ID_KEY)) {
                        id = in.readInt();
                    } else if (key.equals(IP_ASSIGNMENT_KEY)) {
                        ipAssignment = IpAssignment.valueOf(in.readUTF());
                    } else if (key.equals(LINK_ADDRESS_KEY)) {
                        LinkAddress linkAddr = new LinkAddress(NetworkUtils.numericToInetAddress(in.readUTF()), in.readInt());
                        if (linkAddr.getAddress() instanceof Inet4Address && staticIpConfiguration.ipAddress == null) {
                            staticIpConfiguration.ipAddress = linkAddr;
                        } else {
                            loge("Non-IPv4 or duplicate address: " + linkAddr);
                        }
                    } else if (key.equals(GATEWAY_KEY)) {
                        LinkAddress dest = null;
                        InetAddress gateway = null;
                        if (version == 1) {
                            // only supported default gateways - leave the dest/prefix empty
                            gateway = NetworkUtils.numericToInetAddress(in.readUTF());
                            if (staticIpConfiguration.gateway == null) {
                                staticIpConfiguration.gateway = gateway;
                            } else {
                                loge("Duplicate gateway: " + gateway.getHostAddress());
                            }
                        } else {
                            if (in.readInt() == 1) {
                                dest = new LinkAddress(NetworkUtils.numericToInetAddress(in.readUTF()), in.readInt());
                            }
                            if (in.readInt() == 1) {
                                gateway = NetworkUtils.numericToInetAddress(in.readUTF());
                            }
                            RouteInfo route = new RouteInfo(dest, gateway);
                            if (route.isIPv4Default() && staticIpConfiguration.gateway == null) {
                                staticIpConfiguration.gateway = gateway;
                            } else {
                                loge("Non-IPv4 default or duplicate route: " + route);
                            }
                        }
                    } else if (key.equals(DNS_KEY)) {
                        staticIpConfiguration.dnsServers.add(NetworkUtils.numericToInetAddress(in.readUTF()));
                    } else if (key.equals(PROXY_SETTINGS_KEY)) {
                        proxySettings = ProxySettings.valueOf(in.readUTF());
                    } else if (key.equals(PROXY_HOST_KEY)) {
                        proxyHost = in.readUTF();
                    } else if (key.equals(PROXY_PORT_KEY)) {
                        proxyPort = in.readInt();
                    } else if (key.equals(PROXY_PAC_FILE)) {
                        pacFileUrl = in.readUTF();
                    } else if (key.equals(EXCLUSION_LIST_KEY)) {
                        exclusionList = in.readUTF();
                    } else if (key.equals(EOS)) {
                        break;
                    } else {
                        loge("Ignore unknown key " + key + "while reading");
                    }
                } catch (IllegalArgumentException e) {
                    loge("Ignore invalid address while reading" + e);
                }
            } while (true);
            if (id != -1) {
                IpConfiguration config = new IpConfiguration();
                networks.put(id, config);
                switch(ipAssignment) {
                    case STATIC:
                        config.staticIpConfiguration = staticIpConfiguration;
                        config.ipAssignment = ipAssignment;
                        break;
                    case DHCP:
                        config.ipAssignment = ipAssignment;
                        break;
                    case UNASSIGNED:
                        loge("BUG: Found UNASSIGNED IP on file, use DHCP");
                        config.ipAssignment = IpAssignment.DHCP;
                        break;
                    default:
                        loge("Ignore invalid ip assignment while reading.");
                        config.ipAssignment = IpAssignment.UNASSIGNED;
                        break;
                }
                switch(proxySettings) {
                    case STATIC:
                        ProxyInfo proxyInfo = new ProxyInfo(proxyHost, proxyPort, exclusionList);
                        config.proxySettings = proxySettings;
                        config.httpProxy = proxyInfo;
                        break;
                    case PAC:
                        ProxyInfo proxyPacProperties = new ProxyInfo(pacFileUrl);
                        config.proxySettings = proxySettings;
                        config.httpProxy = proxyPacProperties;
                        break;
                    case NONE:
                        config.proxySettings = proxySettings;
                        break;
                    case UNASSIGNED:
                        loge("BUG: Found UNASSIGNED proxy on file, use NONE");
                        config.proxySettings = ProxySettings.NONE;
                        break;
                    default:
                        loge("Ignore invalid proxy settings while reading");
                        config.proxySettings = ProxySettings.UNASSIGNED;
                        break;
                }
            } else {
                if (DBG)
                    log("Missing id while parsing configuration");
            }
        }
    } catch (EOFException ignore) {
    } catch (IOException e) {
        loge("Error parsing configuration: " + e);
    } finally {
        if (in != null) {
            try {
                in.close();
            } catch (Exception e) {
            }
        }
    }
    return networks;
}
Also used : LinkAddress(android.net.LinkAddress) Inet4Address(java.net.Inet4Address) IpConfiguration(android.net.IpConfiguration) StaticIpConfiguration(android.net.StaticIpConfiguration) IpAssignment(android.net.IpConfiguration.IpAssignment) ProxySettings(android.net.IpConfiguration.ProxySettings) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) EOFException(java.io.EOFException) ProxyInfo(android.net.ProxyInfo) SparseArray(android.util.SparseArray) BufferedInputStream(java.io.BufferedInputStream) StaticIpConfiguration(android.net.StaticIpConfiguration) EOFException(java.io.EOFException) RouteInfo(android.net.RouteInfo) InetAddress(java.net.InetAddress)

Example 60 with EOFException

use of java.io.EOFException in project jdk8u_jdk by JetBrains.

the class GlobalFilterTest method testGlobalPattern.

/**
     * Serialize and deserialize an object using the default process-wide filter
     * and check allowed or reject.
     *
     * @param pattern the pattern
     * @param object the test object
     * @param allowed the expected result from ObjectInputStream (exception or not)
     */
static void testGlobalPattern(String pattern, Object object, boolean allowed) {
    try {
        //            System.out.printf("global %s pattern: %s, obj: %s%n", (allowed ? "allowed" : "not allowed"), pattern, object);
        byte[] bytes = SerialFilterTest.writeObjects(object);
        try (ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
            ObjectInputStream ois = new ObjectInputStream(bais)) {
            Object o = ois.readObject();
        } catch (EOFException eof) {
        // normal completion
        } catch (ClassNotFoundException cnf) {
            Assert.fail("Deserializing", cnf);
        }
        Assert.assertTrue(allowed, "filter should have thrown an exception");
    } catch (IllegalArgumentException iae) {
        Assert.fail("bad format pattern", iae);
    } catch (InvalidClassException ice) {
        Assert.assertFalse(allowed, "filter should not have thrown an exception: " + ice);
    } catch (IOException ioe) {
        Assert.fail("Unexpected IOException", ioe);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InvalidClassException(java.io.InvalidClassException) EOFException(java.io.EOFException) IOException(java.io.IOException) ObjectInputStream(java.io.ObjectInputStream)

Aggregations

EOFException (java.io.EOFException)1149 IOException (java.io.IOException)508 DataInputStream (java.io.DataInputStream)139 FileInputStream (java.io.FileInputStream)124 InputStream (java.io.InputStream)100 ByteArrayInputStream (java.io.ByteArrayInputStream)95 ArrayList (java.util.ArrayList)84 Test (org.junit.Test)84 ByteBuffer (java.nio.ByteBuffer)75 File (java.io.File)74 FileNotFoundException (java.io.FileNotFoundException)61 BufferedInputStream (java.io.BufferedInputStream)56 RandomAccessFile (java.io.RandomAccessFile)46 SocketTimeoutException (java.net.SocketTimeoutException)43 HashMap (java.util.HashMap)38 ByteArrayOutputStream (java.io.ByteArrayOutputStream)32 SocketException (java.net.SocketException)31 Map (java.util.Map)30 InterruptedIOException (java.io.InterruptedIOException)29 Path (org.apache.hadoop.fs.Path)29