新增 连接电脑支持运行和保存项目

This commit is contained in:
hyb1996
2018-10-19 15:27:09 +08:00
parent a6bea15ca0
commit 78e0d6b088
15 changed files with 605 additions and 38 deletions

View File

@@ -9,6 +9,7 @@ import android.util.Log;
import com.stardust.util.Func1;
import java.io.Closeable;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
@@ -174,20 +175,28 @@ public class PFiles {
}
}
public static void write(InputStream is, OutputStream os) {
public static void write(InputStream is, OutputStream os, boolean close) {
byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
try {
while (is.available() > 0) {
int n = is.read(buffer);
os.write(buffer, 0, n);
if (n > 0) {
os.write(buffer, 0, n);
}
}
if (close) {
is.close();
os.close();
}
is.close();
os.close();
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
public static void write(InputStream is, OutputStream os) {
write(is, os, true);
}
public static void write(String path, String text) {
write(new File(path), text);
@@ -296,7 +305,7 @@ public class PFiles {
if (list == null)
throw new IOException("not a directory: " + assetsDir);
for (String file : list) {
if(TextUtils.isEmpty(file)){
if (TextUtils.isEmpty(file)) {
continue;
}
String fullAssetsPath = join(assetsDir, file);
@@ -500,4 +509,15 @@ public class PFiles {
throw new UncheckedIOException(e);
}
}
public static void closeSilently(Closeable closeable) {
if (closeable == null) {
return;
}
try {
closeable.close();
} catch (IOException ignored) {
}
}
}