@@ -124,9 +124,7 @@ public Charset getCharset() {
124124 public Type type (final byte [] bytes ) {
125125 if (bytes == null ) throw new NullPointerException ("bytes cannot be null" );
126126
127- BencodeInputStream in = new BencodeInputStream (new ByteArrayInputStream (bytes ), charset , useBytes );
128-
129- try {
127+ try (BencodeInputStream in = new BencodeInputStream (new ByteArrayInputStream (bytes ), charset , useBytes )) {
130128 return in .nextType ();
131129 } catch (Throwable t ) {
132130 throw new BencodeException ("Exception thrown during type detection" , t );
@@ -152,9 +150,7 @@ public <T> T decode(final byte[] bytes, final Type<T> type) {
152150 if (type == null ) throw new NullPointerException ("type cannot be null" );
153151 if (type == Type .UNKNOWN ) throw new IllegalArgumentException ("type cannot be UNKNOWN" );
154152
155- BencodeInputStream in = new BencodeInputStream (new ByteArrayInputStream (bytes ), charset , useBytes );
156-
157- try {
153+ try (BencodeInputStream in = new BencodeInputStream (new ByteArrayInputStream (bytes ), charset , useBytes )) {
158154 if (type == Type .NUMBER )
159155 return (T ) in .readNumber ();
160156 if (type == Type .LIST )
@@ -243,9 +239,8 @@ public byte[] encode(final Map<?, ?> m) {
243239
244240 private byte [] encode (final Object o , final Type type ) {
245241 ByteArrayOutputStream out = new ByteArrayOutputStream ();
246- BencodeOutputStream bencode = new BencodeOutputStream (out , charset );
247242
248- try {
243+ try ( BencodeOutputStream bencode = new BencodeOutputStream ( out , charset )) {
249244 if (type == Type .STRING )
250245 bencode .writeString ((String ) o );
251246 else if (type == Type .NUMBER )
0 commit comments