-
-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
remove log4j-CloseShieldOutputStream usage
- Loading branch information
Showing
6 changed files
with
148 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
planetiler-core/src/main/java/com/onthegomap/planetiler/util/CloseShieldOutputStream.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.onthegomap.planetiler.util; | ||
|
||
import java.io.IOException; | ||
import java.io.OutputStream; | ||
|
||
/** | ||
* {@link OutputStream} decorator that suppresses {@link #close()}. | ||
*/ | ||
public class CloseShieldOutputStream extends DelegatingOutputStream { | ||
|
||
public CloseShieldOutputStream(OutputStream wrapped) { | ||
super(wrapped); | ||
} | ||
|
||
@Override | ||
public void close() throws IOException { | ||
// suppress closing | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
planetiler-core/src/main/java/com/onthegomap/planetiler/util/DelegatingOutputStream.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.onthegomap.planetiler.util; | ||
|
||
import java.io.IOException; | ||
import java.io.OutputStream; | ||
|
||
abstract class DelegatingOutputStream extends OutputStream { | ||
|
||
private final OutputStream delegate; | ||
|
||
protected DelegatingOutputStream(OutputStream wrapped) { | ||
this.delegate = wrapped; | ||
} | ||
|
||
@Override | ||
public void write(int i) throws IOException { | ||
delegate.write(i); | ||
} | ||
|
||
@Override | ||
public void write(byte[] b) throws IOException { | ||
delegate.write(b); | ||
} | ||
|
||
@Override | ||
public void write(byte[] b, int off, int len) throws IOException { | ||
delegate.write(b, off, len); | ||
} | ||
|
||
@Override | ||
public void flush() throws IOException { | ||
delegate.flush(); | ||
} | ||
|
||
@Override | ||
public void close() throws IOException { | ||
delegate.close(); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
...etiler-core/src/test/java/com/onthegomap/planetiler/util/CloseShieldOutputStreamTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.onthegomap.planetiler.util; | ||
|
||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.verifyNoMoreInteractions; | ||
|
||
import java.io.IOException; | ||
import java.io.OutputStream; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class CloseShieldOutputStreamTest { | ||
|
||
@Test | ||
void test() throws IOException { | ||
final OutputStream delegate = mock(OutputStream.class); | ||
final OutputStream os = new CloseShieldOutputStream(delegate); | ||
|
||
os.close(); | ||
verifyNoMoreInteractions(delegate); | ||
|
||
os.write(1); | ||
verify(delegate).write(1); | ||
verifyNoMoreInteractions(delegate); | ||
|
||
os.write(new byte[]{2}); | ||
verify(delegate).write(new byte[]{2}); | ||
verifyNoMoreInteractions(delegate); | ||
|
||
os.write(new byte[]{3}, 4, 5); | ||
verify(delegate).write(new byte[]{3}, 4, 5); | ||
verifyNoMoreInteractions(delegate); | ||
|
||
os.flush(); | ||
verify(delegate).flush(); | ||
verifyNoMoreInteractions(delegate); | ||
} | ||
|
||
} |
47 changes: 47 additions & 0 deletions
47
planetiler-core/src/test/java/com/onthegomap/planetiler/util/CountingOutputStreamTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.onthegomap.planetiler.util; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.verifyNoMoreInteractions; | ||
|
||
import com.onthegomap.planetiler.stats.Counter; | ||
import java.io.IOException; | ||
import java.io.OutputStream; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class CountingOutputStreamTest { | ||
|
||
@Test | ||
void test() throws IOException { | ||
|
||
final OutputStream delegate = mock(OutputStream.class); | ||
final var c = Counter.newSingleThreadCounter(); | ||
final OutputStream os = new CountingOutputStream(delegate, c::incBy); | ||
|
||
os.close(); | ||
verify(delegate).close(); | ||
assertEquals(0, c.get()); | ||
|
||
os.write(1); | ||
verify(delegate).write(1); | ||
verifyNoMoreInteractions(delegate); | ||
assertEquals(1L, c.get()); | ||
|
||
os.write(new byte[]{2, 3}); | ||
verify(delegate).write(new byte[]{2, 3}); | ||
verifyNoMoreInteractions(delegate); | ||
assertEquals(1L + 2L, c.get()); | ||
|
||
os.write(new byte[]{4, 5, 6}, 7, 8); | ||
verify(delegate).write(new byte[]{4, 5, 6}, 7, 8); | ||
verifyNoMoreInteractions(delegate); | ||
assertEquals(1L + 2L + 8L, c.get()); | ||
|
||
os.flush(); | ||
verify(delegate).flush(); | ||
verifyNoMoreInteractions(delegate); | ||
assertEquals(1L + 2L + 8L, c.get()); | ||
} | ||
|
||
} |