use of org.xmlpull.v1.XmlPullParserException in project platform_frameworks_base by android.
the class ParserFactory method readAndClose.
@NonNull
private static InputStream readAndClose(@NonNull InputStream stream, @Nullable String name, long size) throws XmlPullParserException {
// just a sanity check. It's doubtful we'll have such big files!
if (size > Integer.MAX_VALUE) {
throw new XmlPullParserException("File " + name + " is too big to be parsed");
}
int intSize = (int) size;
// create a buffered reader to facilitate reading.
BufferedInputStream bufferedStream = new BufferedInputStream(stream);
try {
int avail;
if (intSize != -1) {
avail = intSize;
} else {
// get the size to read.
avail = bufferedStream.available();
}
// create the initial buffer and read it.
byte[] buffer = new byte[avail];
int read = stream.read(buffer);
// this is the easy case.
if (read == intSize) {
return new ByteArrayInputStream(buffer);
}
// available() returned!)
while ((avail = bufferedStream.available()) > 0) {
if (read + avail > buffer.length) {
// just allocate what is needed. We're mostly reading small files
// so it shouldn't be too problematic.
byte[] moreBuffer = new byte[read + avail];
System.arraycopy(buffer, 0, moreBuffer, 0, read);
buffer = moreBuffer;
}
read += stream.read(buffer, read, avail);
}
// return a new stream encapsulating this buffer.
return new ByteArrayInputStream(buffer);
} catch (IOException e) {
throw new XmlPullParserException("Failed to read " + name, null, e);
} finally {
try {
bufferedStream.close();
} catch (IOException ignored) {
}
}
}
use of org.xmlpull.v1.XmlPullParserException in project platform_frameworks_base by android.
the class PersistentDataStore method load.
private void load() {
clearState();
final InputStream is;
try {
is = mAtomicFile.openRead();
} catch (FileNotFoundException ex) {
return;
}
XmlPullParser parser;
try {
parser = Xml.newPullParser();
parser.setInput(new BufferedInputStream(is), StandardCharsets.UTF_8.name());
loadFromXml(parser);
} catch (IOException ex) {
Slog.w(InputManagerService.TAG, "Failed to load input manager persistent store data.", ex);
clearState();
} catch (XmlPullParserException ex) {
Slog.w(InputManagerService.TAG, "Failed to load input manager persistent store data.", ex);
clearState();
} finally {
IoUtils.closeQuietly(is);
}
}
use of org.xmlpull.v1.XmlPullParserException in project platform_frameworks_base by android.
the class PackageManagerService method restorePreferredActivities.
@Override
public void restorePreferredActivities(byte[] backup, int userId) {
if (Binder.getCallingUid() != Process.SYSTEM_UID) {
throw new SecurityException("Only the system may call restorePreferredActivities()");
}
try {
final XmlPullParser parser = Xml.newPullParser();
parser.setInput(new ByteArrayInputStream(backup), StandardCharsets.UTF_8.name());
restoreFromXml(parser, userId, TAG_PREFERRED_BACKUP, new BlobXmlRestorer() {
@Override
public void apply(XmlPullParser parser, int userId) throws XmlPullParserException, IOException {
synchronized (mPackages) {
mSettings.readPreferredActivitiesLPw(parser, userId);
}
}
});
} catch (Exception e) {
if (DEBUG_BACKUP) {
Slog.e(TAG, "Exception restoring preferred activities: " + e.getMessage());
}
}
}
use of org.xmlpull.v1.XmlPullParserException in project platform_frameworks_base by android.
the class PackageManagerService method restorePermissionGrants.
@Override
public void restorePermissionGrants(byte[] backup, int userId) {
if (Binder.getCallingUid() != Process.SYSTEM_UID) {
throw new SecurityException("Only the system may call restorePermissionGrants()");
}
try {
final XmlPullParser parser = Xml.newPullParser();
parser.setInput(new ByteArrayInputStream(backup), StandardCharsets.UTF_8.name());
restoreFromXml(parser, userId, TAG_PERMISSION_BACKUP, new BlobXmlRestorer() {
@Override
public void apply(XmlPullParser parser, int userId) throws XmlPullParserException, IOException {
synchronized (mPackages) {
processRestoredPermissionGrantsLPr(parser, userId);
}
}
});
} catch (Exception e) {
if (DEBUG_BACKUP) {
Slog.e(TAG, "Exception restoring preferred activities: " + e.getMessage());
}
}
}
use of org.xmlpull.v1.XmlPullParserException in project platform_frameworks_base by android.
the class BootReceiver method readTimestamps.
private static HashMap<String, Long> readTimestamps() {
synchronized (sFile) {
HashMap<String, Long> timestamps = new HashMap<String, Long>();
boolean success = false;
try (final FileInputStream stream = sFile.openRead()) {
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");
}
// Skip the outer <log-files> tag.
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("log")) {
final String filename = parser.getAttributeValue(null, "filename");
final long timestamp = Long.valueOf(parser.getAttributeValue(null, "timestamp"));
timestamps.put(filename, timestamp);
} else {
Slog.w(TAG, "Unknown tag: " + parser.getName());
XmlUtils.skipCurrentTag(parser);
}
}
success = true;
} catch (FileNotFoundException e) {
Slog.i(TAG, "No existing last log timestamp file " + sFile.getBaseFile() + "; starting empty");
} catch (IOException e) {
Slog.w(TAG, "Failed parsing " + e);
} catch (IllegalStateException e) {
Slog.w(TAG, "Failed parsing " + e);
} catch (NullPointerException e) {
Slog.w(TAG, "Failed parsing " + e);
} catch (XmlPullParserException e) {
Slog.w(TAG, "Failed parsing " + e);
} finally {
if (!success) {
timestamps.clear();
}
}
return timestamps;
}
}
Aggregations