@Override public void close() throws IOException { try { if (urlConnection != null) { int responseCode = urlConnection.getResponseCode(); if (responseCode != expectedResponseCode) { try { urlConnection.getInputStream().close(); throw new IOException( String.format( "Expected response code: %d. Got: %d", expectedResponseCode, responseCode)); } catch (IOException expected) { InputStream errorStream = urlConnection.getErrorStream(); if (errorStream != null) { String responseBody = FixJava.readReader(new InputStreamReader(errorStream, "UTF-8")); String contentType = urlConnection.getHeaderField("Content-Type"); if (contentType == null) { contentType = "text/plain"; } throw new ResponseException(responseBody, expected, responseCode, contentType); } else { throw expected; } } } } } finally { out.close(); } }
public String readFile(String path) throws FileNotFoundException, UnsupportedEncodingException { String source = FixJava.readReader(new InputStreamReader(new FileInputStream(path), DEFAULT_ENCODING)); String enc = encoding(source); if (!enc.equals(DEFAULT_ENCODING)) { source = FixJava.readReader(new InputStreamReader(new FileInputStream(path), enc)); } return source; }
private void parse(File file) { try { String input = FixJava.readReader(new FileReader(file)); lexer.scan(input, file.getPath(), 0); } catch (Exception e) { System.err.println(e.getMessage()); System.exit(1); } }