mirror of
https://github.com/dmulloy2/ProtocolLib.git
synced 2024-11-24 03:25:29 +01:00
Temporarily restore Java 6 compatibility
3.6.5 will be the last ProtocolLib release supporting Java 6
This commit is contained in:
parent
125834205a
commit
5a5cd77bac
@ -16,6 +16,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.comphenix.protocol.utility;
|
package com.comphenix.protocol.utility;
|
||||||
|
|
||||||
|
import java.io.Closeable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -23,30 +24,31 @@ import java.util.List;
|
|||||||
* @author dmulloy2
|
* @author dmulloy2
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class Closer implements AutoCloseable {
|
// TODO Switch to AutoCloseable w/ Java 7
|
||||||
private final List<AutoCloseable> list;
|
public class Closer implements Closeable {
|
||||||
|
private final List<Closeable> list;
|
||||||
|
|
||||||
private Closer() {
|
private Closer() {
|
||||||
this.list = new ArrayList<AutoCloseable>();
|
this.list = new ArrayList<Closeable>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Closer create() {
|
public static Closer create() {
|
||||||
return new Closer();
|
return new Closer();
|
||||||
}
|
}
|
||||||
|
|
||||||
public <C extends AutoCloseable> C register(C close) {
|
public <C extends Closeable> C register(C close) {
|
||||||
list.add(close);
|
list.add(close);
|
||||||
return close;
|
return close;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() {
|
public void close() {
|
||||||
for (AutoCloseable close : list) {
|
for (Closeable close : list) {
|
||||||
closeQuietly(close);
|
closeQuietly(close);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void closeQuietly(AutoCloseable close) {
|
public static void closeQuietly(Closeable close) {
|
||||||
try {
|
try {
|
||||||
close.close();
|
close.close();
|
||||||
} catch (Throwable ex) { }
|
} catch (Throwable ex) { }
|
||||||
|
Loading…
Reference in New Issue
Block a user