some reorganization

master
Ondřej Hruška 11 years ago
parent 065392f934
commit 982a4c8e89
  1. 10
      src/mightypork/utils/config/SimpleConfig.java
  2. 14
      src/mightypork/utils/files/FileUtil.java
  3. 12
      src/mightypork/utils/files/zip/ZipBuilder.java
  4. 6
      src/mightypork/utils/files/zip/ZipUtils.java
  5. 8
      src/mightypork/utils/logging/writers/ArchivingLog.java

@ -9,7 +9,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import mightypork.utils.files.FileUtils; import mightypork.utils.files.FileUtil;
import mightypork.utils.logging.Log; import mightypork.utils.logging.Log;
@ -33,7 +33,7 @@ public class SimpleConfig {
*/ */
public static List<String> listFromFile(File file) throws IOException public static List<String> listFromFile(File file) throws IOException
{ {
final String fileText = FileUtils.fileToString(file); final String fileText = FileUtil.fileToString(file);
return listFromString(fileText); return listFromString(fileText);
} }
@ -48,7 +48,7 @@ public class SimpleConfig {
*/ */
public static Map<String, String> mapFromFile(File file) throws IOException public static Map<String, String> mapFromFile(File file) throws IOException
{ {
final String fileText = FileUtils.fileToString(file); final String fileText = FileUtil.fileToString(file);
return mapFromString(fileText); return mapFromString(fileText);
} }
@ -173,7 +173,7 @@ public class SimpleConfig {
text += s; text += s;
} }
FileUtils.stringToFile(target, text); FileUtil.stringToFile(target, text);
} }
@ -199,7 +199,7 @@ public class SimpleConfig {
text += s; text += s;
} }
FileUtils.stringToFile(target, text); FileUtil.stringToFile(target, text);
} }
} }

@ -10,7 +10,7 @@ import mightypork.utils.string.StringUtil;
import mightypork.utils.string.validation.StringFilter; import mightypork.utils.string.validation.StringFilter;
public class FileUtils { public class FileUtil {
/** /**
* Copy directory recursively. * Copy directory recursively.
@ -175,7 +175,7 @@ public class FileUtils {
*/ */
public static List<File> listDirectory(File dir) public static List<File> listDirectory(File dir)
{ {
return FileUtils.listDirectory(dir, null); return FileUtil.listDirectory(dir, null);
} }
@ -322,7 +322,7 @@ public class FileUtils {
public static InputStream getResource(String path) public static InputStream getResource(String path)
{ {
final InputStream in = FileUtils.class.getResourceAsStream(path); final InputStream in = FileUtil.class.getResourceAsStream(path);
if (in != null) return in; if (in != null) return in;
@ -339,7 +339,7 @@ public class FileUtils {
public static String getResourceAsString(String path) public static String getResourceAsString(String path)
{ {
return streamToString(FileUtils.class.getResourceAsStream(path)); return streamToString(FileUtil.class.getResourceAsStream(path));
} }
@ -400,9 +400,9 @@ public class FileUtils {
*/ */
public static void resourceToFile(String resname, File file) throws IOException public static void resourceToFile(String resname, File file) throws IOException
{ {
try (InputStream in = FileUtils.getResource(resname); OutputStream out = new FileOutputStream(file)) { try (InputStream in = FileUtil.getResource(resname); OutputStream out = new FileOutputStream(file)) {
FileUtils.copyStream(in, out); FileUtil.copyStream(in, out);
} }
} }
@ -417,7 +417,7 @@ public class FileUtils {
*/ */
public static String resourceToString(String resname) throws IOException public static String resourceToString(String resname) throws IOException
{ {
try (InputStream in = FileUtils.getResource(resname)) { try (InputStream in = FileUtil.getResource(resname)) {
return streamToString(in); return streamToString(in);
} }
} }

@ -10,7 +10,7 @@ import java.util.HashSet;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream; import java.util.zip.ZipOutputStream;
import mightypork.utils.files.FileUtils; import mightypork.utils.files.FileUtil;
import mightypork.utils.logging.Log; import mightypork.utils.logging.Log;
@ -56,7 +56,7 @@ public class ZipBuilder {
out.putNextEntry(new ZipEntry(path)); out.putNextEntry(new ZipEntry(path));
FileUtils.copyStream(in, out); FileUtil.copyStream(in, out);
} }
@ -75,8 +75,8 @@ public class ZipBuilder {
out.putNextEntry(new ZipEntry(path)); out.putNextEntry(new ZipEntry(path));
try (InputStream in = FileUtils.stringToStream(text)) { try (InputStream in = FileUtil.stringToStream(text)) {
FileUtils.copyStream(in, out); FileUtil.copyStream(in, out);
} }
} }
@ -96,8 +96,8 @@ public class ZipBuilder {
out.putNextEntry(new ZipEntry(path)); out.putNextEntry(new ZipEntry(path));
try (InputStream in = FileUtils.getResource(resPath)) { try (InputStream in = FileUtil.getResource(resPath)) {
FileUtils.copyStream(in, out); FileUtil.copyStream(in, out);
} }
} }

@ -8,7 +8,7 @@ import java.util.List;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipFile; import java.util.zip.ZipFile;
import mightypork.utils.files.FileUtils; import mightypork.utils.files.FileUtil;
import mightypork.utils.logging.Log; import mightypork.utils.logging.Log;
import mightypork.utils.string.validation.StringFilter; import mightypork.utils.string.validation.StringFilter;
@ -136,7 +136,7 @@ public class ZipUtils {
try (InputStream in = zip.getInputStream(entry); BufferedInputStream is = new BufferedInputStream(in); FileOutputStream fos = new FileOutputStream(destFile); BufferedOutputStream dest = new BufferedOutputStream(fos, BUFFER_SIZE)) { try (InputStream in = zip.getInputStream(entry); BufferedInputStream is = new BufferedInputStream(in); FileOutputStream fos = new FileOutputStream(destFile); BufferedOutputStream dest = new BufferedOutputStream(fos, BUFFER_SIZE)) {
FileUtils.copyStream(is, dest); FileUtil.copyStream(is, dest);
} }
} }
@ -154,7 +154,7 @@ public class ZipUtils {
BufferedInputStream is = null; BufferedInputStream is = null;
try { try {
is = new BufferedInputStream(zip.getInputStream(entry)); is = new BufferedInputStream(zip.getInputStream(entry));
final String s = FileUtils.streamToString(is); final String s = FileUtil.streamToString(is);
return s; return s;
} finally { } finally {
try { try {

@ -9,7 +9,7 @@ import java.util.Comparator;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import mightypork.utils.files.FileUtils; import mightypork.utils.files.FileUtil;
import mightypork.utils.string.StringUtil; import mightypork.utils.string.StringUtil;
@ -65,10 +65,10 @@ public class ArchivingLog extends SimpleLog {
final File log_file = getFile(); final File log_file = getFile();
final File log_dir = log_file.getParentFile(); final File log_dir = log_file.getParentFile();
final String fname = FileUtils.getBasename(log_file.toString()); final String fname = FileUtil.getBasename(log_file.toString());
// move old file // move old file
for (final File f : FileUtils.listDirectory(log_dir)) { for (final File f : FileUtil.listDirectory(log_dir)) {
if (!f.isFile()) continue; if (!f.isFile()) continue;
if (f.equals(getFile())) { if (f.equals(getFile())) {
@ -86,7 +86,7 @@ public class ArchivingLog extends SimpleLog {
if (logs_to_keep == -1) return; // keep all if (logs_to_keep == -1) return; // keep all
final List<File> oldLogs = FileUtils.listDirectory(log_dir, new FileFilter() { final List<File> oldLogs = FileUtil.listDirectory(log_dir, new FileFilter() {
@Override @Override
public boolean accept(File f) public boolean accept(File f)

Loading…
Cancel
Save