public void store(String cacheEntryName, InputStream inputStream, long expirationDate) { try { PreparedStatement stmt = connection.prepareStatement( "INSERT INTO " + tableName + " (id, expiration_date, response) VALUES(?, ?, ?)"); stmt.setString(1, cacheEntryName); stmt.setTimestamp(2, new Timestamp(expirationDate)); stmt.setCharacterStream(3, new InputStreamReader(inputStream, "UTF-8"), -1); stmt.execute(); stmt.close(); } catch (SQLException e) { e.printStackTrace(); // ignore } catch (UnsupportedEncodingException e) { e.printStackTrace(); // won't happen } }
public static Pair<String, List<String>> decodeKeyValues(String str) { int index = str.indexOf("="); if (index == -1) { return null; } String k = str.substring(0, index); LinkedList<String> vlist = new LinkedList<String>(); try { String vstr = URLDecoder.decode(str.substring(index + 1, str.length()), "UTF-8"); String[] array = vstr.split(","); for (int i = 0; i < array.length; i++) { vlist.addLast(array[i]); } return new Pair<String, List<String>>(k, vlist); } catch (UnsupportedEncodingException e) { System.err.println("BAD STRING " + str); e.printStackTrace(); return null; } catch (Exception e) { System.err.println("BAD STRING " + str); return null; } }