mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-19 22:29:53 +01:00
Javadocs and unit tests. Woo!
This commit is contained in:
@@ -67,7 +67,8 @@ public class FileUtils {
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies the source file or directory to the destination directory.
|
||||
* Copies the source file or directory to the destination directory. If the
|
||||
* callback is not null it's called once for each file created.
|
||||
*/
|
||||
public static void copyRecursively(File src, File dest, Callback callback)
|
||||
throws IOException {
|
||||
|
||||
@@ -2,11 +2,19 @@ package net.sf.briar.util;
|
||||
|
||||
public class StringUtils {
|
||||
|
||||
/**
|
||||
* Trims the given string to the given length, returning the head and
|
||||
* appending "..." if the string was trimmed.
|
||||
*/
|
||||
public static String head(String s, int length) {
|
||||
if(s.length() > length) return s.substring(0, length) + "...";
|
||||
else return s;
|
||||
}
|
||||
|
||||
/**
|
||||
* Trims the given string to the given length, returning the tail and
|
||||
* prepending "..." if the string was trimmed.
|
||||
*/
|
||||
public static String tail(String s, int length) {
|
||||
if(s.length() > length) return "..." + s.substring(s.length() - length);
|
||||
else return s;
|
||||
|
||||
@@ -11,9 +11,13 @@ import java.util.zip.ZipOutputStream;
|
||||
|
||||
public class ZipUtils {
|
||||
|
||||
/**
|
||||
* Copies the given file to the given zip, using the given path for the
|
||||
* zip entry.
|
||||
*/
|
||||
public static void copyToZip(String path, File file, ZipOutputStream zip)
|
||||
throws IOException {
|
||||
assert file.isFile() : file.getAbsolutePath();
|
||||
assert file.isFile();
|
||||
zip.putNextEntry(new ZipEntry(path));
|
||||
FileInputStream in = new FileInputStream(file);
|
||||
byte[] buf = new byte[1024];
|
||||
@@ -23,6 +27,12 @@ public class ZipUtils {
|
||||
zip.closeEntry();
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies the given directory to the given zip recursively, using the
|
||||
* given path in place of the directory's name as the parent of all the zip
|
||||
* entries. If the callback is not null it's called once for each file
|
||||
* added.
|
||||
*/
|
||||
public static void copyToZipRecursively(String path, File dir,
|
||||
ZipOutputStream zip, Callback callback) throws IOException {
|
||||
assert dir.isDirectory();
|
||||
@@ -42,6 +52,11 @@ public class ZipUtils {
|
||||
else return path + "/" + name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unzips the given stream to the given directory, skipping any zip entries
|
||||
* that don't match the given regex. If the callback is not null it's
|
||||
* called once for each file extracted.
|
||||
*/
|
||||
public static void unzipStream(InputStream in, File dir, String regex,
|
||||
Callback callback) throws IOException {
|
||||
String path = dir.getCanonicalPath();
|
||||
|
||||
Reference in New Issue
Block a user