use of de.schlichtherle.truezip.file.TFile in project codeforces-commons by Codeforces.
the class ZipUtilTest method testIsCorrectZipFileAndGetBytesInLoopAndMultipleThreads.
public void testIsCorrectZipFileAndGetBytesInLoopAndMultipleThreads() throws Exception {
File tempDir = null;
try {
String randomToken = RandomUtil.getRandomToken();
tempDir = FileUtil.createTemporaryDirectory("test-is-correct-zip-file-" + randomToken);
File emptyArchive = new File(tempDir, "empty.zip");
File invalidArchive = new File(tempDir, "invalid.zip");
File validArchive = new File(tempDir, "valid.zip");
File validInnerArchive = new File(tempDir, "valid-with-inner.zip");
FileUtil.writeFile(emptyArchive, getBytes(emptyArchive.getName()));
FileUtil.writeFile(invalidArchive, getBytes(invalidArchive.getName()));
FileUtil.writeFile(validArchive, getBytes(validArchive.getName()));
FileUtil.writeFile(validInnerArchive, getBytes(validInnerArchive.getName()));
List<AssertionError> errors = Collections.synchronizedList(new ArrayList<>());
int iterationCount = 1000;
Thread emptyArchiveTestThread = startThreadToTestIsCorrectZipFile(emptyArchive, errors, iterationCount, true, true);
Thread invalidArchiveTestThread = startThreadToTestIsCorrectZipFile(invalidArchive, errors, iterationCount, false, false);
Thread validArchiveTestThread = startThreadToTestIsCorrectZipFile(validArchive, errors, iterationCount, true, false);
Thread validInnerArchiveTestThread = startThreadToTestIsCorrectZipFile(new TFile(validInnerArchive, "valid.zip"), errors, iterationCount, true, false);
Thread directoryTestThread = startThreadToTestIsCorrectZipFile(tempDir, errors, iterationCount, false, false);
Thread getBytesTestThread = startThreadToTestGetBytes(validArchive, validInnerArchive, errors, iterationCount);
emptyArchiveTestThread.join();
invalidArchiveTestThread.join();
validArchiveTestThread.join();
validInnerArchiveTestThread.join();
directoryTestThread.join();
getBytesTestThread.join();
if (!errors.isEmpty()) {
if (errors.size() > 1) {
errors.forEach(AssertionError::printStackTrace);
}
throw errors.get(0);
}
} finally {
FileUtil.deleteTotally(tempDir);
}
}
use of de.schlichtherle.truezip.file.TFile in project codeforces-commons by Codeforces.
the class FileUtil method internalEqualsOrSameContent.
@SuppressWarnings("OverlyComplexMethod")
private static boolean internalEqualsOrSameContent(@Nonnull File fileA, @Nonnull File fileB) throws IOException {
if (fileA.equals(fileB)) {
return true;
}
if (fileA.isFile()) {
if (fileB.isFile()) {
InputStream inputStreamA = null;
InputStream inputStreamB = null;
try {
return fileA.length() == fileB.length() && IoUtil.contentEquals(inputStreamA = fileA instanceof TFile ? new TFileInputStream(fileA) : new FileInputStream(fileA), inputStreamB = fileB instanceof TFile ? new TFileInputStream(fileB) : new FileInputStream(fileB));
} finally {
IoUtil.closeQuietly(inputStreamA, inputStreamB);
}
} else {
return false;
}
}
if (fileA.isDirectory()) {
if (fileB.isDirectory()) {
File[] childrenA = fileA.listFiles();
int childACount = childrenA == null ? 0 : childrenA.length;
if (childACount != ArrayUtils.getLength(fileB.listFiles())) {
return false;
}
for (int childIndex = 0; childIndex < childACount; ++childIndex) {
File childA = childrenA[childIndex];
File childB = fileB instanceof TFile ? new TFile(fileB, childA.getName()) : new File(fileB, childA.getName());
if (!internalEqualsOrSameContent(childA, childB)) {
return false;
}
}
return true;
} else {
return false;
}
}
return false;
}
use of de.schlichtherle.truezip.file.TFile in project alfresco-repository by Alfresco.
the class ModuleManagementToolTest method checkForFileExistance.
private void checkForFileExistance(String warLocation, List<String> files) {
for (String file : files) {
File file0 = new TFile(warLocation + file);
assertTrue("The file/dir " + file + " does not exist in the WAR.", file0.exists());
}
}
use of de.schlichtherle.truezip.file.TFile in project alfresco-repository by Alfresco.
the class ModuleManagementToolTest method testListAndInstall.
public void testListAndInstall() throws Exception {
String warLocation = getFileLocation(".war", "module/test.war");
String ampLocation = getFileLocation(".amp", "module/test_v1.amp");
String ampV2Location = getFileLocation(".amp", "module/test_v2.amp");
TFile war = new TFile(warLocation);
List<ModuleDetails> details = this.manager.warHelper.listModules(war);
assertNotNull(details);
assertEquals(details.size(), 0);
this.manager.installModule(ampLocation, warLocation);
details = this.manager.warHelper.listModules(war);
assertNotNull(details);
assertEquals(details.size(), 1);
ModuleDetails aModule = details.get(0);
assertEquals("test", aModule.getId());
assertEquals("1.0", aModule.getModuleVersionNumber().toString());
this.manager.installModule(ampV2Location, warLocation);
details = this.manager.warHelper.listModules(war);
assertNotNull(details);
assertEquals(details.size(), 1);
aModule = details.get(0);
assertEquals("test", aModule.getId());
assertEquals("2.0", aModule.getModuleVersionNumber().toString());
String testAmpDepV2Location = getFileLocation(".amp", "module/dependent_on_test_v2.amp");
String testAmp7 = getFileLocation(".amp", "module/test_v7.amp");
this.manager.installModule(testAmpDepV2Location, warLocation, false, true, false);
this.manager.installModule(testAmp7, warLocation, false, true, false);
details = this.manager.warHelper.listModules(war);
assertNotNull(details);
assertEquals(details.size(), 3);
// Sort them by installation date
Collections.sort(details, new Comparator<ModuleDetails>() {
@Override
public int compare(ModuleDetails a, ModuleDetails b) {
return a.getInstallDate().compareTo(b.getInstallDate());
}
});
ModuleDetails installedModule = details.get(0);
assertEquals("test", installedModule.getId());
assertEquals("2.0", installedModule.getModuleVersionNumber().toString());
installedModule = details.get(1);
assertEquals("org.alfresco.module.test.dependent", installedModule.getId());
assertEquals("2.0", installedModule.getModuleVersionNumber().toString());
installedModule = details.get(2);
assertEquals("forcedtest", installedModule.getId());
assertEquals("1.0", installedModule.getModuleVersionNumber().toString());
}
use of de.schlichtherle.truezip.file.TFile in project alfresco-repository by Alfresco.
the class ModuleManagementToolTest method checkForFileNonExistance.
private void checkForFileNonExistance(String warLocation, List<String> files) {
for (String file : files) {
File file0 = new TFile(warLocation + file);
assertFalse("The file/dir " + file + " does exist in the WAR.", file0.exists());
}
}
Aggregations