|
26 | 26 | import java.nio.channels.SocketChannel; |
27 | 27 | import java.nio.channels.spi.SelectorProvider; |
28 | 28 |
|
29 | | -import io.netty.buffer.ByteBufUtil; |
30 | 29 | import jnr.constants.platform.Errno; |
31 | 30 | import jnr.constants.platform.Shutdown; |
32 | 31 |
|
@@ -130,65 +129,63 @@ public SocketChannel shutdownOutput() throws IOException { |
130 | 129 |
|
131 | 130 | private static final int SHUT_RD = Shutdown.SHUT_RD.intValue(); |
132 | 131 | private static final int SHUT_WR = Shutdown.SHUT_WR.intValue(); |
133 | | - |
134 | | - public static String hexDump (ByteBuffer buf, String prefix) |
135 | | - { |
| 132 | + |
| 133 | + public static String hexDump(ByteBuffer buf, String prefix) { |
136 | 134 | buf = buf.duplicate(); |
137 | | - StringWriter str = new StringWriter (); |
138 | | - PrintWriter out = new PrintWriter (str); |
| 135 | + StringWriter str = new StringWriter(); |
| 136 | + PrintWriter out = new PrintWriter(str); |
139 | 137 | int i = 0; |
140 | 138 | int len = buf.remaining(); |
141 | 139 | byte[] line = new byte[16]; |
142 | | - while (i < len) |
143 | | - { |
144 | | - if (prefix != null) |
| 140 | + while (i < len) { |
| 141 | + if (prefix != null) { |
145 | 142 | out.print(prefix); |
146 | | - out.print(formatInt (i, 16, 8)); |
| 143 | + } |
| 144 | + out.print(formatInt(i, 16, 8)); |
147 | 145 | out.print(" "); |
148 | 146 | int l = Math.min(16, len - i); |
149 | 147 | buf.get(line, 0, l); |
150 | 148 | String s = toHexString(line, 0, l, ' '); |
151 | 149 | out.print(s); |
152 | | - for (int j = s.length(); j < 49; j++) |
| 150 | + for (int j = s.length(); j < 49; j++) { |
153 | 151 | out.print(' '); |
154 | | - for (int j = 0; j < l; j++) |
155 | | - { |
| 152 | + } |
| 153 | + for (int j = 0; j < l; j++) { |
156 | 154 | int c = line[j] & 0xFF; |
157 | | - if (c < 0x20 || c > 0x7E) |
| 155 | + if (c < 0x20 || c > 0x7E) { |
158 | 156 | out.print('.'); |
159 | | - else |
| 157 | + } else { |
160 | 158 | out.print((char) c); |
| 159 | + } |
161 | 160 | } |
162 | 161 | out.println(); |
163 | 162 | i += 16; |
164 | 163 | } |
165 | 164 | return str.toString(); |
166 | 165 | } |
167 | | - |
168 | | - public static String formatInt(int i, int radix, int len) |
169 | | - { |
| 166 | + |
| 167 | + public static String formatInt(int i, int radix, int len) { |
170 | 168 | String s = Integer.toString(i, radix); |
171 | 169 | StringBuffer buf = new StringBuffer(); |
172 | | - for (int j = 0; j < len - s.length(); j++) |
| 170 | + for (int j = 0; j < len - s.length(); j++) { |
173 | 171 | buf.append("0"); |
| 172 | + } |
174 | 173 | buf.append(s); |
175 | 174 | return buf.toString(); |
176 | 175 | } |
177 | | - |
178 | | - public static String toHexString(byte[] buf, int off, int len, char sep) |
179 | | - { |
| 176 | + |
| 177 | + public static String toHexString(byte[] buf, int off, int len, char sep) { |
180 | 178 | StringBuffer str = new StringBuffer(); |
181 | | - for (int i = 0; i < len; i++) |
182 | | - { |
183 | | - str.append(HEX.charAt(buf[i+off] >>> 4 & 0x0F)); |
184 | | - str.append(HEX.charAt(buf[i+off] & 0x0F)); |
185 | | - if (i < len - 1) |
| 179 | + for (int i = 0; i < len; i++) { |
| 180 | + str.append(HEX.charAt(buf[i + off] >>> 4 & 0x0F)); |
| 181 | + str.append(HEX.charAt(buf[i + off] & 0x0F)); |
| 182 | + if (i < len - 1) { |
186 | 183 | str.append(sep); |
| 184 | + } |
187 | 185 | } |
188 | 186 | return str.toString(); |
189 | 187 | } |
190 | 188 |
|
191 | | - |
192 | 189 | static final String HEX = "0123456789abcdef"; |
193 | 190 |
|
194 | 191 |
|
|
0 commit comments