diff --git a/src/zutil/Dumpable.java b/src/zutil/Dumpable.java
new file mode 100644
index 00000000..c5fcf87b
--- /dev/null
+++ b/src/zutil/Dumpable.java
@@ -0,0 +1,13 @@
+package zutil;
+
+/**
+ * If an class implements this interface and runs it through
+ * MultiPrintStream.dump then all the values in the object
+ * will be written out.
+ *
+ * @author Ziver
+ *
+ */
+public interface Dumpable {
+
+}
diff --git a/src/zutil/MultiPrintStream.java b/src/zutil/MultiPrintStream.java
index 696ec9d0..c95ce6bf 100644
--- a/src/zutil/MultiPrintStream.java
+++ b/src/zutil/MultiPrintStream.java
@@ -199,7 +199,7 @@ public class MultiPrintStream extends PrintStream {
* @param o is the Object to dump
*/
public void dump( Object o ){
- dumpToString( o );
+ println(dumpToString( o ));
}
/**
@@ -212,24 +212,45 @@ public class MultiPrintStream extends PrintStream {
*
- Instance variables of a Object
*
* @param o is the Object to dump
- * @param print is if the method should print the data or just return it
+ * @return A String with all the printed data
+ */
+ public String dumpToString( Object o) {
+ return dumpToString(o, "");
+ }
+
+ /**
+ * Dumps the content of:
+ *
- Array content
+ *
- Map content (HashMap etc.)
+ *
- List content (ArrayList, LinkedList etc.)
+ *
- InputStream content (Prints out until the end of the stream)
+ *
- Reader content (Prints out until the end of the reader)
+ *
- Instance variables of a Object
+ *
+ * @param o is the Object to dump
+ * @param head is the string that will be put in front of every line
* @return A String with all the printed data
*/
@SuppressWarnings("unchecked")
- public String dumpToString( Object o ) {
+ private String dumpToString( Object o , String head) {
if(o == null) return "NULL";
StringBuffer buffer = new StringBuffer();
Class oClass = o.getClass();
buffer.append( oClass.getName() );
+ String nextHead = head + "\t";
// Prints out Arrays
- if ( oClass.isArray() ) {
+ if ( oClass.isArray() ) {
buffer.append( "[" );
for ( int i=0; i 0 )
- buffer.append( ", " );
Object value = Array.get(o,i);
- buffer.append( (dumbCapable(value) ? dumpToString(value) : value) );
+ buffer.append("\n");
+ buffer.append(nextHead);
+ buffer.append( (dumbCapable(value) ? dumpToString(value, nextHead) : value) );
+ if ( i+1" );
- buffer.append( (dumbCapable(value) ? dumpToString(value) : value) );
+ buffer.append( (dumbCapable(value) ? dumpToString(value, nextHead) : value) );
if(it.hasNext())
- buffer.append( ", " );
+ buffer.append( "," );
}
+ buffer.append( "\n" );
+ buffer.append(head);
buffer.append( "}" );
}
// Prints out data from InputStream
else if(o instanceof InputStream){
- buffer.append( " =>{ \n" );
+ buffer.append( " =>{\n" );
try {
InputStream in = (InputStream)o;
int tmp;
while((tmp = in.read()) != -1){
+ buffer.append(nextHead);
buffer.append( (char)tmp );
}
in.close();
} catch (IOException e) {
e.printStackTrace(this);
}
- buffer.append( "\n}" );
+ buffer.append( "\n" );
+ buffer.append(head);
+ buffer.append( "}" );
}
// Prints out data from InputStream
else if(o instanceof Reader){
- buffer.append( " =>{ \n" );
+ buffer.append( " =>{\n" );
try {
Reader in = (Reader)o;
int tmp;
while((tmp = in.read()) != -1){
+ buffer.append(nextHead);
buffer.append( (char)tmp );
}
in.close();
} catch (IOException e) {
e.printStackTrace(this);
}
- buffer.append( "\n}" );
+ buffer.append( "\n" );
+ buffer.append(head);
+ buffer.append( "}" );
}
// Prints out Object properties
else{
@@ -295,20 +330,24 @@ public class MultiPrintStream extends PrintStream {
while ( oClass != null ) {
Field[] fields = oClass.getDeclaredFields();
for ( int i=0; i 1 )
- buffer.append( ", " );
fields[i].setAccessible( true );
+ buffer.append("\n");
+ buffer.append(head);
buffer.append( fields[i].getName() );
buffer.append( "=" );
try {
Object value = fields[i].get(o);
if (value != null) {
- buffer.append( (dumbCapable(value) ? dumpToString(value) : value) );
+ buffer.append( (dumbCapable(value) ? dumpToString(value, nextHead) : value) );
}
} catch ( IllegalAccessException e ) {}
+ if ( i+1)return true;
+ else if(o instanceof Map,?>)return true;
+ else if(o instanceof InputStream)return true;
+ else if(o instanceof Reader)return true;
+ else if(o instanceof Dumpable)return true;
}
return false;
}
diff --git a/src/zutil/db/MySQLQueue.java b/src/zutil/db/MySQLQueue.java
index 15d50e05..171a478d 100644
--- a/src/zutil/db/MySQLQueue.java
+++ b/src/zutil/db/MySQLQueue.java
@@ -93,7 +93,7 @@ public class MySQLQueue implements Queue{
return poll();
}
- public boolean addAll(Collection arg0) {
+ public boolean addAll(Collection extends E> arg0) {
// TODO Auto-generated method stub
return false;
}
@@ -119,7 +119,7 @@ public class MySQLQueue implements Queue{
return false;
}
- public boolean containsAll(Collection arg0) {
+ public boolean containsAll(Collection> arg0) {
// TODO Auto-generated method stub
return false;
}
@@ -128,7 +128,7 @@ public class MySQLQueue implements Queue{
return (peek() != null);
}
- public Iterator iterator() {
+ public Iterator iterator() {
// TODO Auto-generated method stub
return null;
}
@@ -144,12 +144,12 @@ public class MySQLQueue implements Queue{
return false;
}
- public synchronized boolean removeAll(Collection arg0) {
+ public synchronized boolean removeAll(Collection> arg0) {
// TODO Auto-generated method stub
return false;
}
- public boolean retainAll(Collection arg0) {
+ public boolean retainAll(Collection> arg0) {
// TODO Auto-generated method stub
return false;
}
diff --git a/src/zutil/network/FTPClient.java b/src/zutil/network/FTPClient.java
index 43e37f03..a44c0c48 100644
--- a/src/zutil/network/FTPClient.java
+++ b/src/zutil/network/FTPClient.java
@@ -7,7 +7,9 @@ import java.io.InputStreamReader;
import java.io.PrintStream;
import java.net.Socket;
import java.net.UnknownHostException;
+import java.util.ArrayList;
import java.util.LinkedList;
+import java.util.regex.Pattern;
import javax.security.auth.login.AccountException;
@@ -51,7 +53,8 @@ public class FTPClient extends Thread{
public static void main(String[] args){
try {
- FTPClient client = new FTPClient("koc.se", 21, "ziver", "****", FTP_PASSIVE);
+ FTPClient client = new FTPClient("213.180.86.135", 21, "administrator", "geineZ2K", FTP_PASSIVE);
+ /*
client.createDir("./ziver/lol");
client.removeDir("./ziver/lol");
@@ -67,7 +70,12 @@ public class FTPClient extends Thread{
MultiPrintStream.out.dump(client.getFileList("./ziver"));
client.removeFile("./ziver/test.txt");
MultiPrintStream.out.dump(client.getFileList("./ziver"));
-
+ */
+ ArrayList tmp = client.getFileInfo("");
+ MultiPrintStream.out.println("****************");
+ MultiPrintStream.out.dump(tmp);
+ MultiPrintStream.out.println(tmp.size());
+ MultiPrintStream.out.println("****************");
client.close();
} catch (Exception e) {
e.printStackTrace();
@@ -150,7 +158,7 @@ public class FTPClient extends Thread{
* @return The input line
* @throws IOException
*/
- private synchronized String readCommand(boolean print) throws IOException{
+ public synchronized String readCommand(boolean print) throws IOException{
String tmp = in.readLine();
if(print)System.out.println(tmp);
if(parseReturnCode(tmp) >= 400 ) throw new IOException(tmp);
@@ -161,7 +169,7 @@ public class FTPClient extends Thread{
/**
* Reads from the command channel until there are nothing
* left to read and returns the last line
- * Multiple
+ *
* @param print To print out the received lines
* @return The last received line
* @throws IOException
@@ -225,28 +233,28 @@ public class FTPClient extends Thread{
/**
* Returns information about the file or directory
- * (This is system specific information)
*
- * TODO:
- * @deprecated DOSENT WORK!!!!
+ * @deprecated
* @param path The path and filename of a file or a directory
- * @return A String with information
+ * @return A List of Strings with information
* @throws IOException
*/
- public String getFileInfo(String path) throws IOException{
- StringBuffer info = new StringBuffer("");
+ public ArrayList getFileInfo(String path) throws IOException{
+ Pattern regex = Pattern.compile("\\s{1,}");
+ ArrayList info = new ArrayList();
BufferedReader data_in = getDataInputStream();
- sendCommand("LIST "+path, true);
+ sendCommand("LIST "+path, DEBUG);
String tmp = "";
- while((tmp = data_in.readLine()) != null){
- info.append(tmp);
+ while((tmp = data_in.readLine()) != null){
+ System.err.println(tmp);
+ info.add(regex.split(tmp));
}
data_in.close();
readCommand(DEBUG);
- return info.toString();
+ return info;
}
/**
diff --git a/src/zutil/network/nio/NioNetwork.java b/src/zutil/network/nio/NioNetwork.java
index 2a29e682..b3899a30 100644
--- a/src/zutil/network/nio/NioNetwork.java
+++ b/src/zutil/network/nio/NioNetwork.java
@@ -32,11 +32,11 @@ public abstract class NioNetwork implements Runnable {
/**
* Debug level
* 0 = nothing
- * 1 = connection debug
+ * 1 = connection info
* 2 = message debug
* 3 = selector debug
*/
- public static final int DEBUG = 2;
+ public static int DEBUG = 2;
public static enum NetworkType {SERVER, CLIENT};
private NetworkType type;
@@ -139,7 +139,7 @@ public abstract class NioNetwork implements Runnable {
* @param data The data to send
*/
protected void queueSend(SocketChannel socket, byte[] data){
- if(DEBUG>=3)MultiPrintStream.out.println("Sending Queue...");
+ if(DEBUG>=3) MultiPrintStream.out.println("Sending Queue...");
// And queue the data we want written
synchronized (pendingWriteData) {
List queue = pendingWriteData.get(socket);
@@ -157,7 +157,7 @@ public abstract class NioNetwork implements Runnable {
// Indicate we want the interest ops set changed
pendingChanges.add(new ChangeRequest(socket, ChangeRequest.CHANGEOPS, SelectionKey.OP_WRITE));
}
- if(DEBUG>=3)MultiPrintStream.out.println("selector.wakeup();");
+ if(DEBUG>=3) MultiPrintStream.out.println("selector.wakeup();");
// Finally, wake up our selecting thread so it can make the required changes
selector.wakeup();
}
@@ -175,11 +175,11 @@ public abstract class NioNetwork implements Runnable {
case ChangeRequest.CHANGEOPS:
SelectionKey key = change.socket.keyFor(selector);
key.interestOps(change.ops);
- if(DEBUG>=3)MultiPrintStream.out.println("change.ops "+change.ops);
+ if(DEBUG>=3) MultiPrintStream.out.println("change.ops "+change.ops);
break;
case ChangeRequest.REGISTER:
change.socket.register(selector, change.ops);
- if(DEBUG>=3)MultiPrintStream.out.println("register socket ");
+ if(DEBUG>=3) MultiPrintStream.out.println("register socket ");
break;
}
}
@@ -188,31 +188,31 @@ public abstract class NioNetwork implements Runnable {
// Wait for an event one of the registered channels
selector.select();
- if(DEBUG>=3)MultiPrintStream.out.println("selector is awake");
+ if(DEBUG>=3) MultiPrintStream.out.println("selector is awake");
// Iterate over the set of keys for which events are available
Iterator selectedKeys = selector.selectedKeys().iterator();
while (selectedKeys.hasNext()) {
SelectionKey key = (SelectionKey) selectedKeys.next();
selectedKeys.remove();
- if(DEBUG>=3)MultiPrintStream.out.println("KeyOP: "+key.interestOps()+" isAcceptable: "+SelectionKey.OP_ACCEPT+" isConnectable: "+SelectionKey.OP_CONNECT+" isWritable: "+SelectionKey.OP_WRITE+" isReadable: "+SelectionKey.OP_READ);
+ if(DEBUG>=3) MultiPrintStream.out.println("KeyOP: "+key.interestOps()+" isAcceptable: "+SelectionKey.OP_ACCEPT+" isConnectable: "+SelectionKey.OP_CONNECT+" isWritable: "+SelectionKey.OP_WRITE+" isReadable: "+SelectionKey.OP_READ);
if (key.isValid()) {
// Check what event is available and deal with it
if (key.isAcceptable()) {
- if(DEBUG>=3)MultiPrintStream.out.println("Accepting Connection!!");
+ if(DEBUG>=3) MultiPrintStream.out.println("Accepting Connection!!");
accept(key);
}
else if (key.isConnectable()) {
- if(DEBUG>=3)MultiPrintStream.out.println("Finnishing Connection!!");
+ if(DEBUG>=3) MultiPrintStream.out.println("Finnishing Connection!!");
finishConnection(key);
}
else if (key.isWritable()) {
- if(DEBUG>=3)MultiPrintStream.out.println("Writing");
+ if(DEBUG>=3) MultiPrintStream.out.println("Writing");
write(key);
}
else if (key.isReadable()) {
- if(DEBUG>=3)MultiPrintStream.out.println("Reading");
+ if(DEBUG>=3) MultiPrintStream.out.println("Reading");
read(key);
}
}
@@ -269,7 +269,7 @@ public abstract class NioNetwork implements Runnable {
clients.remove(remoteAdr);
pendingReadData.remove(socketChannel);
pendingWriteData.remove(socketChannel);
- if(DEBUG>=1)MultiPrintStream.out.println("Connection Forced Close("+remoteAdr+")!!! Connection Count: "+clients.size());
+ if(DEBUG>=1) MultiPrintStream.out.println("Connection Forced Close("+remoteAdr+")!!! Connection Count: "+clients.size());
if(type == NetworkType.CLIENT) throw new IOException("Server Closed The Connection!!!");
return;
}
@@ -282,7 +282,7 @@ public abstract class NioNetwork implements Runnable {
clients.remove(remoteAdr);
pendingReadData.remove(socketChannel);
pendingWriteData.remove(socketChannel);
- if(DEBUG>=1)MultiPrintStream.out.println("Connection Close("+remoteAdr+")!!! Connection Count: "+clients.size());
+ if(DEBUG>=1) MultiPrintStream.out.println("Connection Close("+remoteAdr+")!!! Connection Count: "+clients.size());
if(type == NetworkType.CLIENT) throw new IOException("Server Closed The Connection!!!");
return;
}
@@ -293,26 +293,25 @@ public abstract class NioNetwork implements Runnable {
System.arraycopy(readBuffer.array(), 0, rspByteData, 0, numRead);
if(encrypter != null)// Encryption
rspByteData = encrypter.decrypt(rspByteData);
-
- /*
+
+ // Message Count 1m: 36750
+ // Message Count 1s: 612
if(!pendingReadData.containsKey(socketChannel)){
pendingReadData.put(socketChannel, new DynamicByteArrayStream());
}
- if(encrypter != null)// Encryption
- rspByteData = encrypter.decrypt(rspByteData);
-
- pendingReadData.get(socketChannel).add(rspByteData);
- */
+ DynamicByteArrayStream dynBuf = pendingReadData.get(socketChannel);
+ dynBuf.add(rspByteData);
+
Object rspData = null;
try{
- rspData = Converter.toObject(rspByteData);
- //rspData = Converter.toObject(pendingReadData.get(socketChannel));
+ //rspData = Converter.toObject(rspByteData);
+ rspData = Converter.toObject(dynBuf);
handleRecivedMessage(socketChannel, rspData);
- //pendingReadData.get(socketChannel).clear();
+ dynBuf.clear();
}catch(Exception e){
e.printStackTrace();
- //pendingReadData.get(socketChannel).reset();
+ dynBuf.reset();
}
}
@@ -326,18 +325,16 @@ public abstract class NioNetwork implements Runnable {
List queue = pendingWriteData.get(socketChannel);
if(queue == null){
queue = new ArrayList();
+ pendingWriteData.put(socketChannel, queue);
}
- int i = 0;
// Write until there's not more data ...
while (!queue.isEmpty()) {
ByteBuffer buf = queue.get(0);
- i += buf.remaining();
socketChannel.write(buf);
- i -= buf.remaining();
if (buf.remaining() > 0) {
// ... or the socket's buffer fills up
- if(DEBUG>=3)MultiPrintStream.out.println("Write Buffer Full!!");
+ if(DEBUG>=3) MultiPrintStream.out.println("Write Buffer Full!!");
break;
}
queue.remove(0);
@@ -347,31 +344,32 @@ public abstract class NioNetwork implements Runnable {
// We wrote away all data, so we're no longer interested
// in writing on this socket. Switch back to waiting for
// data.
- if(DEBUG>=3)MultiPrintStream.out.println("No more Data to write!!");
+ if(DEBUG>=3) MultiPrintStream.out.println("No more Data to write!!");
key.interestOps(SelectionKey.OP_READ);
}
}
}
private void handleRecivedMessage(SocketChannel socketChannel, Object rspData){
- if(DEBUG>=2)MultiPrintStream.out.println("Handling incomming message...");
+ if(DEBUG>=2) MultiPrintStream.out.println("Handling incomming message...");
+
if(rspData instanceof SystemMessage){
if(systemWorker != null){
- if(DEBUG>=3)MultiPrintStream.out.println("System Message!!!");
+ if(DEBUG>=3) MultiPrintStream.out.println("System Message!!!");
systemWorker.processData(this, socketChannel, rspData);
}
else{
- if(DEBUG>=2)MultiPrintStream.out.println("Unhandled System Message!!!");
+ if(DEBUG>=2) MultiPrintStream.out.println("Unhandled System Message!!!");
}
}
else{
// Hand the data off to our worker thread
if(worker != null){
- if(DEBUG>=3)MultiPrintStream.out.println("Worker Message!!!");
+ if(DEBUG>=3) MultiPrintStream.out.println("Worker Message!!!");
worker.processData(this, socketChannel, rspData);
}
else{
- if(DEBUG>=1)MultiPrintStream.out.println("Unhandled Worker Message!!!");
+ if(DEBUG>=1) MultiPrintStream.out.println("Unhandled Worker Message!!!");
}
}
}
diff --git a/src/zutil/network/nio/worker/SystemWorker.java b/src/zutil/network/nio/worker/SystemWorker.java
index ca8239e1..4bb32656 100644
--- a/src/zutil/network/nio/worker/SystemWorker.java
+++ b/src/zutil/network/nio/worker/SystemWorker.java
@@ -34,19 +34,19 @@ public class SystemWorker extends ThreadedEventWorker {
@Override
public void messageEvent(WorkerDataEvent event) {
try {
- if(NioNetwork.DEBUG>=2)MultiPrintStream.out.println("System Message: "+event.data.getClass().getName());
+ if(NioNetwork.DEBUG>=2) MultiPrintStream.out.println("System Message: "+event.data.getClass().getName());
if(event.data instanceof Message){
if(event.data instanceof EchoMessage && ((EchoMessage)event.data).echo()){
// Echos back the recived message
((EchoMessage)event.data).recived();
- if(NioNetwork.DEBUG>=3)MultiPrintStream.out.println("Echoing Message: "+event.data);
+ if(NioNetwork.DEBUG>=3) MultiPrintStream.out.println("Echoing Message: "+event.data);
nio.send(event.socket, event.data);
}
else if(event.data instanceof ResponseRequestMessage &&
rspEvents.get(((ResponseRequestMessage)event.data).getResponseId()) != null){
// Handle the response
handleResponse(((ResponseRequestMessage)event.data).getResponseId(), event.data);
- if(NioNetwork.DEBUG>=3)MultiPrintStream.out.println("Response Request Message: "+event.data);
+ if(NioNetwork.DEBUG>=3) MultiPrintStream.out.println("Response Request Message: "+event.data);
}
else{
//Services
diff --git a/src/zutil/network/torrent/Torrent.java b/src/zutil/network/torrent/Torrent.java
index 7c9a2036..21482e6e 100644
--- a/src/zutil/network/torrent/Torrent.java
+++ b/src/zutil/network/torrent/Torrent.java
@@ -29,7 +29,7 @@ public class Torrent {
private boolean is_private;
public Torrent(File torrent) throws IOException{
- this(FileFinder.getFileContent(FileFinder.find("C:\\Users\\Ziver\\Desktop\\test.torrent")));
+ this(FileFinder.getFileContent( torrent ));
}
public Torrent(String data){
@@ -51,8 +51,9 @@ public class Torrent {
is_private = false;
}
+ @SuppressWarnings("unchecked")
private void decode(String data){
- HashMap dataMap = (HashMap)TorrentParser.decode(data);
+ HashMap,?> dataMap = (HashMap,?>)TorrentParser.decode(data);
name = (String)dataMap.get("name");
comment = (String)dataMap.get("comment");
@@ -65,4 +66,37 @@ public class Torrent {
info_hash = (HashMap)dataMap.get("info");
is_private = (((Integer)dataMap.get("private")) != 0);
}
+
+ // ************** GETTER **************
+ public String getName(){
+ return name;
+ }
+ public String getComments(){
+ return comment;
+ }
+ public long getDate(){
+ return date;
+ }
+ public ArrayList getFileList(){
+ return file_list;
+ }
+ public long getSize(){
+ return size;
+ }
+ public String getAuthor(){
+ return created_by;
+ }
+ public String getMainTracker(){
+ return main_tracker;
+ }
+ public ArrayList getTrackerList(){
+ return tracker_list;
+ }
+ public HashMap getInfoHash(){
+ return info_hash;
+ }
+ public boolean isPrivate(){
+ return is_private;
+ }
+ // ************************************
}
diff --git a/src/zutil/struct/DynamicByteArrayStream.java b/src/zutil/struct/DynamicByteArrayStream.java
index dae99f50..7b89af88 100644
--- a/src/zutil/struct/DynamicByteArrayStream.java
+++ b/src/zutil/struct/DynamicByteArrayStream.java
@@ -9,12 +9,12 @@ public class DynamicByteArrayStream extends InputStream{
private ArrayList bytes;
/** The current size of the stream */
private int size;
- /** points to the current index in the Arraylist */
- private int globalPointer;
- /** points localy in the current index in the ArrayList */
+ /** points to the current index in the ArrayList */
+ private int byteArrayIndex;
+ /** points locally in the current index in the ArrayList */
private int localPointer;
/** The current position */
- private int currentPos;
+ private int pos;
/**
* Create a new instance of DynamicByteArrayStream
@@ -22,9 +22,9 @@ public class DynamicByteArrayStream extends InputStream{
public DynamicByteArrayStream(){
bytes = new ArrayList();
size = 0;
- globalPointer = 0;
+ byteArrayIndex = 0;
localPointer = 0;
- currentPos = 0;
+ pos = 0;
}
/**
@@ -36,71 +36,77 @@ public class DynamicByteArrayStream extends InputStream{
size += b.length;
}
+ @Override
+ public synchronized int read() throws IOException {
+ if(pos >= size) return -1;
+
+ int ret = bytes.get(byteArrayIndex)[localPointer] & 0xff;
+ pos++;
+ localPointer++;
+ if(localPointer >= bytes.get(byteArrayIndex).length){
+ byteArrayIndex++;
+ localPointer = 0;
+ }
+ return ret;
+ }
+
+ public synchronized int read(byte b[], int off, int len) {
+ //System.out.println("*****************************************************");
+ //System.out.println("off: "+off+" len: "+len);
+ //System.out.println("size: "+size+" arraylen: "+bytes.size());
+ //System.out.println("pos: "+pos+" localPointer: "+localPointer);
+ if(len <= 0) return 0;
+ if(pos >= size) return -1;
+
+ int bytes_read = 0;
+ if(pos+len >= size) len = size - pos;
+ for(int i=0; i= src.length){
+ //System.out.println("1");
+ int length = src.length-localPointer;
+ System.arraycopy(src, localPointer, b, off+i, length);
+
+ localPointer = 0;
+ byteArrayIndex++;
+ bytes_read += length;
+ i += length;
+ }
+ else{
+ //System.out.println("2");
+ int length = len-i;
+ System.arraycopy(src, localPointer, b, off+i, length);
+
+ localPointer += length;
+ bytes_read += length;
+ i += length;
+ }
+ }
+ pos += len;
+ //System.out.println("new_pos: "+pos+" read: "+bytes_read);
+ return bytes_read;
+ }
+
+ public synchronized int available() {
+ return size - pos;
+ }
+
/**
* Clears this stream from the byte arrays
*/
public synchronized void clear(){
size = 0;
- globalPointer = 0;
- localPointer = 0;
- currentPos = 0;
-
+ reset();
bytes.clear();
}
- @Override
- public synchronized int read() throws IOException {
- if(currentPos >= size){
- return -1;
- }
- int ret = bytes.get(globalPointer)[localPointer] & 0xff;
- currentPos++;
- localPointer++;
- if(localPointer >= bytes.get(globalPointer).length){
- globalPointer++;
- localPointer = 0;
- }
- return ret;
- }
-/*
- public synchronized int read(byte b[], int off, int len) {
- System.out.println("read off:"+off+" len: "+len);
- if(currentPos+off >= size){
- return -1;
- }
- off += localPointer;
- while(off>0){
- if(bytes.get(globalPointer).length < off){
- globalPointer++;
- off -= bytes.get(globalPointer).length;
- }
- else break;
- }
-
- int length;
- int oldLen = len;
- while(len > 0){
- length = bytes.get(globalPointer).length;
- System.arraycopy(b, 0, bytes.get(globalPointer), 0, (length 0) globalPointer++;
- if(bytes.size() <= globalPointer) break;
- }
- localPointer = 0;
- currentPos += ( len<0 ? oldLen : oldLen-len);
- return ( len<0 ? oldLen : oldLen-len);
- }*/
-
- public synchronized int available() {
- return size - currentPos;
- }
-
public synchronized void reset() {
- globalPointer = 0;
+ byteArrayIndex = 0;
localPointer = 0;
- currentPos = 0;
+ pos = 0;
}
public void close() throws IOException {
+ //bytes = null;
}
}