-
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
10 changed files
with
344 additions
and
10 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
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.sealdice.dice; | ||
|
||
final class JNI { | ||
|
||
static { | ||
System.loadLibrary("sealjni"); | ||
} | ||
|
||
/** | ||
* Create a subprocess. Differs from {@link ProcessBuilder} in that a pseudoterminal is used to communicate with the | ||
* subprocess. | ||
* <p/> | ||
* Callers are responsible for calling {@link #close(int)} on the returned file descriptor. | ||
* | ||
* @param cmd The command to execute | ||
* @param cwd The current working directory for the executed command | ||
* @param args An array of arguments to the command | ||
* @param envVars An array of strings of the form "VAR=value" to be added to the environment of the process | ||
* @param processId A one-element array to which the process ID of the started process will be written. | ||
* @return the file descriptor resulting from opening /dev/ptmx master device. The sub process will have opened the | ||
* slave device counterpart (/dev/pts/$N) and have it as stdint, stdout and stderr. | ||
*/ | ||
public static native int createSubprocess(String cmd, String cwd, String[] args, String[] envVars, int[] processId, int rows, int columns); | ||
|
||
/** Set the window size for a given pty, which allows connected programs to learn how large their screen is. */ | ||
public static native void setPtyWindowSize(int fd, int rows, int cols); | ||
|
||
/** | ||
* Causes the calling thread to wait for the process associated with the receiver to finish executing. | ||
* | ||
* @return if >= 0, the exit status of the process. If < 0, the signal causing the process to stop negated. | ||
*/ | ||
public static native int waitFor(int processId); | ||
|
||
/** Close a file descriptor through the close(2) system call. */ | ||
public static native void close(int fileDescriptor); | ||
|
||
} |
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
60 changes: 60 additions & 0 deletions
60
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 |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package com.sealdice.dice.utils; | ||
|
||
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); | ||
} | ||
} | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
LOCAL_PATH:= $(call my-dir) | ||
include $(CLEAR_VARS) | ||
LOCAL_MODULE:= libsealjni | ||
LOCAL_SRC_FILES:= jni.c | ||
include $(BUILD_SHARED_LIBRARY) |
Oops, something went wrong.