Many bugfixes and improvements
This commit is contained in:
parent
c3e3bbf787
commit
363e0c6cfc
52 changed files with 2021 additions and 982 deletions
|
|
@ -27,7 +27,7 @@ public class BoundaryBufferedInputStream extends FilterInputStream{
|
|||
/**
|
||||
* Creates a instance of this class with a default buffer size of 64K
|
||||
*
|
||||
* @param in is the InputStream that the buffer will use
|
||||
* @param in is the InputStream that the buffer will use
|
||||
*/
|
||||
public BoundaryBufferedInputStream(InputStream in){
|
||||
this(in, DEFAULT_BUF_SIZE);
|
||||
|
|
@ -41,7 +41,8 @@ public class BoundaryBufferedInputStream extends FilterInputStream{
|
|||
*/
|
||||
public BoundaryBufferedInputStream(InputStream in, int buf_size){
|
||||
super(in);
|
||||
reset();
|
||||
buf_end = 0;
|
||||
buf_pos = 0;
|
||||
buffer = new byte[buf_size];
|
||||
}
|
||||
|
||||
|
|
@ -50,7 +51,7 @@ public class BoundaryBufferedInputStream extends FilterInputStream{
|
|||
* buffer and then fills the buffer with data from
|
||||
* the source stream to the buffer
|
||||
*
|
||||
* @return the size of the buffer
|
||||
* @return the size of the buffer
|
||||
* @throws IOException
|
||||
*/
|
||||
protected int fillBuffer() throws IOException {
|
||||
|
|
@ -64,38 +65,28 @@ public class BoundaryBufferedInputStream extends FilterInputStream{
|
|||
return n+leftover;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets the buffer
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
public synchronized void reset(){
|
||||
buf_end = 0;
|
||||
buf_pos = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the next byte in the buffer
|
||||
* @return the next byte in the buffer
|
||||
*/
|
||||
public final int read() throws IOException{
|
||||
if(buf_pos >= buf_end) {
|
||||
if(buf_pos >= buf_end-boundary.length) {
|
||||
if(fillBuffer() < 0)
|
||||
return -1;
|
||||
}
|
||||
if(buf_end == 0) {
|
||||
return -1;
|
||||
} else {
|
||||
buf_pos++;
|
||||
return buffer[buf_pos-1];
|
||||
return buffer[buf_pos++];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fills the given array with data from the buffer
|
||||
*
|
||||
* @param b is the array that will be filled
|
||||
* @return the amount of bytes read or -1 if eof
|
||||
*/
|
||||
* @param b is the array that will be filled
|
||||
* @return the amount of bytes read or -1 if EOF
|
||||
*/
|
||||
public int read(byte b[]) throws IOException {
|
||||
return read(b, 0, b.length);
|
||||
}
|
||||
|
|
@ -106,10 +97,10 @@ public class BoundaryBufferedInputStream extends FilterInputStream{
|
|||
* @param b is the array that will be filled
|
||||
* @param off is the offset in the array
|
||||
* @param len is the amount to read
|
||||
* @return the amount of bytes read or -1 if eof
|
||||
* @return the amount of bytes read or -1 if EOF
|
||||
*/
|
||||
public int read(byte b[], int off, int len) throws IOException {
|
||||
if(buf_pos >= buf_end) {
|
||||
if(buf_pos >= buf_end-boundary.length) {
|
||||
if(fillBuffer() < 0)
|
||||
return -1; // EOF
|
||||
}
|
||||
|
|
@ -129,6 +120,13 @@ public class BoundaryBufferedInputStream extends FilterInputStream{
|
|||
return leftover;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: Skips over the boundary
|
||||
*/
|
||||
public void next(){
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param n the number of bytes to be skipped.
|
||||
* @return the actual number of bytes skipped.
|
||||
|
|
@ -141,6 +139,21 @@ public class BoundaryBufferedInputStream extends FilterInputStream{
|
|||
}
|
||||
return buf_pos += n;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the boundary for the stream
|
||||
*/
|
||||
public void setBoundary(String b){
|
||||
this.boundary = b.getBytes();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the boundary for the stream
|
||||
*/
|
||||
public void setBoundary(byte[] b){
|
||||
boundary = new byte[b.length];
|
||||
System.arraycopy(b, 0, boundary, 0, b.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return an estimate of the number of bytes that can be read (or skipped
|
||||
|
|
@ -152,7 +165,10 @@ public class BoundaryBufferedInputStream extends FilterInputStream{
|
|||
}
|
||||
|
||||
/**
|
||||
* Unimplemented
|
||||
*/
|
||||
public synchronized void mark(int readlimit) {}
|
||||
* Tests if this input stream supports the mark and
|
||||
* reset methods.
|
||||
*/
|
||||
public boolean markSupported(){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
108
src/zutil/io/StringInputStream.java
Normal file
108
src/zutil/io/StringInputStream.java
Normal file
|
|
@ -0,0 +1,108 @@
|
|||
package zutil.io;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
/**
|
||||
* This class saves all the input data in to an StringBuffer
|
||||
*
|
||||
* @author Ziver
|
||||
*
|
||||
*/
|
||||
public class StringInputStream extends InputStream{
|
||||
// The buffer
|
||||
protected StringBuilder buffer;
|
||||
|
||||
/**
|
||||
* Creates an new instance of this class
|
||||
*/
|
||||
public StringInputStream(){
|
||||
clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an estimate of the number of bytes
|
||||
* that can be read (or skipped over) from this
|
||||
* input stream without blocking by the next
|
||||
* invocation of a method for this input stream.
|
||||
*/
|
||||
public int available(){
|
||||
return buffer.length();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Reads the next byte of data from the input stream.
|
||||
*/
|
||||
public int read(){
|
||||
int ret = Character.getNumericValue( buffer.charAt( 0 ));
|
||||
buffer.deleteCharAt( 0 );
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads some number of bytes from the input stream
|
||||
* and stores them into the buffer array b.
|
||||
*/
|
||||
public int read(byte[] b){
|
||||
return read( b, 0, b.length );
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads up to len bytes of data from the input stream
|
||||
* into an array of bytes.
|
||||
*/
|
||||
public int read(byte[] b, int off, int len){
|
||||
if( buffer.length() < len ){
|
||||
len = buffer.length();
|
||||
}
|
||||
char[] ctmp = new char[len];
|
||||
buffer.getChars(0, len, ctmp, 0);
|
||||
byte[] btmp = new String( ctmp ).getBytes();
|
||||
System.arraycopy(btmp, 0, b, off, len);
|
||||
return len;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Skips over and discards n bytes of data from this
|
||||
* input stream.
|
||||
*
|
||||
* @param n is the amount characters to skip
|
||||
*/
|
||||
public long skip(long n){
|
||||
if( buffer.length() < n ){
|
||||
int len = buffer.length();
|
||||
buffer.delete(0, len);
|
||||
return len;
|
||||
}
|
||||
else{
|
||||
buffer.delete(0, (int) n);
|
||||
return n;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests if this input stream supports the mark and
|
||||
* reset methods.
|
||||
*/
|
||||
public boolean markSupported(){
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Closes this input stream and releases any system
|
||||
* resources associated with the stream.
|
||||
*/
|
||||
public void close(){
|
||||
clear();
|
||||
}
|
||||
|
||||
public void clear(){
|
||||
buffer = new StringBuilder();
|
||||
}
|
||||
|
||||
public void add( String data ){
|
||||
buffer.append( data );
|
||||
}
|
||||
}
|
||||
|
|
@ -10,10 +10,12 @@ import java.net.URL;
|
|||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.regex.Matcher;
|
||||
|
||||
import zutil.io.IOUtil;
|
||||
import zutil.io.MultiPrintStream;
|
||||
import zutil.log.LogUtil;
|
||||
|
||||
/**
|
||||
* File path utilities
|
||||
|
|
@ -21,6 +23,7 @@ import zutil.io.MultiPrintStream;
|
|||
* @author Ziver
|
||||
*/
|
||||
public class FileUtil {
|
||||
public static final Logger logger = LogUtil.getLogger();
|
||||
|
||||
/**
|
||||
* Returns a String with a relative path from the given path
|
||||
|
|
@ -30,6 +33,8 @@ public class FileUtil {
|
|||
* @return A String with a relative path
|
||||
*/
|
||||
public static String relativePath(File file, String path){
|
||||
if( file == null || path == null )
|
||||
return null;
|
||||
String absolute = file.getAbsolutePath();
|
||||
String tmpPath = path.replaceAll(
|
||||
"[/\\\\]",
|
||||
|
|
@ -231,10 +236,11 @@ public class FileUtil {
|
|||
for(int i=0; i<temp.length ;i++){
|
||||
file = new File(dir.getPath()+File.separator+temp[i]);
|
||||
if(file.isDirectory()){
|
||||
logger.finer("Found Folder: "+file);
|
||||
search(new File(dir.getPath()+File.separator+temp[i]+File.separator), fileList, folders, recurse);
|
||||
}
|
||||
else if(file.isFile()){
|
||||
MultiPrintStream.out.println("File Found: "+file);
|
||||
logger.finer("Found File: "+file);
|
||||
fileList.add(file);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue