This commit is contained in:
Ziver Koc 2010-10-27 18:02:44 +00:00
parent 51e9da7c9b
commit ca8f6278b1
30 changed files with 88 additions and 79 deletions

View file

@ -7,7 +7,7 @@ package zutil;
* @author Ziver * @author Ziver
* *
*/ */
public interface OneApp { public interface OneInstance {
/** /**
* Checks if the application is already running * Checks if the application is already running
* *

View file

@ -12,7 +12,7 @@ import java.nio.channels.OverlappingFileLockException;
* *
* @author Ziver Koc * @author Ziver Koc
*/ */
public class OneAppFile implements OneApp{ public class OneInstanceFile implements OneInstance{
private File file; private File file;
private FileChannel channel; private FileChannel channel;
private FileLock lock; private FileLock lock;
@ -22,7 +22,7 @@ public class OneAppFile implements OneApp{
* *
* @param filename The name of the file to be locked * @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); this.file = new File(System.getProperty("user.home"), filename);
} }

View file

@ -4,13 +4,15 @@ import java.io.IOException;
import java.net.ServerSocket; import java.net.ServerSocket;
import java.net.Socket; import java.net.Socket;
import zutil.io.MultiPrintStream;
/** /**
* This class checks if the app is alredy running * This class checks if the app is alredy running
* by Locking a port * by Locking a port
* *
* @author Ziver Koc * @author Ziver Koc
*/ */
public class OneAppNetwork extends Thread implements OneApp{ public class OneInstanceNetwork extends Thread implements OneInstance{
private int port; private int port;
/** /**
@ -18,7 +20,7 @@ public class OneAppNetwork extends Thread implements OneApp{
* *
* @param port The port to lock * @param port The port to lock
*/ */
public OneAppNetwork(int port){ public OneInstanceNetwork(int port){
this.port = port; this.port = port;
} }

View file

@ -3,7 +3,7 @@ package zutil.algo;
import java.math.BigInteger; import java.math.BigInteger;
import java.util.LinkedList; import java.util.LinkedList;
import zutil.MultiPrintStream; import zutil.io.MultiPrintStream;
/** /**
* Euclidean algorithm is an algorithm to determine * Euclidean algorithm is an algorithm to determine

View file

@ -8,8 +8,8 @@ import java.util.Collection;
import java.util.Iterator; import java.util.Iterator;
import java.util.Queue; import java.util.Queue;
import zutil.MultiPrintStream;
import zutil.converters.Converter; import zutil.converters.Converter;
import zutil.io.MultiPrintStream;
/** /**
* This class creates a queue that stors the * This class creates a queue that stors the

View file

@ -1,4 +1,4 @@
package zutil; package zutil.io;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
@ -13,6 +13,8 @@ import java.util.Collection;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map; import java.util.Map;
import zutil.Dumpable;
/** /**
* @author Ziver * @author Ziver
* this class can print strings to multiple PrintStreams * this class can print strings to multiple PrintStreams

View file

@ -1,4 +1,4 @@
package zutil; package zutil.io.file;
import java.io.File; import java.io.File;
@ -10,8 +10,7 @@ import java.io.File;
public interface FileChangeListener{ public interface FileChangeListener{
/** /**
* This method is called when there is a change in * This method is called when there is a change in a file
* a file
* *
* @param file The file that has changed * @param file The file that has changed
*/ */

View file

@ -1,4 +1,4 @@
package zutil; package zutil.io.file;
import java.io.BufferedInputStream; import java.io.BufferedInputStream;
import java.io.BufferedReader; import java.io.BufferedReader;
@ -14,6 +14,8 @@ import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import zutil.io.MultiPrintStream;
/** /**
* File path utilities * File path utilities
* *
@ -24,9 +26,9 @@ public class FileUtil {
/** /**
* Returns a String with a relative path from the given path * Returns a String with a relative path from the given path
* *
* @param file is the file to get a relative path from * @param file is the file to get a relative path from
* @param path is the path * @param path is the path
* @return A String with a relative path * @return A String with a relative path
*/ */
public static String relativePath(File file, String path){ public static String relativePath(File file, String path){
String absolute = file.getAbsolutePath(); String absolute = file.getAbsolutePath();
@ -44,8 +46,8 @@ public class FileUtil {
* Returns the File object for the given file. * Returns the File object for the given file.
* Can not point to files in JAR files. * Can not point to files in JAR files.
* *
* @param path is the path to the file (no / if not absolute path) * @param path is the path to the file (no / if not absolute path)
* @return A File object for the file * @return A File object for the file
*/ */
public static File find(String path){ public static File find(String path){
try { try {
@ -63,8 +65,8 @@ public class FileUtil {
/** /**
* Returns the URL to the given file * Returns the URL to the given file
* *
* @param path is the path to the file (no / if not absolute path) * @param path is the path to the file (no / if not absolute path)
* @return A URL object for the file * @return A URL object for the file
* @throws URISyntaxException * @throws URISyntaxException
*/ */
public static URL findURL(String path){ public static URL findURL(String path){
@ -74,8 +76,8 @@ public class FileUtil {
/** /**
* Returns a InputStream from the path * Returns a InputStream from the path
* *
* @param path is the path to the file (no / if not absolute path) * @param path is the path to the file (no / if not absolute path)
* @return A InputStream object for the file * @return A InputStream object for the file
*/ */
public static InputStream getInputStream(String path){ public static InputStream getInputStream(String path){
try { try {
@ -95,8 +97,8 @@ public class FileUtil {
* Reads and returns the content of a file as a String. * Reads and returns the content of a file as a String.
* Or use FileUtils.readFileToString(file); * Or use FileUtils.readFileToString(file);
* *
* @param file is the file to read * @param file is the file to read
* @return The file content * @return The file content
* @throws IOException * @throws IOException
*/ */
public static String getFileContent(File file) 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. * Reads and returns the content of a file as a String.
* Or use FileUtils.readFileToString(file); * Or use FileUtils.readFileToString(file);
* *
* @param url is the url to read * @param url is the url to read
* @return The file content * @return The file content
* @throws IOException * @throws IOException
*/ */
public static String getContent(URL url) 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. * Reads and returns the content of a file as a String.
* Or use FileUtils.readFileToString(file); * Or use FileUtils.readFileToString(file);
* *
* @param stream is the file stream to read * @param stream is the file stream to read
* @return The file content * @return The file content
* @throws IOException * @throws IOException
*/ */
public static String getContent(InputStream stream) throws IOException{ public static String getContent(InputStream stream) throws IOException{
@ -172,9 +174,9 @@ public class FileUtil {
} }
/** /**
* Same as search(File dir) * Same as search(File dir) but it caches the result
* but is caches the result to be used next time this function is called * to be used next time this function is called with
* with the same parameters. * the same parameters.
*/ */
public static List<File> cachedSearch(File dir){ public static List<File> cachedSearch(File dir){
return cachedSearch(dir, new LinkedList<File>(), true); return cachedSearch(dir, new LinkedList<File>(), true);
@ -182,8 +184,8 @@ public class FileUtil {
/** /**
* Same as search(File dir, List<File> fileList, boolean recursive) * Same as search(File dir, List<File> fileList, boolean recursive)
* but is caches the result to be used next time this function is called * but is caches the result to be used next time this function is
* with the same parameters. * called with the same parameters.
*/ */
public static List<File> cachedSearch(File dir, List<File> fileList, boolean recursive){ public static List<File> cachedSearch(File dir, List<File> fileList, boolean recursive){
return cachedSearch(dir, new LinkedList<File>(), false, (recursive ? Integer.MAX_VALUE : 0)); 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 * Returns a List with all the files in a folder and sub folders
* *
* @param dir is the directory to search in * @param dir is the directory to search in
* @return The List with the files * @return The List with the files
*/ */
public static List<File> search(File dir){ public static List<File> search(File dir){
return search(dir, new LinkedList<File>(), true); 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 * Returns a ArrayList with all the files in a folder and sub folders
* *
* @param dir is the directory to search in * @param dir is the directory to search in
* @param fileList is the List to add the files to * @param fileList is the List to add the files to
* @param recursive is if the method should search the sub directories to. * @param recursive is if the method should search the sub directories to.
* @return A List with the files * @return A List with the files
*/ */
public static List<File> search(File dir, List<File> fileList, boolean recursive){ public static List<File> search(File dir, List<File> fileList, boolean recursive){
return search(dir, new LinkedList<File>(), false, (recursive ? Integer.MAX_VALUE : 0)); 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 * Returns a ArrayList with all the files in a folder and sub folders
* *
* @param dir is the directory to search in * @param dir is the directory to search in
* @param fileList is the List to add the files to * @param fileList is the List to add the files to
* @param folders is if the method should add the folders to the List * @param folders is if the method should add the folders to the List
* @param recurse is how many times it should recurse into folders * @param recurse is how many times it should recurse into folders
* @return A List with the files and/or folders * @return A List with the files and/or folders
*/ */
public static List<File> search(File dir, List<File> fileList, boolean folders, int recurse){ public static List<File> search(File dir, List<File> fileList, boolean folders, int recurse){
if(recurse<0) if(recurse<0)
@ -266,8 +268,8 @@ public class FileUtil {
/** /**
* Returns the extension of the file * Returns the extension of the file
* *
* @param file is the file * @param file is the file
* @return The extension * @return The extension
*/ */
public static String fileExtension(File file){ public static String fileExtension(File file){
return fileExtension(file.getName()); return fileExtension(file.getName());
@ -276,8 +278,8 @@ public class FileUtil {
/** /**
* Returns the extension of the file * Returns the extension of the file
* *
* @param file is the file * @param file is the file
* @return The extension * @return The extension
*/ */
public static String fileExtension(String file){ public static String fileExtension(String file){
if(file.lastIndexOf(".")==-1) if(file.lastIndexOf(".")==-1)

View file

@ -1,13 +1,16 @@
package zutil; package zutil.io.file;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.util.Timer; import java.util.Timer;
import java.util.TimerTask; import java.util.TimerTask;
import zutil.io.MultiPrintStream;
/** /**
* This class calls a given listener * This class calls a given listener
* when a file is changed * when a file is changed
*
* @author Ziver * @author Ziver
* *
*/ */
@ -20,7 +23,7 @@ public class FileWatcher extends TimerTask{
* Creates a watcher for the given file whit the check * Creates a watcher for the given file whit the check
* interval of 1 second * interval of 1 second
* *
* @param file The file to check * @param file is the file to check
* @throws FileNotFoundException * @throws FileNotFoundException
*/ */
public FileWatcher(File file) 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 * Creates a watcher for the given file whit the given
* check interval * check interval
* *
* @param file The file * @param file is the file
* @param intervall The interval * @param intervall is the interval
* @throws FileNotFoundException * @throws FileNotFoundException
*/ */
public FileWatcher(File file, int intervall) 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; this.file = file;
lastChanged = file.lastModified(); lastChanged = file.lastModified();

View file

@ -27,8 +27,8 @@ import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload; import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.apache.commons.fileupload.util.Streams; import org.apache.commons.fileupload.util.Streams;
import zutil.FileUtil;
import zutil.StringUtil; import zutil.StringUtil;
import zutil.io.file.FileUtil;
import zutil.jee.upload.FileUploadListener.Status; import zutil.jee.upload.FileUploadListener.Status;
import zutil.log.LogUtil; import zutil.log.LogUtil;
import zutil.parser.json.JSONNode; import zutil.parser.json.JSONNode;

View file

@ -13,7 +13,7 @@ import java.util.regex.Pattern;
import javax.security.auth.login.AccountException; import javax.security.auth.login.AccountException;
import zutil.MultiPrintStream; import zutil.io.MultiPrintStream;
/** /**
* A simple FTP client class * A simple FTP client class

View file

@ -6,7 +6,7 @@ import java.net.DatagramSocket;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.MulticastSocket; import java.net.MulticastSocket;
import zutil.MultiPrintStream; import zutil.io.MultiPrintStream;
/** /**
* This class broadcast its address in the LAN so that * This class broadcast its address in the LAN so that

View file

@ -8,9 +8,9 @@ import java.io.ObjectOutputStream;
import java.net.Socket; import java.net.Socket;
import java.util.ArrayList; import java.util.ArrayList;
import zutil.FileUtil;
import zutil.MultiPrintStream;
import zutil.ProgressListener; import zutil.ProgressListener;
import zutil.io.MultiPrintStream;
import zutil.io.file.FileUtil;
/** /**
* This class connects to a update server and updates a path * This class connects to a update server and updates a path

View file

@ -13,9 +13,9 @@ import java.security.NoSuchAlgorithmException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import zutil.FileUtil;
import zutil.Hasher; import zutil.Hasher;
import zutil.MultiPrintStream; import zutil.io.MultiPrintStream;
import zutil.io.file.FileUtil;
public class UpdateServer extends Thread{ public class UpdateServer extends Thread{
private ArrayList<FileHash> fileList; private ArrayList<FileHash> fileList;

View file

@ -17,9 +17,9 @@ import java.util.Map;
import java.util.logging.Logger; import java.util.logging.Logger;
import zutil.Encrypter; import zutil.Encrypter;
import zutil.MultiPrintStream;
import zutil.converters.Converter; import zutil.converters.Converter;
import zutil.io.DynamicByteArrayStream; import zutil.io.DynamicByteArrayStream;
import zutil.io.MultiPrintStream;
import zutil.log.LogUtil; import zutil.log.LogUtil;
import zutil.network.nio.message.type.ResponseRequestMessage; import zutil.network.nio.message.type.ResponseRequestMessage;
import zutil.network.nio.message.type.SystemMessage; import zutil.network.nio.message.type.SystemMessage;

View file

@ -1,6 +1,6 @@
package zutil.network.nio.response; package zutil.network.nio.response;
import zutil.MultiPrintStream; import zutil.io.MultiPrintStream;
public class PrintRsp extends ResponseEvent{ public class PrintRsp extends ResponseEvent{

View file

@ -2,7 +2,7 @@ package zutil.network.nio.worker;
import java.io.IOException; import java.io.IOException;
import zutil.MultiPrintStream; import zutil.io.MultiPrintStream;
public class EchoWorker extends ThreadedEventWorker { public class EchoWorker extends ThreadedEventWorker {

View file

@ -4,7 +4,7 @@ import java.io.IOException;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.Queue; import java.util.Queue;
import zutil.MultiPrintStream; import zutil.io.MultiPrintStream;
import zutil.network.nio.NioClient; import zutil.network.nio.NioClient;
import zutil.network.nio.message.GridMessage; import zutil.network.nio.message.GridMessage;
import zutil.network.nio.worker.ThreadedEventWorker; import zutil.network.nio.worker.ThreadedEventWorker;

View file

@ -9,7 +9,7 @@ import java.util.TimerTask;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import zutil.MultiPrintStream; import zutil.io.MultiPrintStream;
import zutil.io.StringOutputStream; import zutil.io.StringOutputStream;
import zutil.log.LogUtil; import zutil.log.LogUtil;
import zutil.network.http.HTTPHeaderParser; import zutil.network.http.HTTPHeaderParser;

View file

@ -11,7 +11,7 @@ import java.security.cert.CertificateException;
import javax.net.ssl.SSLServerSocketFactory; import javax.net.ssl.SSLServerSocketFactory;
import zutil.MultiPrintStream; import zutil.io.MultiPrintStream;
/** /**

View file

@ -5,7 +5,7 @@ import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import zutil.FileUtil; import zutil.io.file.FileUtil;
public class Torrent { public class Torrent {
// Name of the torrent // Name of the torrent

View file

@ -5,8 +5,8 @@ import java.io.IOException;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedList; import java.util.LinkedList;
import zutil.FileUtil; import zutil.io.MultiPrintStream;
import zutil.MultiPrintStream; import zutil.io.file.FileUtil;
/** /**
* http://wiki.theory.org/BitTorrentSpecification * http://wiki.theory.org/BitTorrentSpecification

View file

@ -7,7 +7,7 @@ import java.util.Map;
import org.dom4j.DocumentException; import org.dom4j.DocumentException;
import zutil.FileUtil; import zutil.io.file.FileUtil;
import zutil.network.http.HttpPage; import zutil.network.http.HttpPage;
import zutil.network.http.HttpPrintStream; import zutil.network.http.HttpPrintStream;
import zutil.network.upnp.UPnPService; import zutil.network.upnp.UPnPService;

View file

@ -1,6 +1,6 @@
package zutil.parser.json; package zutil.parser.json;
import zutil.MultiPrintStream; import zutil.io.MultiPrintStream;
import zutil.parser.json.JSONNode.JSONType; import zutil.parser.json.JSONNode.JSONType;
/** /**

View file

@ -4,9 +4,9 @@ import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import zutil.FileChangeListener; import zutil.io.file.FileChangeListener;
import zutil.FileUtil; import zutil.io.file.FileUtil;
import zutil.FileWatcher; import zutil.io.file.FileWatcher;
public class FileChangedTest implements FileChangeListener{ public class FileChangedTest implements FileChangeListener{
public static void main(String[] args) throws URISyntaxException, FileNotFoundException{ public static void main(String[] args) throws URISyntaxException, FileNotFoundException{

View file

@ -4,8 +4,8 @@ import java.io.File;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.util.List; import java.util.List;
import zutil.FileUtil;
import zutil.Hasher; import zutil.Hasher;
import zutil.io.file.FileUtil;
public class FileFinderHasherTest { public class FileFinderHasherTest {
public static void main(String[] args) throws URISyntaxException{ public static void main(String[] args) throws URISyntaxException{

View file

@ -5,7 +5,7 @@ import java.io.IOException;
import javax.wsdl.WSDLException; import javax.wsdl.WSDLException;
import zutil.MultiPrintStream; import zutil.io.MultiPrintStream;
import zutil.network.http.HttpServer; import zutil.network.http.HttpServer;
import zutil.network.http.soap.SOAPHttpPage; import zutil.network.http.soap.SOAPHttpPage;
import zutil.network.ssdp.SSDPServer; import zutil.network.ssdp.SSDPServer;

View file

@ -31,7 +31,7 @@ import javax.swing.text.Document;
import javax.swing.text.Style; import javax.swing.text.Style;
import javax.swing.text.StyleConstants; import javax.swing.text.StyleConstants;
import zutil.FileUtil; import zutil.io.file.FileUtil;
/** /**
* Creates a Swing console window Thats takes System.in and * Creates a Swing console window Thats takes System.in and

View file

@ -7,8 +7,8 @@ import java.io.IOException;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
import javax.swing.JPanel; import javax.swing.JPanel;
import zutil.FileUtil;
import zutil.image.ImageUtil; import zutil.image.ImageUtil;
import zutil.io.file.FileUtil;
/** /**
* This class is a panel with a background image * This class is a panel with a background image

View file

@ -20,8 +20,8 @@ import javax.swing.WindowConstants;
import javax.swing.GroupLayout.Alignment; import javax.swing.GroupLayout.Alignment;
import javax.swing.LayoutStyle.ComponentPlacement; import javax.swing.LayoutStyle.ComponentPlacement;
import zutil.FileUtil; import zutil.io.MultiPrintStream;
import zutil.MultiPrintStream; import zutil.io.file.FileUtil;
import zutil.struct.HistoryList; import zutil.struct.HistoryList;
import zutil.ui.JImagePanel; import zutil.ui.JImagePanel;
import zutil.ui.wizard.listener.BlockingWizardListener; import zutil.ui.wizard.listener.BlockingWizardListener;