use of java.io.FileOutputStream in project VirtualApp by asLody.
the class VUserManagerService method writeUserListLocked.
/*
* Writes the user list file in this format:
*
* <users nextSerialNumber="3">
* <user id="0"></user>
* <user id="2"></user>
* </users>
*/
private void writeUserListLocked() {
FileOutputStream fos = null;
AtomicFile userListFile = new AtomicFile(mUserListFile);
try {
fos = userListFile.startWrite();
final BufferedOutputStream bos = new BufferedOutputStream(fos);
// XmlSerializer serializer = XmlUtils.serializerInstance();
final XmlSerializer serializer = new FastXmlSerializer();
serializer.setOutput(bos, "utf-8");
serializer.startDocument(null, true);
serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
serializer.startTag(null, TAG_USERS);
serializer.attribute(null, ATTR_NEXT_SERIAL_NO, Integer.toString(mNextSerialNumber));
serializer.attribute(null, ATTR_USER_VERSION, Integer.toString(mUserVersion));
for (int i = 0; i < mUsers.size(); i++) {
VUserInfo user = mUsers.valueAt(i);
serializer.startTag(null, TAG_USER);
serializer.attribute(null, ATTR_ID, Integer.toString(user.id));
serializer.endTag(null, TAG_USER);
}
serializer.endTag(null, TAG_USERS);
serializer.endDocument();
userListFile.finishWrite(fos);
} catch (Exception e) {
userListFile.failWrite(fos);
VLog.e(LOG_TAG, "Error writing user list");
}
}
use of java.io.FileOutputStream in project VirtualApp by asLody.
the class VUserManagerService method writeBitmapLocked.
private void writeBitmapLocked(VUserInfo info, Bitmap bitmap) {
try {
File dir = new File(mUsersDir, Integer.toString(info.id));
File file = new File(dir, USER_PHOTO_FILENAME);
if (!dir.exists()) {
dir.mkdir();
// FileUtils.setPermissions(
// dir.getPath(),
// FileUtils.S_IRWXU|FileUtils.S_IRWXG|FileUtils.S_IXOTH,
// -1, -1);
}
FileOutputStream os;
if (bitmap.compress(Bitmap.CompressFormat.PNG, 100, os = new FileOutputStream(file))) {
info.iconPath = file.getAbsolutePath();
}
try {
os.close();
} catch (IOException ioe) {
// What the ... !
}
} catch (FileNotFoundException e) {
VLog.w(LOG_TAG, "Error setting photo for user ", e);
}
}
use of java.io.FileOutputStream in project VirtualApp by asLody.
the class PackageParserEx method savePackageCache.
public static void savePackageCache(VPackage pkg) {
final String packageName = pkg.packageName;
Parcel p = Parcel.obtain();
try {
p.writeInt(4);
pkg.writeToParcel(p, 0);
FileOutputStream fos = new FileOutputStream(VEnvironment.getPackageCacheFile(packageName));
fos.write(p.marshall());
fos.close();
} catch (Exception e) {
e.printStackTrace();
} finally {
p.recycle();
}
Signature[] signatures = pkg.mSignatures;
if (signatures != null) {
File signatureFile = VEnvironment.getSignatureFile(packageName);
if (signatureFile.exists() && !signatureFile.delete()) {
VLog.w(TAG, "Unable to delete the signatures of " + packageName);
}
p = Parcel.obtain();
try {
p.writeTypedArray(signatures, 0);
FileUtils.writeParcelToFile(p, signatureFile);
} catch (IOException e) {
e.printStackTrace();
} finally {
p.recycle();
}
}
}
use of java.io.FileOutputStream in project bazel by bazelbuild.
the class ZipReaderTest method testZip64_NumFiles.
@Test
public void testZip64_NumFiles() throws IOException {
try (ZipWriter writer = new ZipWriter(new FileOutputStream(test), UTF_8, true)) {
ZipFileEntry template = new ZipFileEntry("template");
template.setSize(0);
template.setCompressedSize(0);
template.setCrc(0);
template.setTime(ZipUtil.DOS_EPOCH);
for (int i = 0; i < 0x100ff; i++) {
ZipFileEntry entry = new ZipFileEntry(template);
entry.setName("entry" + i);
writer.putNextEntry(entry);
}
}
try (ZipReader reader = new ZipReader(test, UTF_8, true)) {
Collection<ZipFileEntry> entries = reader.entries();
assertThat(entries).hasSize(0x100ff);
}
}
use of java.io.FileOutputStream in project bazel by bazelbuild.
the class ZipReaderTest method testZip64_Zip64SizeFile.
@Test
public void testZip64_Zip64SizeFile() throws IOException {
File biggerFile = tmp.newFile("big");
try (RandomAccessFile biggerOut = new RandomAccessFile(biggerFile, "rw")) {
biggerOut.setLength(0x1000000ffL);
}
try (ZipWriter writer = new ZipWriter(new FileOutputStream(test), UTF_8, true)) {
ZipFileEntry bigEntry = new ZipFileEntry(biggerFile.getName());
bigEntry.setSize(0x1000000ffL);
bigEntry.setCompressedSize(0x1000000ffL);
bigEntry.setCrc(0);
bigEntry.setTime(ZipUtil.DOS_EPOCH);
writer.putNextEntry(bigEntry);
ByteStreams.copy(new BufferedInputStream(new FileInputStream(biggerFile)), writer);
}
try (ZipReader reader = new ZipReader(test, UTF_8)) {
Collection<ZipFileEntry> entries = reader.entries();
assertThat(entries).hasSize(1);
ZipFileEntry bigEntry = reader.getEntry(biggerFile.getName());
assertThat(bigEntry.getSize()).isEqualTo(0x1000000ffL);
}
}
Aggregations