001package daikon.tools.runtimechecker; 002 003import static java.nio.charset.StandardCharsets.UTF_8; 004 005import java.io.BufferedReader; 006import java.io.IOException; 007import java.io.InputStream; 008import java.io.InputStreamReader; 009import java.io.UncheckedIOException; 010 011/** 012 * A command handler handles a set of commands. A command is the first argument given to the 013 * instrumenter. 014 */ 015public class CommandHandler { 016 017 public boolean handles(String command) { 018 throw new UnsupportedOperationException(); 019 } 020 021 public boolean handle(String[] args) { 022 throw new UnsupportedOperationException(); 023 } 024 025 public void usageMessage() { 026 String[] classnameArray = getClass().getName().split("\\."); 027 String simpleClassname = classnameArray[classnameArray.length - 1]; 028 029 String docFile = simpleClassname + ".doc"; 030 InputStream in = getClass().getResourceAsStream(docFile); 031 if (in == null) { 032 System.err.println("Didn't find documentation for " + getClass()); 033 return; 034 } 035 BufferedReader reader = new BufferedReader(new InputStreamReader(in, UTF_8)); 036 try { 037 String line; 038 while ((line = reader.readLine()) != null) { 039 System.err.println(line); 040 } 041 } catch (IOException e) { 042 try { 043 reader.close(); 044 } catch (IOException e2) { 045 // ignore second exception 046 } 047 throw new Error(e); 048 } 049 try { 050 reader.close(); 051 } catch (IOException e) { 052 throw new UncheckedIOException("problem closing " + docFile, e); 053 } 054 } 055}