-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
39 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
final class JNI { | ||
|
||
static { | ||
System.loadLibrary("sealjni"); | ||
System.loadLibrary("seal"); | ||
} | ||
|
||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 19 additions & 49 deletions
68
app/src/main/java/com/sealdice/dice/utils/DecompressUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,30 @@ | ||
package com.sealdice.dice.utils; | ||
|
||
import android.util.Log; | ||
|
||
import java.io.*; | ||
import java.nio.file.*; | ||
import java.util.zip.GZIPInputStream; | ||
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; | ||
|
||
public class DecompressUtil { | ||
|
||
|
||
public static void decompressTar(String tarFilePath, String outputDir) throws IOException { | ||
try (FileInputStream fis = new FileInputStream(tarFilePath); | ||
TarArchiveInputStream tarArchiveInputStream = new TarArchiveInputStream(fis)) { | ||
org.apache.commons.compress.archivers.tar.TarArchiveEntry entry; | ||
|
||
while ((entry = (org.apache.commons.compress.archivers.tar.TarArchiveEntry) tarArchiveInputStream.getNextEntry()) != null) { | ||
final String individualFile = outputDir + File.separator + entry.getName(); | ||
final File file = new File(individualFile); | ||
|
||
if (entry.isDirectory()) { | ||
if (!file.exists()) { | ||
file.mkdirs(); | ||
} | ||
} else { | ||
int count; | ||
byte[] data = new byte[1024]; | ||
FileOutputStream fos = new FileOutputStream(individualFile, false); | ||
try (BufferedOutputStream dest = new BufferedOutputStream(fos, 1024)) { | ||
while ((count = tarArchiveInputStream.read(data, 0, 1024)) != -1) { | ||
dest.write(data, 0, count); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
public static void decompressTarGz(String tarGzFilePath, String outputDir) throws IOException { | ||
try (GZIPInputStream gis = new GZIPInputStream(Files.newInputStream(Paths.get(tarGzFilePath))); | ||
TarArchiveInputStream tarArchiveInputStream = new TarArchiveInputStream(gis)) { | ||
org.apache.commons.compress.archivers.tar.TarArchiveEntry entry; | ||
|
||
while ((entry = (org.apache.commons.compress.archivers.tar.TarArchiveEntry) tarArchiveInputStream.getNextEntry()) != null) { | ||
final Path outputPath = Paths.get(outputDir, entry.getName()); | ||
|
||
if (entry.isDirectory()) { | ||
Files.createDirectories(outputPath); | ||
} else if (entry.isSymbolicLink()) { | ||
// 对符号链接的处理 | ||
Path target = Paths.get(entry.getLinkName()); | ||
Files.createSymbolicLink(outputPath, target); | ||
} else { | ||
// 处理常规文件 | ||
Files.createDirectories(outputPath.getParent()); | ||
Files.copy(tarArchiveInputStream, outputPath, StandardCopyOption.REPLACE_EXISTING); | ||
} | ||
public static void decompressTarSys(String tarFilePath, String outputDir) throws IOException { | ||
// make sure the output directory exists | ||
ProcessBuilder pb = new ProcessBuilder("sh"); | ||
pb.redirectErrorStream(true); | ||
Process p = pb.start(); | ||
try (BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(p.getOutputStream())); | ||
BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()))) { | ||
bw.write("mkdir "+ outputDir + "&&tar xf " + tarFilePath + " -C " + outputDir + "\n"); | ||
Log.d("DecompressUtilSys", "tar xf " + tarFilePath + " -C " + outputDir); | ||
bw.write("exit\n"); | ||
bw.flush(); | ||
p.waitFor(); | ||
String line; | ||
while ((line = br.readLine()) != null) { | ||
Log.d("DecompressUtilSys", line); | ||
} | ||
} catch (InterruptedException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
LOCAL_PATH:= $(call my-dir) | ||
include $(CLEAR_VARS) | ||
LOCAL_MODULE:= libsealjni | ||
LOCAL_MODULE:= libseal | ||
LOCAL_SRC_FILES:= jni.c | ||
include $(BUILD_SHARED_LIBRARY) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters