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) {
}
}
}
}
}
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;
}
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
}
}
}
}
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();
}
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);
}
Aggregations