Вот ошибка, которую я получаю, когда пытаюсь разархивировать файл :
Код: Выделить всё
Archive: test2MB.zip
End-of-central-directory signature not found. Either this file is not
a zipfile, or it constitutes one disk of a multi-part archive. In the
latter case the central directory and zipfile comment will be found on
the last disk(s) of this archive.
unzip: cannot find zipfile directory in one of test2MB.zip or
test2MB.zip.zip, and cannot find test2MB.zip.ZIP, period.
Код: Выделить всё
private Single zipAndUploadZipParts(String uploadId) {
List uploadPartObservables = new ArrayList();
final int[] partNumber = {Constants.START_PART_NUMBER};
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
ZipOutputStream zipOutputStream = new ZipOutputStream(byteArrayOutputStream);
return zipMetadata(zipOutputStream)
.andThen(uploadZipPart(byteArrayOutputStream, uploadPartObservables, partNumber, uploadId)
.onErrorResumeNext(error -> {
this.contextRx.log().error(String.format("placeholder", partNumber[0], this.logIdentifier, error.getMessage()), error);
return Completable.error(new RuntimeException("Placeholder"));
}))
.andThen(finalizeZipUpload(uploadPartObservables, zipOutputStream, byteArrayOutputStream));
}
Код: Выделить всё
private Completable zipMetadata(ZipOutputStream zipOutputStream) {
return Completable.create(emitter -> {
try {
ZipEntry metadataEntry = new ZipEntry(Constants.METADATA_FILE_NAME);
zipOutputStream.putNextEntry(metadataEntry);
zipOutputStream.write(this.catalogObjectsMetadata.getBytes());
zipOutputStream.closeEntry();
emitter.onComplete();
} catch (IOException exception) {
this.contextRx.log().error(String.format(Constants.LOG_ERROR_ZIPPING_METADATA, this.logIdentifier, exception.getMessage()), exception);
emitter.onError(new RuntimeException(String.format(Constants.ERROR_ZIPPING_METADATA)));
}
});
}
Код: Выделить всё
private Completable uploadZipPart(ByteArrayOutputStream byteArrayOutputStream, List uploadPartObservables, int[] partNumber, String uploadId) {
return Completable.create(emitter -> {
try {
byte[] zipData = byteArrayOutputStream.toByteArray();
uploadPartObservables.add(uploadPart(zipData, partNumber[0]++, uploadId));
byteArrayOutputStream.reset();
this.contextRx.log().info(String.format("Uploaded part %d for uploadId %s", partNumber[0] - 1, uploadId));
emitter.onComplete();
} catch (Exception exception) {
emitter.onError(exception);
}
});
}
Код: Выделить всё
private Single finalizeZipUpload(List uploadPartObservables, ZipOutputStream zipOutputStream, ByteArrayOutputStream byteArrayOutputStream) {
return Single.defer(() -> {
try {
zipOutputStream.finish();
} catch (IOException e) {
return Single.error(new RuntimeException("Error finishing zip output stream", e));
} finally {
try {
zipOutputStream.close();
} catch (IOException e) {
return Single.error(new RuntimeException("Error closing zip output stream", e));
}
try {
byteArrayOutputStream.close();
} catch (IOException e) {
return Single.error(new RuntimeException("Error closing byte array output stream", e));
}
}
return Single.merge(uploadPartObservables)
.toList()
.doOnSuccess(parts -> this.contextRx.log().info(String.format(Constants.ALL_PARTS_UPLOADED, this.logIdentifier, parts)))
.onErrorReturnItem(new ArrayList());
});
}
Содержимое внутри zip-файла не должно быть повреждено.< /п>
Подробнее здесь: https://stackoverflow.com/questions/788 ... -in-rxjava
Мобильная версия