Code example for OutputStreamWriter

Methods: close, flush, write

0
	public void update(String metric, Object value) throws UnknownHostException, IOException {
		String line = generateLine(metric, value);
		Socket socket = new Socket(getHost(), getPort());
		 
		try { 
			Writer writer = new OutputStreamWriter(socket.getOutputStream());
			writer.write(line);
			writer.flush();
			writer.close();
		} finally { 
			socket.close();
		} 
	} 
	 
	public static String generateLine(String metric, Object value) {
		return String.format("stats.%s %s %s\n", metric, value, System.currentTimeMillis() / 1000);
	} 
	 
	public StatsPlugin getPlugin() { 
		return plugin;
	}