Search in sources :

Example 76 with FileNotFoundException

use of java.io.FileNotFoundException in project platform_frameworks_base by android.

the class AppOpsService method readState.

void readState() {
    synchronized (mFile) {
        synchronized (this) {
            FileInputStream stream;
            try {
                stream = mFile.openRead();
            } catch (FileNotFoundException e) {
                Slog.i(TAG, "No existing app ops " + mFile.getBaseFile() + "; starting empty");
                return;
            }
            boolean success = false;
            mUidStates.clear();
            try {
                XmlPullParser parser = Xml.newPullParser();
                parser.setInput(stream, StandardCharsets.UTF_8.name());
                int type;
                while ((type = parser.next()) != XmlPullParser.START_TAG && type != XmlPullParser.END_DOCUMENT) {
                    ;
                }
                if (type != XmlPullParser.START_TAG) {
                    throw new IllegalStateException("no start tag found");
                }
                int outerDepth = parser.getDepth();
                while ((type = parser.next()) != XmlPullParser.END_DOCUMENT && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
                    if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
                        continue;
                    }
                    String tagName = parser.getName();
                    if (tagName.equals("pkg")) {
                        readPackage(parser);
                    } else if (tagName.equals("uid")) {
                        readUidOps(parser);
                    } else {
                        Slog.w(TAG, "Unknown element under <app-ops>: " + parser.getName());
                        XmlUtils.skipCurrentTag(parser);
                    }
                }
                success = true;
            } catch (IllegalStateException e) {
                Slog.w(TAG, "Failed parsing " + e);
            } catch (NullPointerException e) {
                Slog.w(TAG, "Failed parsing " + e);
            } catch (NumberFormatException e) {
                Slog.w(TAG, "Failed parsing " + e);
            } catch (XmlPullParserException e) {
                Slog.w(TAG, "Failed parsing " + e);
            } catch (IOException e) {
                Slog.w(TAG, "Failed parsing " + e);
            } catch (IndexOutOfBoundsException e) {
                Slog.w(TAG, "Failed parsing " + e);
            } finally {
                if (!success) {
                    mUidStates.clear();
                }
                try {
                    stream.close();
                } catch (IOException e) {
                }
            }
        }
    }
}
Also used : FileNotFoundException(java.io.FileNotFoundException) XmlPullParser(org.xmlpull.v1.XmlPullParser) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream)

Example 77 with FileNotFoundException

use of java.io.FileNotFoundException in project platform_frameworks_base by android.

the class ConnectivityService method getProvisioningUrlBaseFromFile.

private String getProvisioningUrlBaseFromFile() {
    FileReader fileReader = null;
    XmlPullParser parser = null;
    Configuration config = mContext.getResources().getConfiguration();
    try {
        fileReader = new FileReader(mProvisioningUrlFile);
        parser = Xml.newPullParser();
        parser.setInput(fileReader);
        XmlUtils.beginDocument(parser, TAG_PROVISIONING_URLS);
        while (true) {
            XmlUtils.nextElement(parser);
            String element = parser.getName();
            if (element == null)
                break;
            if (element.equals(TAG_PROVISIONING_URL)) {
                String mcc = parser.getAttributeValue(null, ATTR_MCC);
                try {
                    if (mcc != null && Integer.parseInt(mcc) == config.mcc) {
                        String mnc = parser.getAttributeValue(null, ATTR_MNC);
                        if (mnc != null && Integer.parseInt(mnc) == config.mnc) {
                            parser.next();
                            if (parser.getEventType() == XmlPullParser.TEXT) {
                                return parser.getText();
                            }
                        }
                    }
                } catch (NumberFormatException e) {
                    loge("NumberFormatException in getProvisioningUrlBaseFromFile: " + e);
                }
            }
        }
        return null;
    } catch (FileNotFoundException e) {
        loge("Carrier Provisioning Urls file not found");
    } catch (XmlPullParserException e) {
        loge("Xml parser exception reading Carrier Provisioning Urls file: " + e);
    } catch (IOException e) {
        loge("I/O exception reading Carrier Provisioning Urls file: " + e);
    } finally {
        if (fileReader != null) {
            try {
                fileReader.close();
            } catch (IOException e) {
            }
        }
    }
    return null;
}
Also used : Configuration(android.content.res.Configuration) XmlPullParser(org.xmlpull.v1.XmlPullParser) FileNotFoundException(java.io.FileNotFoundException) FileReader(java.io.FileReader) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) NetworkPolicyManager.uidRulesToString(android.net.NetworkPolicyManager.uidRulesToString) IOException(java.io.IOException)

Example 78 with FileNotFoundException

use of java.io.FileNotFoundException in project platform_frameworks_base by android.

the class AssetAtlasService method writeConfiguration.

/**
     * Writes the specified atlas configuration to the specified file.
     */
private void writeConfiguration(Configuration config, File file, String versionName) {
    BufferedWriter writer = null;
    try {
        writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file)));
        writer.write(getBuildIdentifier(versionName));
        writer.newLine();
        writer.write(config.type.toString());
        writer.newLine();
        writer.write(String.valueOf(config.width));
        writer.newLine();
        writer.write(String.valueOf(config.height));
        writer.newLine();
        writer.write(String.valueOf(config.count));
        writer.newLine();
        writer.write(String.valueOf(config.flags));
        writer.newLine();
    } catch (FileNotFoundException e) {
        Log.w(LOG_TAG, "Could not write " + file, e);
    } catch (IOException e) {
        Log.w(LOG_TAG, "Could not write " + file, e);
    } finally {
        if (writer != null) {
            try {
                writer.close();
            } catch (IOException e) {
            // Ignore
            }
        }
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) FileNotFoundException(java.io.FileNotFoundException) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) BufferedWriter(java.io.BufferedWriter)

Example 79 with FileNotFoundException

use of java.io.FileNotFoundException in project platform_frameworks_base by android.

the class PersistentDataBlockService method formatPartitionLocked.

private void formatPartitionLocked(boolean setOemUnlockEnabled) {
    DataOutputStream outputStream;
    try {
        outputStream = new DataOutputStream(new FileOutputStream(new File(mDataBlockFile)));
    } catch (FileNotFoundException e) {
        Slog.e(TAG, "partition not available?", e);
        return;
    }
    byte[] data = new byte[DIGEST_SIZE_BYTES];
    try {
        outputStream.write(data, 0, DIGEST_SIZE_BYTES);
        outputStream.writeInt(PARTITION_TYPE_MARKER);
        // data size
        outputStream.writeInt(0);
        outputStream.flush();
    } catch (IOException e) {
        Slog.e(TAG, "failed to format block", e);
        return;
    } finally {
        IoUtils.closeQuietly(outputStream);
    }
    doSetOemUnlockEnabledLocked(setOemUnlockEnabled);
    computeAndWriteDigestLocked();
}
Also used : DataOutputStream(java.io.DataOutputStream) FileOutputStream(java.io.FileOutputStream) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) File(java.io.File)

Example 80 with FileNotFoundException

use of java.io.FileNotFoundException in project jstorm by alibaba.

the class Utils method loadDefinedConf.

public static Map loadDefinedConf(String confFile) {
    File file = new File(confFile);
    if (!file.exists()) {
        return LoadConf.findAndReadYaml(confFile, true, false);
    }
    Yaml yaml = new Yaml();
    Map ret;
    try {
        ret = (Map) yaml.load(new FileReader(file));
    } catch (FileNotFoundException e) {
        ret = null;
    }
    if (ret == null)
        ret = new HashMap();
    return new HashMap(ret);
}
Also used : HashMap(java.util.HashMap) FileNotFoundException(java.io.FileNotFoundException) FileReader(java.io.FileReader) RandomAccessFile(java.io.RandomAccessFile) JarFile(java.util.jar.JarFile) ZipFile(java.util.zip.ZipFile) File(java.io.File) Map(java.util.Map) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) Yaml(org.yaml.snakeyaml.Yaml)

Aggregations

FileNotFoundException (java.io.FileNotFoundException)3572 IOException (java.io.IOException)2027 File (java.io.File)1415 FileInputStream (java.io.FileInputStream)906 InputStream (java.io.InputStream)535 FileOutputStream (java.io.FileOutputStream)522 BufferedReader (java.io.BufferedReader)301 FileReader (java.io.FileReader)267 ArrayList (java.util.ArrayList)232 Path (org.apache.hadoop.fs.Path)224 Test (org.junit.Test)212 InputStreamReader (java.io.InputStreamReader)193 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)189 XmlPullParser (org.xmlpull.v1.XmlPullParser)166 BufferedInputStream (java.io.BufferedInputStream)154 URL (java.net.URL)139 ParcelFileDescriptor (android.os.ParcelFileDescriptor)131 FileStatus (org.apache.hadoop.fs.FileStatus)131 Properties (java.util.Properties)129 HashMap (java.util.HashMap)120