mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-25 05:41:12 +00:00
Bug 1694481 - Remove unused NativeZip. r=aklotz
Differential Revision: https://phabricator.services.mozilla.com/D106180
This commit is contained in:
parent
b39485034a
commit
71dbca3068
@ -1,84 +0,0 @@
|
||||
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*-
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
package org.mozilla.gecko.mozglue;
|
||||
|
||||
import androidx.annotation.Keep;
|
||||
import org.mozilla.gecko.annotation.JNITarget;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.zip.Inflater;
|
||||
import java.util.zip.InflaterInputStream;
|
||||
|
||||
public class NativeZip implements NativeReference {
|
||||
private static final int DEFLATE = 8;
|
||||
private static final int STORE = 0;
|
||||
|
||||
private volatile long mObj;
|
||||
@Keep
|
||||
private InputStream mInput;
|
||||
|
||||
public NativeZip(final String path) {
|
||||
mObj = getZip(path);
|
||||
}
|
||||
|
||||
public NativeZip(final InputStream input) {
|
||||
if (!(input instanceof ByteBufferInputStream)) {
|
||||
throw new IllegalArgumentException("Got " + input.getClass()
|
||||
+ ", but expected ByteBufferInputStream!");
|
||||
}
|
||||
ByteBufferInputStream bbinput = (ByteBufferInputStream)input;
|
||||
mObj = getZipFromByteBuffer(bbinput.mBuf);
|
||||
mInput = input;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void finalize() {
|
||||
release();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void release() {
|
||||
if (mObj != 0) {
|
||||
_release(mObj);
|
||||
mObj = 0;
|
||||
}
|
||||
mInput = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isReleased() {
|
||||
return (mObj == 0);
|
||||
}
|
||||
|
||||
public InputStream getInputStream(final String path) {
|
||||
if (isReleased()) {
|
||||
throw new IllegalStateException("Can't get path \"" + path
|
||||
+ "\" because NativeZip is closed!");
|
||||
}
|
||||
return _getInputStream(mObj, path);
|
||||
}
|
||||
|
||||
private static native long getZip(String path);
|
||||
private static native long getZipFromByteBuffer(ByteBuffer buffer);
|
||||
private static native void _release(long obj);
|
||||
private native InputStream _getInputStream(long obj, String path);
|
||||
|
||||
@JNITarget
|
||||
private InputStream createInputStream(final ByteBuffer buffer, final int compression) {
|
||||
if (compression != STORE && compression != DEFLATE) {
|
||||
throw new IllegalArgumentException("Unexpected compression: " + compression);
|
||||
}
|
||||
|
||||
InputStream input = new ByteBufferInputStream(buffer, this);
|
||||
if (compression == DEFLATE) {
|
||||
Inflater inflater = new Inflater(true);
|
||||
input = new InflaterInputStream(input, inflater);
|
||||
}
|
||||
|
||||
return input;
|
||||
}
|
||||
}
|
@ -44,79 +44,6 @@ Java_org_mozilla_gecko_mozglue_GeckoLoader_verifyCRCs(JNIEnv* jenv, jclass,
|
||||
return jboolean(valid);
|
||||
}
|
||||
|
||||
extern "C" __attribute__((visibility("default"))) jlong MOZ_JNICALL
|
||||
Java_org_mozilla_gecko_mozglue_NativeZip_getZip(JNIEnv* jenv, jclass,
|
||||
jstring path) {
|
||||
const char* str;
|
||||
str = jenv->GetStringUTFChars(path, nullptr);
|
||||
if (!str || !*str) {
|
||||
if (str) jenv->ReleaseStringUTFChars(path, str);
|
||||
JNI_Throw(jenv, "java/lang/IllegalArgumentException", "Invalid path");
|
||||
return 0;
|
||||
}
|
||||
RefPtr<Zip> zip = ZipCollection::GetZip(str);
|
||||
jenv->ReleaseStringUTFChars(path, str);
|
||||
if (!zip) {
|
||||
JNI_Throw(jenv, "java/lang/IllegalArgumentException",
|
||||
"Invalid path or invalid zip");
|
||||
return 0;
|
||||
}
|
||||
return reinterpret_cast<jlong>(zip.forget().take());
|
||||
}
|
||||
|
||||
extern "C" __attribute__((visibility("default"))) jlong MOZ_JNICALL
|
||||
Java_org_mozilla_gecko_mozglue_NativeZip_getZipFromByteBuffer(JNIEnv* jenv,
|
||||
jclass,
|
||||
jobject buffer) {
|
||||
void* buf = jenv->GetDirectBufferAddress(buffer);
|
||||
size_t size = jenv->GetDirectBufferCapacity(buffer);
|
||||
RefPtr<Zip> zip = Zip::Create(buf, size);
|
||||
if (!zip) {
|
||||
JNI_Throw(jenv, "java/lang/IllegalArgumentException", "Invalid zip");
|
||||
return 0;
|
||||
}
|
||||
return reinterpret_cast<jlong>(zip.forget().take());
|
||||
}
|
||||
|
||||
extern "C" __attribute__((visibility("default"))) void MOZ_JNICALL
|
||||
Java_org_mozilla_gecko_mozglue_NativeZip__1release(JNIEnv* jenv, jclass,
|
||||
jlong obj) {
|
||||
Zip* zip = (Zip*)obj;
|
||||
zip->Release();
|
||||
}
|
||||
|
||||
extern "C" __attribute__((visibility("default"))) jobject MOZ_JNICALL
|
||||
Java_org_mozilla_gecko_mozglue_NativeZip__1getInputStream(JNIEnv* jenv,
|
||||
jobject jzip,
|
||||
jlong obj,
|
||||
jstring path) {
|
||||
Zip* zip = (Zip*)obj;
|
||||
const char* str;
|
||||
str = jenv->GetStringUTFChars(path, nullptr);
|
||||
|
||||
Zip::Stream stream;
|
||||
bool res = zip->GetStream(str, &stream);
|
||||
jenv->ReleaseStringUTFChars(path, str);
|
||||
if (!res) {
|
||||
return nullptr;
|
||||
}
|
||||
jobject buf = jenv->NewDirectByteBuffer(const_cast<void*>(stream.GetBuffer()),
|
||||
stream.GetSize());
|
||||
if (!buf) {
|
||||
JNI_Throw(jenv, "java/lang/RuntimeException",
|
||||
"Failed to create ByteBuffer");
|
||||
return nullptr;
|
||||
}
|
||||
jclass nativeZip = jenv->GetObjectClass(jzip);
|
||||
jmethodID method =
|
||||
jenv->GetMethodID(nativeZip, "createInputStream",
|
||||
"(Ljava/nio/ByteBuffer;I)Ljava/io/InputStream;");
|
||||
// Since this function is only expected to be called from Java, it is safe
|
||||
// to skip exception checking for the method call below, as long as no
|
||||
// other Native -> Java call doesn't happen before returning to Java.
|
||||
return jenv->CallObjectMethod(jzip, method, buf, (jint)stream.GetType());
|
||||
}
|
||||
|
||||
#ifdef MOZ_CRASHREPORTER
|
||||
|
||||
extern "C" __attribute__((visibility("default"))) jboolean MOZ_JNICALL
|
||||
|
Loading…
Reference in New Issue
Block a user