1 /* 2 * Copyright (C) 2015 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.ahat; 18 19 import com.google.common.io.ByteStreams; 20 import com.sun.net.httpserver.HttpExchange; 21 import com.sun.net.httpserver.HttpHandler; 22 import java.io.IOException; 23 import java.io.InputStream; 24 import java.io.PrintStream; 25 26 /** 27 * HelpHandler. 28 * 29 * HttpHandler to show the help page. 30 */ 31 class HelpHandler implements HttpHandler { 32 33 @Override handle(HttpExchange exchange)34 public void handle(HttpExchange exchange) throws IOException { 35 ClassLoader loader = HelpHandler.class.getClassLoader(); 36 exchange.getResponseHeaders().add("Content-Type", "text/html;charset=utf-8"); 37 exchange.sendResponseHeaders(200, 0); 38 PrintStream ps = new PrintStream(exchange.getResponseBody()); 39 HtmlDoc doc = new HtmlDoc(ps, DocString.text("ahat"), DocString.uri("style.css")); 40 doc.menu(Menu.getMenu()); 41 42 InputStream is = loader.getResourceAsStream("help.html"); 43 if (is == null) { 44 ps.println("No help available."); 45 } else { 46 ByteStreams.copy(is, ps); 47 } 48 49 doc.close(); 50 ps.close(); 51 } 52 } 53