Skip to content

Commit 94d8c10

Browse files
author
Niall Pemberton
committed
IO-201 Fix inconsistent synchronization
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/io/trunk@1004079 13f79535-47bb-0310-9956-ffa450edef68
1 parent 79c97ab commit 94d8c10

2 files changed

Lines changed: 7 additions & 7 deletions

File tree

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public CountingInputStream(InputStream in) {
5555
* @see java.io.InputStream#skip(long)
5656
*/
5757
@Override
58-
public long skip(final long length) throws IOException {
58+
public synchronized long skip(final long length) throws IOException {
5959
final long skip = super.skip(length);
6060
this.count += skip;
6161
return skip;
@@ -68,7 +68,7 @@ public long skip(final long length) throws IOException {
6868
* @since Commons IO 2.0
6969
*/
7070
@Override
71-
protected void afterRead(int n) {
71+
protected synchronized void afterRead(int n) {
7272
if (n != -1) {
7373
this.count += n;
7474
}
@@ -85,7 +85,7 @@ protected void afterRead(int n) {
8585
* @return the number of bytes accumulated
8686
* @throws ArithmeticException if the byte count is too large
8787
*/
88-
public synchronized int getCount() {
88+
public int getCount() {
8989
long result = getByteCount();
9090
if (result > Integer.MAX_VALUE) {
9191
throw new ArithmeticException("The byte count " + result + " is too large to be converted to an int");
@@ -103,7 +103,7 @@ public synchronized int getCount() {
103103
* @return the count previous to resetting
104104
* @throws ArithmeticException if the byte count is too large
105105
*/
106-
public synchronized int resetCount() {
106+
public int resetCount() {
107107
long result = resetByteCount();
108108
if (result > Integer.MAX_VALUE) {
109109
throw new ArithmeticException("The byte count " + result + " is too large to be converted to an int");

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public CountingOutputStream( OutputStream out ) {
5050
* @since Commons IO 2.0
5151
*/
5252
@Override
53-
protected void beforeWrite(int n) {
53+
protected synchronized void beforeWrite(int n) {
5454
count += n;
5555
}
5656

@@ -65,7 +65,7 @@ protected void beforeWrite(int n) {
6565
* @return the number of bytes accumulated
6666
* @throws ArithmeticException if the byte count is too large
6767
*/
68-
public synchronized int getCount() {
68+
public int getCount() {
6969
long result = getByteCount();
7070
if (result > Integer.MAX_VALUE) {
7171
throw new ArithmeticException("The byte count " + result + " is too large to be converted to an int");
@@ -83,7 +83,7 @@ public synchronized int getCount() {
8383
* @return the count previous to resetting
8484
* @throws ArithmeticException if the byte count is too large
8585
*/
86-
public synchronized int resetCount() {
86+
public int resetCount() {
8787
long result = resetByteCount();
8888
if (result > Integer.MAX_VALUE) {
8989
throw new ArithmeticException("The byte count " + result + " is too large to be converted to an int");

0 commit comments

Comments
 (0)