DB db = new DB();\r
@SuppressWarnings("resource")\r
Connection conn = db.getConnection();\r
- PreparedStatement ps = conn.prepareStatement(SELECT_SQL);\r
+ try(PreparedStatement ps = conn.prepareStatement(SELECT_SQL)){\r
ps.setLong(1, from);\r
ps.setLong(2, to);\r
- ResultSet rs = ps.executeQuery();\r
- PrintWriter os = new PrintWriter(outfile);\r
- os.println("recordid,feedid,uri,size,min,max,avg,fanout");\r
- Counters c = null;\r
- while (rs.next()) {\r
- long etime = rs.getLong("EVENT_TIME");\r
- String type = rs.getString("TYPE");\r
- String id = rs.getString("PUBLISH_ID");\r
- String fid = rs.getString("FEED_FILEID");\r
- int feed = rs.getInt("FEEDID");\r
- long clen = rs.getLong("CONTENT_LENGTH");\r
- if (c != null && !id.equals(c.id)) {\r
- String line = id + "," + c.toString();\r
- os.println(line);\r
- c = null;\r
+ try(ResultSet rs = ps.executeQuery()) {\r
+ try(PrintWriter os = new PrintWriter(outfile)) {\r
+ os.println("recordid,feedid,uri,size,min,max,avg,fanout");\r
+ Counters c = null;\r
+ while (rs.next()) {\r
+ long etime = rs.getLong("EVENT_TIME");\r
+ String type = rs.getString("TYPE");\r
+ String id = rs.getString("PUBLISH_ID");\r
+ String fid = rs.getString("FEED_FILEID");\r
+ int feed = rs.getInt("FEEDID");\r
+ long clen = rs.getLong("CONTENT_LENGTH");\r
+ if (c != null && !id.equals(c.id)) {\r
+ String line = id + "," + c.toString();\r
+ os.println(line);\r
+ c = null;\r
+ }\r
+ if (c == null) {\r
+ c = new Counters(id, feed, clen, fid);\r
+ }\r
+ if (feed != c.feedid)\r
+ System.err.println("Feed ID mismatch, " + feed + " <=> " + c.feedid);\r
+ if (clen != c.clen)\r
+ System.err.println("Cont Len mismatch, " + clen + " <=> " + c.clen);\r
+ c.addEvent(type, etime);\r
+ }\r
}\r
- if (c == null) {\r
- c = new Counters(id, feed, clen, fid);\r
- }\r
- if (feed != c.feedid)\r
- System.err.println("Feed ID mismatch, " + feed + " <=> " + c.feedid);\r
- if (clen != c.clen)\r
- System.err.println("Cont Len mismatch, " + clen + " <=> " + c.clen);\r
-// if (fid != c.fileid)\r
-// System.err.println("File ID mismatch, "+fid+" <=> "+c.fileid);\r
- c.addEvent(type, etime);\r
+ db.release(conn);\r
+ }\r
}\r
- rs.close();\r
- ps.close();\r
- db.release(conn);\r
- os.close();\r
} catch (FileNotFoundException e) {\r
System.err.println("File cannot be written: " + outfile);\r
} catch (SQLException e) {\r