mirror of
https://github.com/stleary/JSON-java.git
synced 2025-08-03 11:25:30 -04:00
Merge pull request #733 from haribabu-dev/jsontokener_closable
JSONTokener implemented java.io.Closeable
This commit is contained in:
commit
fe22b242b5
@ -1,11 +1,6 @@
|
|||||||
package org.json;
|
package org.json;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.*;
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.io.Reader;
|
|
||||||
import java.io.StringReader;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Public Domain.
|
Public Domain.
|
||||||
@ -522,4 +517,10 @@ public class JSONTokener {
|
|||||||
return " at " + this.index + " [character " + this.character + " line " +
|
return " at " + this.index + " [character " + this.character + " line " +
|
||||||
this.line + "]";
|
this.line + "]";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void close() throws IOException {
|
||||||
|
if(reader!=null){
|
||||||
|
reader.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -313,4 +313,16 @@ public class JSONTokenerTest {
|
|||||||
assertEquals(0, t2.next());
|
assertEquals(0, t2.next());
|
||||||
assertFalse(t2.more());
|
assertFalse(t2.more());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAutoClose(){
|
||||||
|
Reader reader = new StringReader("some test string");
|
||||||
|
try {
|
||||||
|
JSONTokener tokener = new JSONTokener(reader);
|
||||||
|
tokener.close();
|
||||||
|
tokener.next();
|
||||||
|
} catch (Exception exception){
|
||||||
|
assertEquals("Stream closed", exception.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user