This commit is contained in:
parent
51e9da7c9b
commit
ca8f6278b1
30 changed files with 88 additions and 79 deletions
|
|
@ -7,7 +7,7 @@ package zutil;
|
|||
* @author Ziver
|
||||
*
|
||||
*/
|
||||
public interface OneApp {
|
||||
public interface OneInstance {
|
||||
/**
|
||||
* Checks if the application is already running
|
||||
*
|
||||
|
|
@ -12,7 +12,7 @@ import java.nio.channels.OverlappingFileLockException;
|
|||
*
|
||||
* @author Ziver Koc
|
||||
*/
|
||||
public class OneAppFile implements OneApp{
|
||||
public class OneInstanceFile implements OneInstance{
|
||||
private File file;
|
||||
private FileChannel channel;
|
||||
private FileLock lock;
|
||||
|
|
@ -22,7 +22,7 @@ public class OneAppFile implements OneApp{
|
|||
*
|
||||
* @param filename The name of the file to be locked
|
||||
*/
|
||||
public OneAppFile(String filename){
|
||||
public OneInstanceFile(String filename){
|
||||
this.file = new File(System.getProperty("user.home"), filename);
|
||||
}
|
||||
|
||||
|
|
@ -4,13 +4,15 @@ import java.io.IOException;
|
|||
import java.net.ServerSocket;
|
||||
import java.net.Socket;
|
||||
|
||||
import zutil.io.MultiPrintStream;
|
||||
|
||||
/**
|
||||
* This class checks if the app is alredy running
|
||||
* by Locking a port
|
||||
*
|
||||
* @author Ziver Koc
|
||||
*/
|
||||
public class OneAppNetwork extends Thread implements OneApp{
|
||||
public class OneInstanceNetwork extends Thread implements OneInstance{
|
||||
private int port;
|
||||
|
||||
/**
|
||||
|
|
@ -18,7 +20,7 @@ public class OneAppNetwork extends Thread implements OneApp{
|
|||
*
|
||||
* @param port The port to lock
|
||||
*/
|
||||
public OneAppNetwork(int port){
|
||||
public OneInstanceNetwork(int port){
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
|
|
@ -3,7 +3,7 @@ package zutil.algo;
|
|||
import java.math.BigInteger;
|
||||
import java.util.LinkedList;
|
||||
|
||||
import zutil.MultiPrintStream;
|
||||
import zutil.io.MultiPrintStream;
|
||||
|
||||
/**
|
||||
* Euclidean algorithm is an algorithm to determine
|
||||
|
|
|
|||
|
|
@ -8,8 +8,8 @@ import java.util.Collection;
|
|||
import java.util.Iterator;
|
||||
import java.util.Queue;
|
||||
|
||||
import zutil.MultiPrintStream;
|
||||
import zutil.converters.Converter;
|
||||
import zutil.io.MultiPrintStream;
|
||||
|
||||
/**
|
||||
* This class creates a queue that stors the
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
package zutil;
|
||||
package zutil.io;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
|
|
@ -13,6 +13,8 @@ import java.util.Collection;
|
|||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import zutil.Dumpable;
|
||||
|
||||
/**
|
||||
* @author Ziver
|
||||
* this class can print strings to multiple PrintStreams
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package zutil;
|
||||
package zutil.io.file;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
|
|
@ -10,8 +10,7 @@ import java.io.File;
|
|||
public interface FileChangeListener{
|
||||
|
||||
/**
|
||||
* This method is called when there is a change in
|
||||
* a file
|
||||
* This method is called when there is a change in a file
|
||||
*
|
||||
* @param file The file that has changed
|
||||
*/
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package zutil;
|
||||
package zutil.io.file;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedReader;
|
||||
|
|
@ -14,6 +14,8 @@ import java.util.LinkedList;
|
|||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
|
||||
import zutil.io.MultiPrintStream;
|
||||
|
||||
/**
|
||||
* File path utilities
|
||||
*
|
||||
|
|
@ -24,9 +26,9 @@ public class FileUtil {
|
|||
/**
|
||||
* Returns a String with a relative path from the given path
|
||||
*
|
||||
* @param file is the file to get a relative path from
|
||||
* @param path is the path
|
||||
* @return A String with a relative path
|
||||
* @param file is the file to get a relative path from
|
||||
* @param path is the path
|
||||
* @return A String with a relative path
|
||||
*/
|
||||
public static String relativePath(File file, String path){
|
||||
String absolute = file.getAbsolutePath();
|
||||
|
|
@ -44,8 +46,8 @@ public class FileUtil {
|
|||
* Returns the File object for the given file.
|
||||
* Can not point to files in JAR files.
|
||||
*
|
||||
* @param path is the path to the file (no / if not absolute path)
|
||||
* @return A File object for the file
|
||||
* @param path is the path to the file (no / if not absolute path)
|
||||
* @return A File object for the file
|
||||
*/
|
||||
public static File find(String path){
|
||||
try {
|
||||
|
|
@ -63,8 +65,8 @@ public class FileUtil {
|
|||
/**
|
||||
* Returns the URL to the given file
|
||||
*
|
||||
* @param path is the path to the file (no / if not absolute path)
|
||||
* @return A URL object for the file
|
||||
* @param path is the path to the file (no / if not absolute path)
|
||||
* @return A URL object for the file
|
||||
* @throws URISyntaxException
|
||||
*/
|
||||
public static URL findURL(String path){
|
||||
|
|
@ -74,8 +76,8 @@ public class FileUtil {
|
|||
/**
|
||||
* Returns a InputStream from the path
|
||||
*
|
||||
* @param path is the path to the file (no / if not absolute path)
|
||||
* @return A InputStream object for the file
|
||||
* @param path is the path to the file (no / if not absolute path)
|
||||
* @return A InputStream object for the file
|
||||
*/
|
||||
public static InputStream getInputStream(String path){
|
||||
try {
|
||||
|
|
@ -95,8 +97,8 @@ public class FileUtil {
|
|||
* Reads and returns the content of a file as a String.
|
||||
* Or use FileUtils.readFileToString(file);
|
||||
*
|
||||
* @param file is the file to read
|
||||
* @return The file content
|
||||
* @param file is the file to read
|
||||
* @return The file content
|
||||
* @throws IOException
|
||||
*/
|
||||
public static String getFileContent(File file) throws IOException{
|
||||
|
|
@ -107,8 +109,8 @@ public class FileUtil {
|
|||
* Reads and returns the content of a file as a String.
|
||||
* Or use FileUtils.readFileToString(file);
|
||||
*
|
||||
* @param url is the url to read
|
||||
* @return The file content
|
||||
* @param url is the url to read
|
||||
* @return The file content
|
||||
* @throws IOException
|
||||
*/
|
||||
public static String getContent(URL url) throws IOException{
|
||||
|
|
@ -119,8 +121,8 @@ public class FileUtil {
|
|||
* Reads and returns the content of a file as a String.
|
||||
* Or use FileUtils.readFileToString(file);
|
||||
*
|
||||
* @param stream is the file stream to read
|
||||
* @return The file content
|
||||
* @param stream is the file stream to read
|
||||
* @return The file content
|
||||
* @throws IOException
|
||||
*/
|
||||
public static String getContent(InputStream stream) throws IOException{
|
||||
|
|
@ -172,9 +174,9 @@ public class FileUtil {
|
|||
}
|
||||
|
||||
/**
|
||||
* Same as search(File dir)
|
||||
* but is caches the result to be used next time this function is called
|
||||
* with the same parameters.
|
||||
* Same as search(File dir) but it caches the result
|
||||
* to be used next time this function is called with
|
||||
* the same parameters.
|
||||
*/
|
||||
public static List<File> cachedSearch(File dir){
|
||||
return cachedSearch(dir, new LinkedList<File>(), true);
|
||||
|
|
@ -182,8 +184,8 @@ public class FileUtil {
|
|||
|
||||
/**
|
||||
* Same as search(File dir, List<File> fileList, boolean recursive)
|
||||
* but is caches the result to be used next time this function is called
|
||||
* with the same parameters.
|
||||
* but is caches the result to be used next time this function is
|
||||
* called with the same parameters.
|
||||
*/
|
||||
public static List<File> cachedSearch(File dir, List<File> fileList, boolean recursive){
|
||||
return cachedSearch(dir, new LinkedList<File>(), false, (recursive ? Integer.MAX_VALUE : 0));
|
||||
|
|
@ -208,8 +210,8 @@ public class FileUtil {
|
|||
/**
|
||||
* Returns a List with all the files in a folder and sub folders
|
||||
*
|
||||
* @param dir is the directory to search in
|
||||
* @return The List with the files
|
||||
* @param dir is the directory to search in
|
||||
* @return The List with the files
|
||||
*/
|
||||
public static List<File> search(File dir){
|
||||
return search(dir, new LinkedList<File>(), true);
|
||||
|
|
@ -218,10 +220,10 @@ public class FileUtil {
|
|||
/**
|
||||
* Returns a ArrayList with all the files in a folder and sub folders
|
||||
*
|
||||
* @param dir is the directory to search in
|
||||
* @param fileList is the List to add the files to
|
||||
* @param recursive is if the method should search the sub directories to.
|
||||
* @return A List with the files
|
||||
* @param dir is the directory to search in
|
||||
* @param fileList is the List to add the files to
|
||||
* @param recursive is if the method should search the sub directories to.
|
||||
* @return A List with the files
|
||||
*/
|
||||
public static List<File> search(File dir, List<File> fileList, boolean recursive){
|
||||
return search(dir, new LinkedList<File>(), false, (recursive ? Integer.MAX_VALUE : 0));
|
||||
|
|
@ -230,11 +232,11 @@ public class FileUtil {
|
|||
/**
|
||||
* Returns a ArrayList with all the files in a folder and sub folders
|
||||
*
|
||||
* @param dir is the directory to search in
|
||||
* @param fileList is the List to add the files to
|
||||
* @param folders is if the method should add the folders to the List
|
||||
* @param recurse is how many times it should recurse into folders
|
||||
* @return A List with the files and/or folders
|
||||
* @param dir is the directory to search in
|
||||
* @param fileList is the List to add the files to
|
||||
* @param folders is if the method should add the folders to the List
|
||||
* @param recurse is how many times it should recurse into folders
|
||||
* @return A List with the files and/or folders
|
||||
*/
|
||||
public static List<File> search(File dir, List<File> fileList, boolean folders, int recurse){
|
||||
if(recurse<0)
|
||||
|
|
@ -266,8 +268,8 @@ public class FileUtil {
|
|||
/**
|
||||
* Returns the extension of the file
|
||||
*
|
||||
* @param file is the file
|
||||
* @return The extension
|
||||
* @param file is the file
|
||||
* @return The extension
|
||||
*/
|
||||
public static String fileExtension(File file){
|
||||
return fileExtension(file.getName());
|
||||
|
|
@ -276,8 +278,8 @@ public class FileUtil {
|
|||
/**
|
||||
* Returns the extension of the file
|
||||
*
|
||||
* @param file is the file
|
||||
* @return The extension
|
||||
* @param file is the file
|
||||
* @return The extension
|
||||
*/
|
||||
public static String fileExtension(String file){
|
||||
if(file.lastIndexOf(".")==-1)
|
||||
|
|
@ -1,13 +1,16 @@
|
|||
package zutil;
|
||||
package zutil.io.file;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
import zutil.io.MultiPrintStream;
|
||||
|
||||
/**
|
||||
* This class calls a given listener
|
||||
* when a file is changed
|
||||
*
|
||||
* @author Ziver
|
||||
*
|
||||
*/
|
||||
|
|
@ -20,7 +23,7 @@ public class FileWatcher extends TimerTask{
|
|||
* Creates a watcher for the given file whit the check
|
||||
* interval of 1 second
|
||||
*
|
||||
* @param file The file to check
|
||||
* @param file is the file to check
|
||||
* @throws FileNotFoundException
|
||||
*/
|
||||
public FileWatcher(File file) throws FileNotFoundException{
|
||||
|
|
@ -31,12 +34,13 @@ public class FileWatcher extends TimerTask{
|
|||
* Creates a watcher for the given file whit the given
|
||||
* check interval
|
||||
*
|
||||
* @param file The file
|
||||
* @param intervall The interval
|
||||
* @param file is the file
|
||||
* @param intervall is the interval
|
||||
* @throws FileNotFoundException
|
||||
*/
|
||||
public FileWatcher(File file, int intervall) throws FileNotFoundException{
|
||||
if(file==null || !file.exists()) throw new FileNotFoundException("File not found: "+file);
|
||||
if(file==null || !file.exists())
|
||||
throw new FileNotFoundException("File not found: "+file);
|
||||
this.file = file;
|
||||
lastChanged = file.lastModified();
|
||||
|
||||
|
|
@ -27,8 +27,8 @@ import org.apache.commons.fileupload.disk.DiskFileItemFactory;
|
|||
import org.apache.commons.fileupload.servlet.ServletFileUpload;
|
||||
import org.apache.commons.fileupload.util.Streams;
|
||||
|
||||
import zutil.FileUtil;
|
||||
import zutil.StringUtil;
|
||||
import zutil.io.file.FileUtil;
|
||||
import zutil.jee.upload.FileUploadListener.Status;
|
||||
import zutil.log.LogUtil;
|
||||
import zutil.parser.json.JSONNode;
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ import java.util.regex.Pattern;
|
|||
|
||||
import javax.security.auth.login.AccountException;
|
||||
|
||||
import zutil.MultiPrintStream;
|
||||
import zutil.io.MultiPrintStream;
|
||||
|
||||
/**
|
||||
* A simple FTP client class
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import java.net.DatagramSocket;
|
|||
import java.net.InetAddress;
|
||||
import java.net.MulticastSocket;
|
||||
|
||||
import zutil.MultiPrintStream;
|
||||
import zutil.io.MultiPrintStream;
|
||||
|
||||
/**
|
||||
* This class broadcast its address in the LAN so that
|
||||
|
|
|
|||
|
|
@ -8,9 +8,9 @@ import java.io.ObjectOutputStream;
|
|||
import java.net.Socket;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import zutil.FileUtil;
|
||||
import zutil.MultiPrintStream;
|
||||
import zutil.ProgressListener;
|
||||
import zutil.io.MultiPrintStream;
|
||||
import zutil.io.file.FileUtil;
|
||||
|
||||
/**
|
||||
* This class connects to a update server and updates a path
|
||||
|
|
|
|||
|
|
@ -13,9 +13,9 @@ import java.security.NoSuchAlgorithmException;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import zutil.FileUtil;
|
||||
import zutil.Hasher;
|
||||
import zutil.MultiPrintStream;
|
||||
import zutil.io.MultiPrintStream;
|
||||
import zutil.io.file.FileUtil;
|
||||
|
||||
public class UpdateServer extends Thread{
|
||||
private ArrayList<FileHash> fileList;
|
||||
|
|
|
|||
|
|
@ -17,9 +17,9 @@ import java.util.Map;
|
|||
import java.util.logging.Logger;
|
||||
|
||||
import zutil.Encrypter;
|
||||
import zutil.MultiPrintStream;
|
||||
import zutil.converters.Converter;
|
||||
import zutil.io.DynamicByteArrayStream;
|
||||
import zutil.io.MultiPrintStream;
|
||||
import zutil.log.LogUtil;
|
||||
import zutil.network.nio.message.type.ResponseRequestMessage;
|
||||
import zutil.network.nio.message.type.SystemMessage;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package zutil.network.nio.response;
|
||||
|
||||
import zutil.MultiPrintStream;
|
||||
import zutil.io.MultiPrintStream;
|
||||
|
||||
public class PrintRsp extends ResponseEvent{
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ package zutil.network.nio.worker;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
import zutil.MultiPrintStream;
|
||||
import zutil.io.MultiPrintStream;
|
||||
|
||||
public class EchoWorker extends ThreadedEventWorker {
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import java.io.IOException;
|
|||
import java.util.LinkedList;
|
||||
import java.util.Queue;
|
||||
|
||||
import zutil.MultiPrintStream;
|
||||
import zutil.io.MultiPrintStream;
|
||||
import zutil.network.nio.NioClient;
|
||||
import zutil.network.nio.message.GridMessage;
|
||||
import zutil.network.nio.worker.ThreadedEventWorker;
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import java.util.TimerTask;
|
|||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import zutil.MultiPrintStream;
|
||||
import zutil.io.MultiPrintStream;
|
||||
import zutil.io.StringOutputStream;
|
||||
import zutil.log.LogUtil;
|
||||
import zutil.network.http.HTTPHeaderParser;
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ import java.security.cert.CertificateException;
|
|||
|
||||
import javax.net.ssl.SSLServerSocketFactory;
|
||||
|
||||
import zutil.MultiPrintStream;
|
||||
import zutil.io.MultiPrintStream;
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import java.io.IOException;
|
|||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import zutil.FileUtil;
|
||||
import zutil.io.file.FileUtil;
|
||||
|
||||
public class Torrent {
|
||||
// Name of the torrent
|
||||
|
|
|
|||
|
|
@ -5,8 +5,8 @@ import java.io.IOException;
|
|||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
|
||||
import zutil.FileUtil;
|
||||
import zutil.MultiPrintStream;
|
||||
import zutil.io.MultiPrintStream;
|
||||
import zutil.io.file.FileUtil;
|
||||
|
||||
/**
|
||||
* http://wiki.theory.org/BitTorrentSpecification
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import java.util.Map;
|
|||
|
||||
import org.dom4j.DocumentException;
|
||||
|
||||
import zutil.FileUtil;
|
||||
import zutil.io.file.FileUtil;
|
||||
import zutil.network.http.HttpPage;
|
||||
import zutil.network.http.HttpPrintStream;
|
||||
import zutil.network.upnp.UPnPService;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package zutil.parser.json;
|
||||
|
||||
import zutil.MultiPrintStream;
|
||||
import zutil.io.MultiPrintStream;
|
||||
import zutil.parser.json.JSONNode.JSONType;
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -4,9 +4,9 @@ import java.io.File;
|
|||
import java.io.FileNotFoundException;
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
import zutil.FileChangeListener;
|
||||
import zutil.FileUtil;
|
||||
import zutil.FileWatcher;
|
||||
import zutil.io.file.FileChangeListener;
|
||||
import zutil.io.file.FileUtil;
|
||||
import zutil.io.file.FileWatcher;
|
||||
|
||||
public class FileChangedTest implements FileChangeListener{
|
||||
public static void main(String[] args) throws URISyntaxException, FileNotFoundException{
|
||||
|
|
|
|||
|
|
@ -4,8 +4,8 @@ import java.io.File;
|
|||
import java.net.URISyntaxException;
|
||||
import java.util.List;
|
||||
|
||||
import zutil.FileUtil;
|
||||
import zutil.Hasher;
|
||||
import zutil.io.file.FileUtil;
|
||||
|
||||
public class FileFinderHasherTest {
|
||||
public static void main(String[] args) throws URISyntaxException{
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import java.io.IOException;
|
|||
|
||||
import javax.wsdl.WSDLException;
|
||||
|
||||
import zutil.MultiPrintStream;
|
||||
import zutil.io.MultiPrintStream;
|
||||
import zutil.network.http.HttpServer;
|
||||
import zutil.network.http.soap.SOAPHttpPage;
|
||||
import zutil.network.ssdp.SSDPServer;
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ import javax.swing.text.Document;
|
|||
import javax.swing.text.Style;
|
||||
import javax.swing.text.StyleConstants;
|
||||
|
||||
import zutil.FileUtil;
|
||||
import zutil.io.file.FileUtil;
|
||||
|
||||
/**
|
||||
* Creates a Swing console window Thats takes System.in and
|
||||
|
|
|
|||
|
|
@ -7,8 +7,8 @@ import java.io.IOException;
|
|||
import javax.imageio.ImageIO;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
import zutil.FileUtil;
|
||||
import zutil.image.ImageUtil;
|
||||
import zutil.io.file.FileUtil;
|
||||
|
||||
/**
|
||||
* This class is a panel with a background image
|
||||
|
|
|
|||
|
|
@ -20,8 +20,8 @@ import javax.swing.WindowConstants;
|
|||
import javax.swing.GroupLayout.Alignment;
|
||||
import javax.swing.LayoutStyle.ComponentPlacement;
|
||||
|
||||
import zutil.FileUtil;
|
||||
import zutil.MultiPrintStream;
|
||||
import zutil.io.MultiPrintStream;
|
||||
import zutil.io.file.FileUtil;
|
||||
import zutil.struct.HistoryList;
|
||||
import zutil.ui.JImagePanel;
|
||||
import zutil.ui.wizard.listener.BlockingWizardListener;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue