public void sendBatch(Track track, HttpSaver.Cache cache) throws Exception { if (cache.getSize() > 0) { if (authenticated()) { if (!track.isTrackIDSet()) { // this is a new track startTrack(track); // throws SaveException if failed } // Assemble JSON: StringBuffer jsonBff = new StringBuffer(); // First the measurements: jsonBff.append("{measures:["); Enumeration mEnum = cache.getMeasurements().elements(); while (mEnum.hasMoreElements()) { jsonBff.append(((NTMeasurement) mEnum.nextElement()).toJSON()); if (mEnum.hasMoreElements()) jsonBff.append(","); } jsonBff.append("],"); // Then the tagged intervals: jsonBff.append("taggedIntervals:["); Enumeration tiEnum = cache.getTaggedIntervals().elements(); while (tiEnum.hasMoreElements()) { jsonBff.append(((TaggedInterval) tiEnum.nextElement()).toJSON()); if (tiEnum.hasMoreElements()) jsonBff.append(","); } jsonBff.append("]}"); // send the JSON: log.debug( "Sending a batch of " + cache.getSize() + " measurements and tagged intervals of track " + track.getTrackID()); try { httpClient.postJSONRequest( apiBaseURL + "upload?key=" + account.getAPIKey() + "&track=" + track.getTrackID(), jsonBff.toString()); } catch (Exception e) { // log.debug("Could not send batch: " + e.getMessage()); throw e; } cache.clear(); // only if sending was successful } else throw new Exception("Not logged in"); } }