use of java.io.FileOutputStream in project bazel by bazelbuild.
the class ZipReaderTest method testSimultaneousReads.
@Test
public void testSimultaneousReads() throws IOException {
byte[] expectedFooData = "This is file foo. It contains a foo.".getBytes(UTF_8);
byte[] expectedBarData = "This is a different file bar. It contains only a bar.".getBytes(UTF_8);
try (ZipOutputStream zout = new ZipOutputStream(new FileOutputStream(test))) {
ZipEntry foo = new ZipEntry("foo");
foo.setComment("foo comment.");
foo.setMethod(ZipEntry.DEFLATED);
zout.putNextEntry(foo);
zout.write(expectedFooData);
zout.closeEntry();
ZipEntry bar = new ZipEntry("bar");
bar.setComment("bar comment.");
bar.setMethod(ZipEntry.DEFLATED);
zout.putNextEntry(bar);
zout.write(expectedBarData);
zout.closeEntry();
}
try (ZipReader reader = new ZipReader(test, UTF_8)) {
ZipFileEntry fooEntry = reader.getEntry("foo");
ZipFileEntry barEntry = reader.getEntry("bar");
InputStream fooIn = reader.getInputStream(fooEntry);
InputStream barIn = reader.getInputStream(barEntry);
byte[] fooData = new byte[expectedFooData.length];
byte[] barData = new byte[expectedBarData.length];
fooIn.read(fooData, 0, 10);
barIn.read(barData, 0, 10);
fooIn.read(fooData, 10, 10);
barIn.read(barData, 10, 10);
fooIn.read(fooData, 20, fooData.length - 20);
barIn.read(barData, 20, barData.length - 20);
assertThat(fooData).isEqualTo(expectedFooData);
assertThat(barData).isEqualTo(expectedBarData);
}
}
use of java.io.FileOutputStream in project bazel by bazelbuild.
the class ZipReaderTest method testZipEntryInvalidTime.
@Test
public void testZipEntryInvalidTime() throws IOException {
// 11/30/1979 00:00:00, which is also 0 in DOS format
long date = 312796800000L;
byte[] extra = new ExtraData((short) 0xaa, new byte[] { (byte) 0xbb, (byte) 0xcd }).getBytes();
try (ZipOutputStream zout = new ZipOutputStream(new FileOutputStream(test))) {
ZipEntry foo = new ZipEntry("foo");
foo.setComment("foo comment.");
foo.setMethod(ZipEntry.DEFLATED);
foo.setTime(date);
foo.setExtra(extra);
zout.putNextEntry(foo);
zout.write("foo".getBytes(UTF_8));
zout.closeEntry();
}
try (ZipReader reader = new ZipReader(test, UTF_8)) {
ZipFileEntry fooEntry = reader.getEntry("foo");
assertThat(fooEntry.getTime()).isEqualTo(ZipUtil.DOS_EPOCH);
}
}
use of java.io.FileOutputStream in project bazel by bazelbuild.
the class ZipReaderTest method testZip64_FileCount_Zip64Range_ForceZip32.
@Test
public void testZip64_FileCount_Zip64Range_ForceZip32() throws IOException {
try (ZipWriter writer = new ZipWriter(new FileOutputStream(test), UTF_8, false)) {
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)) {
assertThat(reader.size()).isEqualTo(0x100ff);
}
try (ZipReader reader = new ZipReader(test, UTF_8, true)) {
assertThat(reader.size()).isEqualTo(0x00ff);
}
}
use of java.io.FileOutputStream in project VirtualApp by asLody.
the class VAccountManagerService method saveAllAccounts.
/**
* Serializing all accounts
*/
private void saveAllAccounts() {
File accountFile = VEnvironment.getAccountConfigFile();
Parcel dest = Parcel.obtain();
try {
dest.writeInt(1);
List<VAccount> accounts = new ArrayList<>();
for (int i = 0; i < this.accountsByUserId.size(); i++) {
List<VAccount> list = this.accountsByUserId.valueAt(i);
if (list != null) {
accounts.addAll(list);
}
}
dest.writeInt(accounts.size());
for (VAccount account : accounts) {
account.writeToParcel(dest, 0);
}
dest.writeLong(lastAccountChangeTime);
FileOutputStream fileOutputStream = new FileOutputStream(accountFile);
fileOutputStream.write(dest.marshall());
fileOutputStream.close();
} catch (Exception e) {
e.printStackTrace();
}
dest.recycle();
}
use of java.io.FileOutputStream in project VirtualApp by asLody.
the class UidSystem method save.
private void save() {
File uidFile = VEnvironment.getUidListFile();
File bakUidFile = VEnvironment.getBakUidListFile();
if (uidFile.exists()) {
if (bakUidFile.exists() && !bakUidFile.delete()) {
VLog.w(TAG, "Warning: Unable to delete the expired file --\n " + bakUidFile.getPath());
}
try {
FileUtils.copyFile(uidFile, bakUidFile);
} catch (IOException e) {
e.printStackTrace();
}
}
try {
ObjectOutputStream os = new ObjectOutputStream(new FileOutputStream(uidFile));
os.writeInt(mFreeUid);
os.writeObject(mSharedUserIdMap);
os.close();
} catch (IOException e) {
e.printStackTrace();
}
}
Aggregations