1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/mobile/android/thirdparty/ch/boye/httpclientandroidlib/impl/conn/Wire.java Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,161 @@ 1.4 +/* 1.5 + * ==================================================================== 1.6 + * 1.7 + * Licensed to the Apache Software Foundation (ASF) under one or more 1.8 + * contributor license agreements. See the NOTICE file distributed with 1.9 + * this work for additional information regarding copyright ownership. 1.10 + * The ASF licenses this file to You under the Apache License, Version 2.0 1.11 + * (the "License"); you may not use this file except in compliance with 1.12 + * the License. You may obtain a copy of the License at 1.13 + * 1.14 + * http://www.apache.org/licenses/LICENSE-2.0 1.15 + * 1.16 + * Unless required by applicable law or agreed to in writing, software 1.17 + * distributed under the License is distributed on an "AS IS" BASIS, 1.18 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1.19 + * See the License for the specific language governing permissions and 1.20 + * limitations under the License. 1.21 + * ==================================================================== 1.22 + * 1.23 + * This software consists of voluntary contributions made by many 1.24 + * individuals on behalf of the Apache Software Foundation. For more 1.25 + * information on the Apache Software Foundation, please see 1.26 + * <http://www.apache.org/>. 1.27 + * 1.28 + */ 1.29 + 1.30 +package ch.boye.httpclientandroidlib.impl.conn; 1.31 + 1.32 +import java.io.IOException; 1.33 +import java.io.InputStream; 1.34 +import java.io.ByteArrayInputStream; 1.35 + 1.36 +import ch.boye.httpclientandroidlib.annotation.Immutable; 1.37 + 1.38 +import ch.boye.httpclientandroidlib.androidextra.HttpClientAndroidLog; 1.39 + 1.40 +/** 1.41 + * Logs data to the wire LOG. 1.42 + * 1.43 + * 1.44 + * @since 4.0 1.45 + */ 1.46 +@Immutable 1.47 +public class Wire { 1.48 + 1.49 + public HttpClientAndroidLog log; 1.50 + 1.51 + public Wire(HttpClientAndroidLog log) { 1.52 + this.log = log; 1.53 + } 1.54 + 1.55 + private void wire(String header, InputStream instream) 1.56 + throws IOException { 1.57 + StringBuilder buffer = new StringBuilder(); 1.58 + int ch; 1.59 + while ((ch = instream.read()) != -1) { 1.60 + if (ch == 13) { 1.61 + buffer.append("[\\r]"); 1.62 + } else if (ch == 10) { 1.63 + buffer.append("[\\n]\""); 1.64 + buffer.insert(0, "\""); 1.65 + buffer.insert(0, header); 1.66 + log.debug(buffer.toString()); 1.67 + buffer.setLength(0); 1.68 + } else if ((ch < 32) || (ch > 127)) { 1.69 + buffer.append("[0x"); 1.70 + buffer.append(Integer.toHexString(ch)); 1.71 + buffer.append("]"); 1.72 + } else { 1.73 + buffer.append((char) ch); 1.74 + } 1.75 + } 1.76 + if (buffer.length() > 0) { 1.77 + buffer.append('\"'); 1.78 + buffer.insert(0, '\"'); 1.79 + buffer.insert(0, header); 1.80 + log.debug(buffer.toString()); 1.81 + } 1.82 + } 1.83 + 1.84 + 1.85 + public boolean enabled() { 1.86 + return log.isDebugEnabled(); 1.87 + } 1.88 + 1.89 + public void output(InputStream outstream) 1.90 + throws IOException { 1.91 + if (outstream == null) { 1.92 + throw new IllegalArgumentException("Output may not be null"); 1.93 + } 1.94 + wire(">> ", outstream); 1.95 + } 1.96 + 1.97 + public void input(InputStream instream) 1.98 + throws IOException { 1.99 + if (instream == null) { 1.100 + throw new IllegalArgumentException("Input may not be null"); 1.101 + } 1.102 + wire("<< ", instream); 1.103 + } 1.104 + 1.105 + public void output(byte[] b, int off, int len) 1.106 + throws IOException { 1.107 + if (b == null) { 1.108 + throw new IllegalArgumentException("Output may not be null"); 1.109 + } 1.110 + wire(">> ", new ByteArrayInputStream(b, off, len)); 1.111 + } 1.112 + 1.113 + public void input(byte[] b, int off, int len) 1.114 + throws IOException { 1.115 + if (b == null) { 1.116 + throw new IllegalArgumentException("Input may not be null"); 1.117 + } 1.118 + wire("<< ", new ByteArrayInputStream(b, off, len)); 1.119 + } 1.120 + 1.121 + public void output(byte[] b) 1.122 + throws IOException { 1.123 + if (b == null) { 1.124 + throw new IllegalArgumentException("Output may not be null"); 1.125 + } 1.126 + wire(">> ", new ByteArrayInputStream(b)); 1.127 + } 1.128 + 1.129 + public void input(byte[] b) 1.130 + throws IOException { 1.131 + if (b == null) { 1.132 + throw new IllegalArgumentException("Input may not be null"); 1.133 + } 1.134 + wire("<< ", new ByteArrayInputStream(b)); 1.135 + } 1.136 + 1.137 + public void output(int b) 1.138 + throws IOException { 1.139 + output(new byte[] {(byte) b}); 1.140 + } 1.141 + 1.142 + public void input(int b) 1.143 + throws IOException { 1.144 + input(new byte[] {(byte) b}); 1.145 + } 1.146 + 1.147 + @Deprecated 1.148 + public void output(final String s) 1.149 + throws IOException { 1.150 + if (s == null) { 1.151 + throw new IllegalArgumentException("Output may not be null"); 1.152 + } 1.153 + output(s.getBytes()); 1.154 + } 1.155 + 1.156 + @Deprecated 1.157 + public void input(final String s) 1.158 + throws IOException { 1.159 + if (s == null) { 1.160 + throw new IllegalArgumentException("Input may not be null"); 1.161 + } 1.162 + input(s.getBytes()); 1.163 + } 1.164 +}