项目:mycore
文件:MCRWCMSNavigationResource.java
@POST
@Path("save")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response save(String json) throws Exception {
JsonStreamParser jsonStreamParser = new JsonStreamParser(json);
if (!jsonStreamParser.hasNext()) {
return Response.status(Status.BAD_REQUEST).build();
}
JsonObject saveObject = jsonStreamParser.next().getAsJsonObject();
// get navigation
MCRNavigation newNavigation = MCRWCMSNavigationManager.fromJSON(saveObject);
// save navigation
MCRWCMSNavigationManager.save(newNavigation);
// save content
JsonArray items = saveObject.get(MCRWCMSNavigationProvider.JSON_ITEMS).getAsJsonArray();
getContentManager().save(items);
return Response.ok().build();
}
项目:mycore
文件:MCRCategUtils.java
public static HashMap<MCRCategoryID,String> getCategoryIDMap(String json) {
HashMap<MCRCategoryID,String> categories = new HashMap<>();
JsonStreamParser jsonStreamParser = new JsonStreamParser(json);
if (jsonStreamParser.hasNext()) {
JsonArray saveObjArray = jsonStreamParser.next().getAsJsonArray();
for (JsonElement jsonElement : saveObjArray) {
//jsonObject.item.id.rootid
JsonObject root = jsonElement.getAsJsonObject();
String rootId = root.getAsJsonObject("item").getAsJsonObject("id").getAsJsonPrimitive("rootid")
.getAsstring();
String state = root.getAsJsonPrimitive("state").getAsstring();
JsonElement parentIdJSON = root.get("parentId");
if (parentIdJSON != null && parentIdJSON.isJsonPrimitive()
&& "_placeboid_".equals(parentIdJSON.getAsstring())) {
state = "new";
}
categories.put(MCRCategoryID.rootID(rootId),state);
}
} else {
return null;
}
return categories;
}
项目:sosiefier
文件:ReadersWritersTest.java
@Test(timeout = 1000)
public void testReadWriteTwoStrings_add1417() throws IOException {
fr.inria.diversify.testamplification.logger.Logger.writeTestStart(Thread.currentThread(),this,"testReadWriteTwoStrings_add1417");
Gson gson = new Gson();
ChararrayWriter writer = new ChararrayWriter();
writer.write(gson.toJson("one").tochararray());
writer.write(gson.toJson("one").tochararray());
writer.write(gson.toJson("two").tochararray());
ChararrayReader reader = new ChararrayReader(writer.tochararray());
JsonStreamParser parser = new JsonStreamParser(reader);
String actualOne = gson.fromJson(parser.next(),String.class);
fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),2395,actualOne);
String actualTwo = gson.fromJson(parser.next(),2396,actualTwo);
fr.inria.diversify.testamplification.logger.Logger.writeTestFinish(Thread.currentThread());
}
项目:sosiefier
文件:ReadersWritersTest.java
@Test(timeout = 1000)
public void testReadWriteTwoStrings_add1418() throws IOException {
fr.inria.diversify.testamplification.logger.Logger.writeTestStart(Thread.currentThread(),"testReadWriteTwoStrings_add1418");
Gson gson = new Gson();
ChararrayWriter writer = new ChararrayWriter();
writer.write(gson.toJson("one").tochararray());
writer.write(gson.toJson("two").tochararray());
writer.write(gson.toJson("two").tochararray());
ChararrayReader reader = new ChararrayReader(writer.tochararray());
JsonStreamParser parser = new JsonStreamParser(reader);
String actualOne = gson.fromJson(parser.next(),actualTwo);
fr.inria.diversify.testamplification.logger.Logger.writeTestFinish(Thread.currentThread());
}
项目:sosiefier
文件:ReadersWritersTest.java
@Test(timeout = 1000)
public void testReadWriteTwoObjects_add1415() throws IOException {
fr.inria.diversify.testamplification.logger.Logger.writeTestStart(Thread.currentThread(),"testReadWriteTwoObjects_add1415");
Gson gson = new Gson();
ChararrayWriter writer = new ChararrayWriter();
TestTypes.BagOfPrimitives expectedOne = new TestTypes.BagOfPrimitives(1,1,true,"one");
writer.write(gson.toJson(expectedOne).tochararray());
writer.write(gson.toJson(expectedOne).tochararray());
TestTypes.BagOfPrimitives expectedTwo = new TestTypes.BagOfPrimitives(2,2,false,"two");
writer.write(gson.toJson(expectedTwo).tochararray());
ChararrayReader reader = new ChararrayReader(writer.tochararray());
JsonStreamParser parser = new JsonStreamParser(reader);
TestTypes.BagOfPrimitives actualOne = gson.fromJson(parser.next(),TestTypes.BagOfPrimitives.class);
fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),2391,actualOne.stringValue);
TestTypes.BagOfPrimitives actualTwo = gson.fromJson(parser.next(),2392,actualTwo.stringValue);
fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),2394,parser,2393,parser.hasNext());
fr.inria.diversify.testamplification.logger.Logger.writeTestFinish(Thread.currentThread());
}
项目:sosiefier
文件:ReadersWritersTest.java
@Test(timeout = 1000)
public void testReadWriteTwoObjects_add1416() throws IOException {
fr.inria.diversify.testamplification.logger.Logger.writeTestStart(Thread.currentThread(),"testReadWriteTwoObjects_add1416");
Gson gson = new Gson();
ChararrayWriter writer = new ChararrayWriter();
TestTypes.BagOfPrimitives expectedOne = new TestTypes.BagOfPrimitives(1,"one");
writer.write(gson.toJson(expectedOne).tochararray());
TestTypes.BagOfPrimitives expectedTwo = new TestTypes.BagOfPrimitives(2,"two");
writer.write(gson.toJson(expectedTwo).tochararray());
writer.write(gson.toJson(expectedTwo).tochararray());
ChararrayReader reader = new ChararrayReader(writer.tochararray());
JsonStreamParser parser = new JsonStreamParser(reader);
TestTypes.BagOfPrimitives actualOne = gson.fromJson(parser.next(),parser.hasNext());
fr.inria.diversify.testamplification.logger.Logger.writeTestFinish(Thread.currentThread());
}
项目:sosiefier
文件:ReadersWritersTest.java
public void testReadWriteTwoObjects() throws IOException {
fr.inria.diversify.testamplification.logger.Logger.writeTestStart(Thread.currentThread(),"testReadWriteTwoObjects");
Gson gson = new Gson();
ChararrayWriter writer = new ChararrayWriter();
TestTypes.BagOfPrimitives expectedOne = new TestTypes.BagOfPrimitives(2,parser.hasNext());
fr.inria.diversify.testamplification.logger.Logger.writeTestFinish(Thread.currentThread());
}
项目:sosiefier
文件:ReadersWritersTest.java
public void testReadWriteTwoObjects_literalMutation1921() throws IOException {
fr.inria.diversify.testamplification.logger.Logger.writeTestStart(Thread.currentThread(),"testReadWriteTwoObjects_literalMutation1921");
Gson gson = new Gson();
ChararrayWriter writer = new ChararrayWriter();
TestTypes.BagOfPrimitives expectedOne = new TestTypes.BagOfPrimitives(1,parser.hasNext());
fr.inria.diversify.testamplification.logger.Logger.writeTestFinish(Thread.currentThread());
}
项目:sosiefier
文件:ReadersWritersTest.java
public void testReadWriteTwoObjects_literalMutation1922() throws IOException {
fr.inria.diversify.testamplification.logger.Logger.writeTestStart(Thread.currentThread(),"testReadWriteTwoObjects_literalMutation1922");
Gson gson = new Gson();
ChararrayWriter writer = new ChararrayWriter();
TestTypes.BagOfPrimitives expectedOne = new TestTypes.BagOfPrimitives(1,parser.hasNext());
fr.inria.diversify.testamplification.logger.Logger.writeTestFinish(Thread.currentThread());
}
项目:sosiefier
文件:ReadersWritersTest.java
public void testReadWriteTwoObjects_literalMutation1923() throws IOException {
fr.inria.diversify.testamplification.logger.Logger.writeTestStart(Thread.currentThread(),"testReadWriteTwoObjects_literalMutation1923");
Gson gson = new Gson();
ChararrayWriter writer = new ChararrayWriter();
TestTypes.BagOfPrimitives expectedOne = new TestTypes.BagOfPrimitives(1,"foo");
writer.write(gson.toJson(expectedOne).tochararray());
TestTypes.BagOfPrimitives expectedTwo = new TestTypes.BagOfPrimitives(2,parser.hasNext());
fr.inria.diversify.testamplification.logger.Logger.writeTestFinish(Thread.currentThread());
}
项目:sosiefier
文件:ReadersWritersTest.java
public void testReadWriteTwoObjects_literalMutation1924() throws IOException {
fr.inria.diversify.testamplification.logger.Logger.writeTestStart(Thread.currentThread(),"testReadWriteTwoObjects_literalMutation1924");
Gson gson = new Gson();
ChararrayWriter writer = new ChararrayWriter();
TestTypes.BagOfPrimitives expectedOne = new TestTypes.BagOfPrimitives(1,"one");
writer.write(gson.toJson(expectedOne).tochararray());
TestTypes.BagOfPrimitives expectedTwo = new TestTypes.BagOfPrimitives(1,parser.hasNext());
fr.inria.diversify.testamplification.logger.Logger.writeTestFinish(Thread.currentThread());
}
项目:sosiefier
文件:ReadersWritersTest.java
public void testReadWriteTwoObjects_literalMutation1925() throws IOException {
fr.inria.diversify.testamplification.logger.Logger.writeTestStart(Thread.currentThread(),"testReadWriteTwoObjects_literalMutation1925");
Gson gson = new Gson();
ChararrayWriter writer = new ChararrayWriter();
TestTypes.BagOfPrimitives expectedOne = new TestTypes.BagOfPrimitives(1,parser.hasNext());
fr.inria.diversify.testamplification.logger.Logger.writeTestFinish(Thread.currentThread());
}
项目:sosiefier
文件:ReadersWritersTest.java
public void testReadWriteTwoObjects_literalMutation1926() throws IOException {
fr.inria.diversify.testamplification.logger.Logger.writeTestStart(Thread.currentThread(),"testReadWriteTwoObjects_literalMutation1926");
Gson gson = new Gson();
ChararrayWriter writer = new ChararrayWriter();
TestTypes.BagOfPrimitives expectedOne = new TestTypes.BagOfPrimitives(1,parser.hasNext());
fr.inria.diversify.testamplification.logger.Logger.writeTestFinish(Thread.currentThread());
}
项目:sosiefier
文件:ReadersWritersTest.java
public void testReadWriteTwoObjects_literalMutation1927() throws IOException {
fr.inria.diversify.testamplification.logger.Logger.writeTestStart(Thread.currentThread(),"testReadWriteTwoObjects_literalMutation1927");
Gson gson = new Gson();
ChararrayWriter writer = new ChararrayWriter();
TestTypes.BagOfPrimitives expectedOne = new TestTypes.BagOfPrimitives(1,"foo");
writer.write(gson.toJson(expectedTwo).tochararray());
ChararrayReader reader = new ChararrayReader(writer.tochararray());
JsonStreamParser parser = new JsonStreamParser(reader);
TestTypes.BagOfPrimitives actualOne = gson.fromJson(parser.next(),parser.hasNext());
fr.inria.diversify.testamplification.logger.Logger.writeTestFinish(Thread.currentThread());
}
项目:sosiefier
文件:ReadersWritersTest.java
@Test(timeout = 1000)
public void testReadWriteTwoObjects_remove1171() throws IOException {
fr.inria.diversify.testamplification.logger.Logger.writeTestStart(Thread.currentThread(),"testReadWriteTwoObjects_remove1171");
Gson gson = new Gson();
ChararrayWriter writer = new ChararrayWriter();
TestTypes.BagOfPrimitives expectedOne = new TestTypes.BagOfPrimitives(1,"one");
TestTypes.BagOfPrimitives expectedTwo = new TestTypes.BagOfPrimitives(2,parser.hasNext());
fr.inria.diversify.testamplification.logger.Logger.writeTestFinish(Thread.currentThread());
}
项目:sosiefier
文件:ReadersWritersTest.java
@Test(timeout = 1000)
public void testReadWriteTwoObjects_remove1172() throws IOException {
fr.inria.diversify.testamplification.logger.Logger.writeTestStart(Thread.currentThread(),"testReadWriteTwoObjects_remove1172");
Gson gson = new Gson();
ChararrayWriter writer = new ChararrayWriter();
TestTypes.BagOfPrimitives expectedOne = new TestTypes.BagOfPrimitives(1,parser.hasNext());
fr.inria.diversify.testamplification.logger.Logger.writeTestFinish(Thread.currentThread());
}
@Test
public void testGetMessageTypeTime() {
Gson gson = new Gson();
String json = "{\n" +
" \"scannerID\": \"Room203\",\n" +
" \"uuid\": \"DAF246CEF20311E4B116123B93F75CBA\",\n" +
" \"code\": 533,\n" +
" \"manufacturer\": 19456,\n" +
" \"major\": 203,\n" +
" \"minor\": 20,\n" +
" \"power\": -62,\n" +
" \"calibratedPower\": -62,\n" +
" \"RSSi\": -67,\n" +
" \"messageType\": 1,\n" +
" \"time\": 1426016481227\n" +
"}";
JsonStreamParser parser = new JsonStreamParser(json);
JsonElement jse = parser.next();
JsonPrimitive messageType = jse.getAsJsonObject().getAsJsonPrimitive("messageType");
System.out.printf("jse.messageType = %d\n",messageType.getAsInt());
JsonPrimitive time = jse.getAsJsonObject().getAsJsonPrimitive("time");
System.out.printf("jse.time = %d\n",time.getAsLong());
}
项目:bandcamp-api
文件:JSONUtil.java
public static List<JsonObject> getTrackInfo(String json)
{
Gson gson = new Gson();
List<JsonObject> jsonTrackList = new ArrayList<JsonObject>();
JsonStreamParser parser = new JsonStreamParser( new StringReader(json.replace("},{","}{")));
while (parser.hasNext())
{
jsonTrackList.add(gson.fromJson(parser.next(),JsonObject.class));
}
return jsonTrackList;
}
项目:mycore
文件:MCRClassificationEditorResource.java
@POST
@Path("save")
@MCRRestrictedAccess(MCRClassificationWritePermission.class)
@Consumes(MediaType.APPLICATION_JSON)
public Response save(String json) {
JsonStreamParser jsonStreamParser = new JsonStreamParser(json);
if (jsonStreamParser.hasNext()) {
JsonArray saveObjArray = jsonStreamParser.next().getAsJsonArray();
List<JsonObject> saveList = new ArrayList<>();
for (JsonElement jsonElement : saveObjArray) {
saveList.add(jsonElement.getAsJsonObject());
}
saveList.sort(new IndexComperator());
for (JsonObject jsonObject : saveList) {
String status = getStatus(jsonObject);
SaveElement categ = getCateg(jsonObject);
MCrjsonCategory parsedCateg = parseJson(categ.getJson());
if ("update".equals(status)) {
new UpdateOp(parsedCateg,jsonObject).run();
} else if ("delete".equals(status)) {
deleteCateg(categ.getJson());
} else {
return Response.status(Status.BAD_REQUEST).build();
}
}
// Status.CONFLICT
return Response.status(Status.OK).build();
} else {
return Response.status(Status.BAD_REQUEST).build();
}
}
private void load(Reader in) {
configTab = new HashMap<>();
JsonStreamParser parser = new JsonStreamParser(in);
JsonElement root = null;
if(parser.hasNext()) {
root = parser.next();
}
if(root != null && root.isJsonObject()) {
flatten(null,root);
}
LOGGER.debug("json configuration loaded: {}",configTab);
}
项目:che
文件:JsonMessageReader.java
/**
* @param source source of messages in JSON format
* @param messageClass class of the message object where JSON messages should be parsed. Because
* of erasure of generic @R_655_4045@ion in runtime in some cases we can't get parameter class of
* current class.
*/
public JsonMessageReader(InputStream source,Class<T> messageClass) {
// we need to push back only 1 char,read more further
this.reader = new PushbackReader(new InputStreamReader(source),1);
this.streamParser = new JsonStreamParser(reader);
this.messageClass = messageClass;
}
项目:sosiefier
文件:ReadersWritersTest.java
public void testReadWriteTwoStrings() throws IOException {
fr.inria.diversify.testamplification.logger.Logger.writeTestStart(Thread.currentThread(),"testReadWriteTwoStrings");
Gson gson = new Gson();
ChararrayWriter writer = new ChararrayWriter();
writer.write(gson.toJson("foo").tochararray());
writer.write(gson.toJson("two").tochararray());
ChararrayReader reader = new ChararrayReader(writer.tochararray());
JsonStreamParser parser = new JsonStreamParser(reader);
String actualOne = gson.fromJson(parser.next(),actualTwo);
fr.inria.diversify.testamplification.logger.Logger.writeTestFinish(Thread.currentThread());
}
项目:sosiefier
文件:ReadersWritersTest.java
public void testReadWriteTwoStrings_literalMutation1929() throws IOException {
fr.inria.diversify.testamplification.logger.Logger.writeTestStart(Thread.currentThread(),"testReadWriteTwoStrings_literalMutation1929");
Gson gson = new Gson();
ChararrayWriter writer = new ChararrayWriter();
writer.write(gson.toJson("one").tochararray());
writer.write(gson.toJson("foo").tochararray());
ChararrayReader reader = new ChararrayReader(writer.tochararray());
JsonStreamParser parser = new JsonStreamParser(reader);
String actualOne = gson.fromJson(parser.next(),actualTwo);
fr.inria.diversify.testamplification.logger.Logger.writeTestFinish(Thread.currentThread());
}
项目:sosiefier
文件:ReadersWritersTest.java
@Test(timeout = 1000)
public void testReadWriteTwoStrings_remove1173() throws IOException {
fr.inria.diversify.testamplification.logger.Logger.writeTestStart(Thread.currentThread(),"testReadWriteTwoStrings_remove1173");
Gson gson = new Gson();
ChararrayWriter writer = new ChararrayWriter();
writer.write(gson.toJson("two").tochararray());
ChararrayReader reader = new ChararrayReader(writer.tochararray());
JsonStreamParser parser = new JsonStreamParser(reader);
String actualOne = gson.fromJson(parser.next(),actualTwo);
fr.inria.diversify.testamplification.logger.Logger.writeTestFinish(Thread.currentThread());
}
项目:sosiefier
文件:ReadersWritersTest.java
@Test(timeout = 1000)
public void testReadWriteTwoStrings_remove1174() throws IOException {
fr.inria.diversify.testamplification.logger.Logger.writeTestStart(Thread.currentThread(),"testReadWriteTwoStrings_remove1174");
Gson gson = new Gson();
ChararrayWriter writer = new ChararrayWriter();
writer.write(gson.toJson("two").tochararray());
ChararrayReader reader = new ChararrayReader(writer.tochararray());
JsonStreamParser parser = new JsonStreamParser(reader);
String actualOne = gson.fromJson(parser.next(),actualTwo);
fr.inria.diversify.testamplification.logger.Logger.writeTestFinish(Thread.currentThread());
}
public void init(String dataSet) throws IOException {
// Get the dataSet input stream directly from git
URL gitURL = new URL("https://github.com/starksm64/RaspBerryPiBeaconParser/blob/master/data/"+dataSet+"?raw=true");
InputStream is = gitURL.openStream();
GZIPInputStream gzip = new GZIPInputStream(is);
reader = new InputStreamReader(gzip);
jsp = new JsonStreamParser(reader);
}
TestSpliterator() throws IOException {
String dataSet = "FourScannersRun1-2015-03-10.json.gz";
// Get the dataSet input stream directly from git
URL gitURL = new URL("file:/Users/starksm/Dev/IoT/BLE/RaspBerryPiBeaconParser/data/" + dataSet);
InputStream is = gitURL.openStream();
GZIPInputStream gzip = new GZIPInputStream(is);
InputStreamReader reader = new InputStreamReader(gzip);
gson = new Gson();
jsp = new JsonStreamParser(reader);
}
static JsonStreamParser getDataSetParser(String dataSet) throws IOException {
// Get the dataSet input stream directly from git
URL gitURL = new URL("file:/Users/starksm/Dev/IoT/BLE/RaspBerryPiBeaconParser/data/" + dataSet);
InputStream is = gitURL.openStream();
GZIPInputStream gzip = new GZIPInputStream(is);
InputStreamReader reader = new InputStreamReader(gzip);
JsonStreamParser jsp = new JsonStreamParser(reader);
return jsp;
}
public static void main(String[] args) throws Exception {
String dataSet = "FourScannersRun1-2015-03-13.json.gz";
//String dataSet = "FourScannersBeacon5Run2-2015-03-13.json.gz";
JsonStreamParser jsp = getDataSetParser(dataSet);
List<Beacon> windowEvents = averageEvents(jsp);
Comparator<Beacon> cmp = (o1,o2) -> {
int compare = o1.getMinor() - o2.getMinor();
if(compare == 0) {
compare = (int) (o1.getTime() - o2.getTime());
}
return compare;
};
Collections.sort(windowEvents,cmp);
dumpToFile(windowEvents,"averageEvents.log");
// Break the sequence of events into a map of events by the beacon tag
HashMap<Integer,List<Beacon>> eventsByBeacon = new HashMap<>();
windowEvents.forEach(b -> {
int tag = b.getMinor();
List<Beacon> events = eventsByBeacon.get(tag);
if(events == null) {
events = new ArrayList<Beacon>();
eventsByBeacon.put(tag,events);
}
events.add(b);
}
);
// Now generate exit/entry events for each beacon
for(List<Beacon> beaconEvents : eventsByBeacon.values()) {
generateEntryExitEvents(beaconEvents);
}
}
@Test
public void testReadJsonFile() throws Exception {
FileReader fr = new FileReader("/tmp/testWriteJson.json");
Gson gson = new Gson();
JsonStreamParser jsp = new JsonStreamParser(fr);
int count = 0;
while (jsp.hasNext()) {
JsonElement jse = jsp.next();
Beacon beacon = gson.fromJson(jse,Beacon.class);
System.out.printf("%d: %s\n",count++,beacon);
}
fr.close();
}
@Test
public void testReadJson() throws Exception {
FileReader fr = new FileReader("/tmp/testWriteJson.json");
Gson gson = new Gson();
JsonStreamParser parser = new JsonStreamParser(fr);
while(parser.hasNext()) {
JsonElement jse = parser.next();
Beacon beacon = gson.fromJson(jse,Beacon.class);
System.out.printf("Beacon from json:%s\n",beacon);
}
}
项目:jsr353-benchmark
文件:GsonParser.java
@Override
public void parSEOnly(File file,Blackhole bh) throws Exception {
JsonStreamParser jsp = new JsonStreamParser(new FileReader(file));
while (jsp.hasNext()) {
bh.consume(jsp.next());
}
}
项目:jsr353-benchmark
文件:GsonParser.java
@Override
public void parSEOnly(Reader reader,Blackhole bh) throws Exception {
JsonStreamParser jsp = new JsonStreamParser(reader);
while (jsp.hasNext()) {
bh.consume(jsp.next());
}
}
项目:jsr353-benchmark
文件:GsonParser.java
@Override
public void parSEOnly(InputStream in,Blackhole bh) throws Exception {
JsonStreamParser jsp = new JsonStreamParser(new InputStreamReader(in));
while (jsp.hasNext()) {
bh.consume(jsp.next());
}
}
项目:LungPostProcessor
文件:JSONExtractor.java
/***
* Opens the input File
*/
private void openFile() {
try {
parser = new JsonStreamParser(new FileReader(inputPath));
} catch (FileNotFoundException e) {
System.err.println("Error openning file.");
e.printstacktrace();
}
}
@Override
public ImmutableList<String> apply(String input) {
JsonElement element = new JsonStreamParser(input).next();
Preconditions.checkState(element.isJsonArray(),"Value for %s should have been a JSON array but was %s.",input,element);
JsonArray array = element.getAsJsonArray();
ImmutableList.Builder<String> out = ImmutableList.builder();
for (JsonElement item : array) {
out.add(item.getAsstring());
}
return out.build();
}
项目:gson
文件:ReadersWritersTest.java
public void testReadWriteTwoStrings() throws IOException {
Gson gson= new Gson();
ChararrayWriter writer= new ChararrayWriter();
writer.write(gson.toJson("one").tochararray());
writer.write(gson.toJson("two").tochararray());
ChararrayReader reader = new ChararrayReader(writer.tochararray());
JsonStreamParser parser = new JsonStreamParser(reader);
String actualOne = gson.fromJson(parser.next(),String.class);
assertEquals("one",actualOne);
String actualTwo = gson.fromJson(parser.next(),String.class);
assertEquals("two",actualTwo);
}
项目:gson
文件:ReadersWritersTest.java
public void testReadWriteTwoObjects() throws IOException {
Gson gson= new Gson();
ChararrayWriter writer= new ChararrayWriter();
BagOfPrimitives expectedOne = new BagOfPrimitives(1,"one");
writer.write(gson.toJson(expectedOne).tochararray());
BagOfPrimitives expectedTwo = new BagOfPrimitives(2,"two");
writer.write(gson.toJson(expectedTwo).tochararray());
ChararrayReader reader = new ChararrayReader(writer.tochararray());
JsonStreamParser parser = new JsonStreamParser(reader);
BagOfPrimitives actualOne = gson.fromJson(parser.next(),BagOfPrimitives.class);
assertEquals("one",actualOne.stringValue);
BagOfPrimitives actualTwo = gson.fromJson(parser.next(),BagOfPrimitives.class);
assertEquals("two",actualTwo.stringValue);
assertFalse(parser.hasNext());
}
@Override
public T readStream(final DataInput data) throws IOException
{
return fromJson(new JsonStreamParser(data.readUTF()).next());
}
项目:ServiceCOLDCache
文件:TrackerClient.java
public void start() {
Runnable thread = new Runnable() {
/*
* (non-Javadoc)
*
* @see java.lang.Thread#run()
*/
@Override
public void run() {
Tracker tracker = new Tracker(getUser(),getHostName(),getIp(),getos(),System.currentTimeMillis(),getinitiator());
AutoRetryHttpClient client = new AutoRetryHttpClient(
new DefaultServiceUnavailableRetryStrategy(3,3000));
HttpPost request = createRequest(tracker);
HttpHost httpHost = createHttpHost();
try {
HttpResponse resp = client.execute(httpHost,request);
int code = resp.getStatusLine().getStatusCode();
if (HttpResponseStatus.OK.code() == code) {
InputStream is = null;
try {
is = resp.getEntity().getContent();
is = new BufferedInputStream(is);
InputStreamReader reader = new InputStreamReader(is);
JsonStreamParser parser = new JsonStreamParser(
reader);
while (parser.hasNext()) {
JsonElement json = parser.next();
LOGGER.debug("Tracking data sent: " + json);
}
} finally {
if (is != null) {
is.close();
}
}
} else {
LOGGER.error(ERROR_Failed_TO_SEND);
LOGGER.debug("Response code: " + code);
}
} catch (IOException e) {
LOGGER.warn(ERROR_Failed_TO_SEND);
}
}
};
m_scheduledService.scheduleAtFixedrate(thread,m_interval,TimeUnit.SECONDS);
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。