On Sun, Oct 19, 2008 at 9:32 PM, <[EMAIL PROTECTED]> wrote:
> Author: j16sdiz
> Date: 2008-10-19 13:32:27 +0000 (Sun, 19 Oct 2008)
> New Revision: 23010
>
> Modified:
> trunk/freenet/src/freenet/support/io/ArrayBucket.java
> Log:
> Don't append for ArrayBucket
> - see
> http://archives.freenetproject.org/message/20081014.143053.dd1d17ba.en.html
>
I have done some insert/request test. Everything seems fine.
PaddedEphemerallyEncryptedBucket throws IOException if we call
getOutputStream() twice -- do we want to do the same for ArrayBucket?
> Modified: trunk/freenet/src/freenet/support/io/ArrayBucket.java
> ===================================================================
> --- trunk/freenet/src/freenet/support/io/ArrayBucket.java 2008-10-18
> 23:14:36 UTC (rev 23009)
> +++ trunk/freenet/src/freenet/support/io/ArrayBucket.java 2008-10-19
> 13:32:27 UTC (rev 23010)
> @@ -5,8 +5,6 @@
> import java.io.IOException;
> import java.io.InputStream;
> import java.io.OutputStream;
> -import java.util.ArrayList;
> -import java.util.Iterator;
>
> import freenet.support.api.Bucket;
>
> @@ -18,8 +16,7 @@
> * @author oskar
> */
> public class ArrayBucket implements Bucket {
> -
> - private final ArrayList<byte[]> data;
> + private volatile byte[] data;
> private String name;
> private boolean readOnly;
>
> @@ -29,11 +26,11 @@
>
> public ArrayBucket(byte[] initdata) {
> this("ArrayBucket");
> - data.add(initdata);
> + data = initdata;
> }
>
> public ArrayBucket(String name) {
> - data = new ArrayList<byte[]>();
> + data = new byte[0];
> this.name = name;
> }
>
> @@ -43,24 +40,16 @@
> }
>
> public InputStream getInputStream() {
> - return new ArrayBucketInputStream();
> + return new ByteArrayInputStream(data);
> }
>
> @Override
> public String toString() {
> - StringBuilder s = new StringBuilder(250);
> - for (byte[] b : data) {
> - s.append(new String(b));
> - }
> - return s.toString();
> + return new String(data);
> }
>
> public long size() {
> - long size = 0;
> - for (byte[] b : data) {
> - size += b.length;
> - }
> - return size;
> + return data.length;
> }
>
> public String getName() {
> @@ -77,85 +66,13 @@
> @Override
> public synchronized void close() throws IOException {
> if(hasBeenClosed) return;
> - data.add(super.toByteArray());
> + data = super.toByteArray();
> if(readOnly) throw new IOException("Read only");
> // FIXME maybe we should throw on write instead? :)
> hasBeenClosed = true;
> }
> }
>
> - private class ArrayBucketInputStream extends InputStream {
> -
> - private Iterator<byte[]> i;
> - private ByteArrayInputStream in;
> -
> - public ArrayBucketInputStream() {
> - i = data.iterator();
> - }
> -
> - @Override
> - public int read() {
> - return priv_read();
> - }
> -
> - private int priv_read() {
> - if (in == null) {
> - if (i.hasNext()) {
> - in = new
> ByteArrayInputStream(i.next());
> - } else {
> - return -1;
> - }
> - }
> - int i = in.read();
> - if (i == -1) {
> - in = null;
> - return priv_read();
> - } else {
> - return i;
> - }
> - }
> -
> - @Override
> - public int read(byte[] b) {
> - return priv_read(b, 0, b.length);
> - }
> -
> - @Override
> - public int read(byte[] b, int off, int len) {
> - return priv_read(b, off, len);
> - }
> -
> - private int priv_read(byte[] b, int off, int len) {
> - if (in == null) {
> - if (i.hasNext()) {
> - in = new
> ByteArrayInputStream(i.next());
> - } else {
> - return -1;
> - }
> - }
> - int i = in.read(b, off, len);
> - if (i == -1) {
> - in = null;
> - return priv_read(b, off, len);
> - } else {
> - return i;
> - }
> - }
> -
> - @Override
> - public int available() {
> - if (in == null) {
> - if (i.hasNext()) {
> - in = new
> ByteArrayInputStream(i.next());
> - } else {
> - return 0;
> - }
> - }
> - return in.available();
> - }
> -
> - }
> -
> public boolean isReadOnly() {
> return readOnly;
> }
> @@ -165,7 +82,7 @@
> }
>
> public void free() {
> - data.clear();
> + data = new byte[0];
> // Not much else we can do.
> }
>
> @@ -173,13 +90,7 @@
> long sz = size();
> int size = (int)sz;
> byte[] buf = new byte[size];
> - int index = 0;
> - for (byte[] obuf : data) {
> - System.arraycopy(obuf, 0, buf, index, obuf.length);
> - index += obuf.length;
> - }
> - if(index != buf.length)
> - throw new IllegalStateException();
> + System.arraycopy(data, 0, buf, 0, size);
> return buf;
> }
> }
>
> _______________________________________________
> cvs mailing list
> [EMAIL PROTECTED]
> http://emu.freenetproject.org/cgi-bin/mailman/listinfo/cvs
>
_______________________________________________
Devl mailing list
[email protected]
http://emu.freenetproject.org/cgi-bin/mailman/listinfo/devl