Skip to content

Commit 4a92373

Browse files
author
Stephen Colebourne
committed
Optimize implementation by using the superclass instance variable
bug 28977, from Lars Beuster git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/io/trunk@154556 13f79535-47bb-0310-9956-ffa450edef68
1 parent 64320f1 commit 4a92373

4 files changed

Lines changed: 64 additions & 54 deletions

File tree

src/java/org/apache/commons/io/input/ProxyInputStream.java

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2004 The Apache Software Foundation.
2+
* Copyright 2002-2005 The Apache Software Foundation.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -23,67 +23,70 @@
2323
* A Proxy stream which acts as expected, that is it passes the method
2424
* calls on to the proxied stream and doesn't change which methods are
2525
* being called.
26-
*
26+
* <p>
2727
* It is an alternative base class to FilterInputStream
2828
* to increase reusability, because FilterInputStream changes the
2929
* methods being called, such as read(byte[]) to read(byte[], int, int).
30+
*
31+
* @author Henri Yandell
32+
* @author Stephen Colebourne
33+
* @version $Id$
3034
*/
3135
public abstract class ProxyInputStream extends FilterInputStream {
3236

33-
private InputStream proxy;
34-
3537
/**
3638
* Constructs a new ProxyInputStream.
37-
* @param proxy InputStream to delegate to
39+
*
40+
* @param proxy the InputStream to delegate to
3841
*/
3942
public ProxyInputStream(InputStream proxy) {
4043
super(proxy);
41-
this.proxy = proxy;
44+
// the proxy is stored in a protected superclass variable named 'in'
4245
}
4346

4447
/** @see java.io.InputStream#read() */
4548
public int read() throws IOException {
46-
return this.proxy.read();
49+
return in.read();
4750
}
4851

4952
/** @see java.io.InputStream#read(byte[]) */
5053
public int read(byte[] bts) throws IOException {
51-
return this.proxy.read(bts);
54+
return in.read(bts);
5255
}
5356

5457
/** @see java.io.InputStream#read(byte[], int, int) */
5558
public int read(byte[] bts, int st, int end) throws IOException {
56-
return this.proxy.read(bts, st, end);
59+
return in.read(bts, st, end);
5760
}
5861

5962
/** @see java.io.InputStream#skip(long) */
6063
public long skip(long ln) throws IOException {
61-
return this.proxy.skip(ln);
64+
return in.skip(ln);
6265
}
6366

6467
/** @see java.io.InputStream#available() */
6568
public int available() throws IOException {
66-
return this.proxy.available();
69+
return in.available();
6770
}
6871

6972
/** @see java.io.InputStream#close() */
7073
public void close() throws IOException {
71-
this.proxy.close();
74+
in.close();
7275
}
7376

7477
/** @see java.io.InputStream#mark(int) */
7578
public synchronized void mark(int idx) {
76-
this.proxy.mark(idx);
79+
in.mark(idx);
7780
}
7881

7982
/** @see java.io.InputStream#reset() */
8083
public synchronized void reset() throws IOException {
81-
this.proxy.reset();
84+
in.reset();
8285
}
8386

8487
/** @see java.io.InputStream#markSupported() */
8588
public boolean markSupported() {
86-
return this.proxy.markSupported();
89+
return in.markSupported();
8790
}
8891

8992
}

src/java/org/apache/commons/io/input/ProxyReader.java

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2004 The Apache Software Foundation.
2+
* Copyright 2002-2005 The Apache Software Foundation.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -23,67 +23,70 @@
2323
* A Proxy stream which acts as expected, that is it passes the method
2424
* calls on to the proxied stream and doesn't change which methods are
2525
* being called.
26-
*
26+
* <p>
2727
* It is an alternative base class to FilterReader
2828
* to increase reusability, because FilterReader changes the
2929
* methods being called, such as read(char[]) to read(char[], int, int).
30+
*
31+
* @author Henri Yandell
32+
* @author Stephen Colebourne
33+
* @version $Id$
3034
*/
3135
public abstract class ProxyReader extends FilterReader {
3236

33-
private Reader proxy;
34-
3537
/**
3638
* Constructs a new ProxyReader.
37-
* @param proxy Reader to delegate to
39+
*
40+
* @param proxy the Reader to delegate to
3841
*/
3942
public ProxyReader(Reader proxy) {
4043
super(proxy);
41-
this.proxy = proxy;
44+
// the proxy is stored in a protected superclass variable named 'in'
4245
}
4346

4447
/** @see java.io.Reader#read() */
4548
public int read() throws IOException {
46-
return this.proxy.read();
49+
return in.read();
4750
}
4851

4952
/** @see java.io.Reader#read(char[]) */
5053
public int read(char[] chr) throws IOException {
51-
return this.proxy.read(chr);
54+
return in.read(chr);
5255
}
5356

5457
/** @see java.io.Reader#read(char[], int, int) */
5558
public int read(char[] chr, int st, int end) throws IOException {
56-
return this.proxy.read(chr, st, end);
59+
return in.read(chr, st, end);
5760
}
5861

5962
/** @see java.io.Reader#skip(long) */
6063
public long skip(long ln) throws IOException {
61-
return this.proxy.skip(ln);
64+
return in.skip(ln);
6265
}
6366

6467
/** @see java.io.Reader#ready() */
6568
public boolean ready() throws IOException {
66-
return this.proxy.ready();
69+
return in.ready();
6770
}
6871

6972
/** @see java.io.Reader#close() */
7073
public void close() throws IOException {
71-
this.proxy.close();
74+
in.close();
7275
}
7376

7477
/** @see java.io.Reader#mark(int) */
7578
public synchronized void mark(int idx) throws IOException {
76-
this.proxy.mark(idx);
79+
in.mark(idx);
7780
}
7881

7982
/** @see java.io.Reader#reset() */
8083
public synchronized void reset() throws IOException {
81-
this.proxy.reset();
84+
in.reset();
8285
}
8386

8487
/** @see java.io.Reader#markSupported() */
8588
public boolean markSupported() {
86-
return this.proxy.markSupported();
89+
return in.markSupported();
8790
}
8891

8992
}

src/java/org/apache/commons/io/output/ProxyOutputStream.java

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2004 The Apache Software Foundation.
2+
* Copyright 2002-2005 The Apache Software Foundation.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -20,48 +20,50 @@
2020
import java.io.OutputStream;
2121

2222
/**
23-
*
2423
* A Proxy stream which acts as expected, that is it passes the method
2524
* calls on to the proxied stream and doesn't change which methods are
2625
* being called. It is an alternative base class to FilterOutputStream
2726
* to increase reusability.
27+
*
28+
* @author Henri Yandell
29+
* @author Stephen Colebourne
30+
* @version $Id$
2831
*/
2932
public class ProxyOutputStream extends FilterOutputStream {
3033

31-
private OutputStream proxy;
32-
3334
/**
3435
* Constructs a new ProxyOutputStream.
35-
* @param proxy OutputStream to delegate to
36+
*
37+
* @param proxy the OutputStream to delegate to
3638
*/
3739
public ProxyOutputStream(OutputStream proxy) {
3840
super(proxy);
39-
this.proxy = proxy;
41+
// the proxy is stored in a protected superclass variable named 'out'
4042
}
4143

4244
/** @see java.io.OutputStream#write(int) */
4345
public void write(int idx) throws IOException {
44-
this.proxy.write(idx);
46+
out.write(idx);
4547
}
4648

4749
/** @see java.io.OutputStream#write(byte[]) */
4850
public void write(byte[] bts) throws IOException {
49-
this.proxy.write(bts);
51+
out.write(bts);
5052
}
5153

5254
/** @see java.io.OutputStream#write(byte[], int, int) */
5355
public void write(byte[] bts, int st, int end) throws IOException {
54-
this.proxy.write(bts, st, end);
56+
out.write(bts, st, end);
5557
}
5658

5759
/** @see java.io.OutputStream#flush() */
5860
public void flush() throws IOException {
59-
this.proxy.flush();
61+
out.flush();
6062
}
6163

6264
/** @see java.io.OutputStream#close() */
6365
public void close() throws IOException {
64-
this.proxy.close();
66+
out.close();
6567
}
6668

6769
}
Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2004 The Apache Software Foundation.
2+
* Copyright 2002-2005 The Apache Software Foundation.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -20,60 +20,62 @@
2020
import java.io.Writer;
2121

2222
/**
23-
*
2423
* A Proxy stream which acts as expected, that is it passes the method
2524
* calls on to the proxied stream and doesn't change which methods are
2625
* being called. It is an alternative base class to FilterWriter
2726
* to increase reusability, because FilterWriter changes the
2827
* methods being called, such as write(char[]) to write(char[], int, int)
2928
* and write(String) to write(String, int, int).
29+
*
30+
* @author Henri Yandell
31+
* @author Stephen Colebourne
32+
* @version $Id$
3033
*/
3134
public class ProxyWriter extends FilterWriter {
3235

33-
private Writer proxy;
34-
3536
/**
3637
* Constructs a new ProxyWriter.
37-
* @param proxy Writer to delegate to
38+
*
39+
* @param proxy the Writer to delegate to
3840
*/
3941
public ProxyWriter(Writer proxy) {
4042
super(proxy);
41-
this.proxy = proxy;
43+
// the proxy is stored in a protected superclass variable named 'out'
4244
}
4345

4446
/** @see java.io.Writer#write(int) */
4547
public void write(int idx) throws IOException {
46-
this.proxy.write(idx);
48+
out.write(idx);
4749
}
4850

4951
/** @see java.io.Writer#write(char[]) */
5052
public void write(char[] chr) throws IOException {
51-
this.proxy.write(chr);
53+
out.write(chr);
5254
}
5355

5456
/** @see java.io.Writer#write(char[], int, int) */
5557
public void write(char[] chr, int st, int end) throws IOException {
56-
this.proxy.write(chr, st, end);
58+
out.write(chr, st, end);
5759
}
5860

5961
/** @see java.io.Writer#write(String) */
6062
public void write(String str) throws IOException {
61-
this.proxy.write(str);
63+
out.write(str);
6264
}
6365

6466
/** @see java.io.Writer#write(String, int, int) */
6567
public void write(String str, int st, int end) throws IOException {
66-
this.proxy.write(str, st, end);
68+
out.write(str, st, end);
6769
}
6870

6971
/** @see java.io.Writer#flush() */
7072
public void flush() throws IOException {
71-
this.proxy.flush();
73+
out.flush();
7274
}
7375

7476
/** @see java.io.Writer#close() */
7577
public void close() throws IOException {
76-
this.proxy.close();
78+
out.close();
7779
}
7880

7981
}

0 commit comments

Comments
 (0)