/** * @since 4.4 */ public HttpRequestBuilder setCharset(final CharsetEnum charset) { this.charset = charset.getCharset(); return this; }
/** * Constructor with method, URL, headers, body and type. * @param body the body * @param headers the headers * @param method the method * @param url the URL * @param type the type used for generic type resolution * @since 4.3 */ public RequestEntity(T body, MultiValueMap<String, String> headers, HttpMethod method, URI url, Type type) { this(body, headers, method, url, null, CharsetEnum.UTF_8.getCharset()); }
public DefaultBodyBuilder(HttpMethod method, String url) { this.method = method; this.url = url; this.charsetResolve = CharsetEnum.UTF_8.getCharset(); this.headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); }
/** * 获得认证信息 * @return */ public String getAuthentication() { return "Basic " + EncryptUtil.encodeBase64((name + ":" + password).getBytes(CharsetEnum.UTF_8.getCharset())); }
@Override public void channelReadInternal(NettyProtocol read) { System.out.println(new String(read.getContent(), CharsetEnum.UTF_8.getCharset())); }
public String stringVale() { return new String(getContent(), CharsetEnum.UTF_8.getCharset()); }
public static String importFileNio(FileInputStream inputStream, CharsetEnum charset) { byte[] result = null; try (FileChannel channel = inputStream.getChannel()) { long allByteLength = channel.size(); ByteBuffer byteBuffer = ByteBuffer.allocate(1024); int nowByteLength = 0; result = new byte[Integer.parseInt(String.valueOf(allByteLength))]; while (channel.read(byteBuffer) != -1) { int position = byteBuffer.position(); System.arraycopy(byteBuffer.array(), 0, result, nowByteLength, position); nowByteLength += position; byteBuffer.clear(); } } catch (IOException e) { e.printStackTrace(); } return new String(result, charset.getCharset()); }
public static List<String> importText(InputStream inputStream) { Reader reader = null; BufferedReader br = null; List<String> list = null; try { reader = new InputStreamReader(inputStream); br = new BufferedReader(reader); list = new ArrayList<String>(); String str = ""; while ((str = br.readLine()) != null) { list.add(new String(str.getBytes(), CharsetEnum.ISO_8859_1.getCharset())); } } catch (Exception e) { log.error("读取文件出错,原因为:" + e); } finally { IOUtils.closeQuietly(br); IOUtils.closeQuietly(reader); } return list; }
@Override public void channelReadInternal(NettyProtocol read) throws Exception { System.out.println(new String(read.getContent(), CharsetEnum.UTF_8.getCharset())); write("success!"); } }
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { T buf = (T) msg; String request = new String(buf.getContent(), CharsetEnum.UTF_8.getCharset()); channelReadInternal(ctx, request); }
public void write(String content) throws Exception { getCtx().writeAndFlush(new NettyProtocol(content.getBytes(CharsetEnum.UTF_8.getCharset()))); }
StringBuffer stringBuffer = new StringBuffer(); while ((len = stream.read(b)) != -1) { stringBuffer.append(new String(b, 0, len, CharsetEnum.UTF_8.getCharset()));
/** * 原生HttpClient使用方法 * @author jwSun * @date 2017年6月14日 下午4:21:29 * @param request * @return */ public static ResponseEntity<String> execute(HttpRequestBase request, HttpClient httpClient) { try { HttpResponse response = httpClient.execute(request); HttpEntity responseEntity = response.getEntity(); String body = EntityUtils.toString(responseEntity, CharsetEnum.UTF_8.getCharset()); EntityUtils.consume(response.getEntity()); return ResponseEntity.status(response.getStatusLine().getStatusCode()).body(body); } catch (Exception e) { log.error(e.getLocalizedMessage()); throw new ConnectionException(request.toString(), e); } finally { request.releaseConnection(); } }
private static EncodedResource[] loadResources(String location) { try { Resource[] resources = resourceResolver.getResources(location); EncodedResource[] encodeResources = new EncodedResource[resources.length]; for (int i = 0; i < resources.length; i++) { Resource resource = resources[i]; encodeResources[i] = new EncodedResource(resource, CharsetEnum.UTF_8.getCharset()); } return encodeResources; } catch (Exception e) { log.error("loadResource error", e); throw new BusinessException("loadResource error"); } }
if (val != null) val = new String(val.getBytes(CharsetEnum.ISO_8859_1.getName()), CharsetEnum.UTF_8.getCharset()); } else { val = ConfigProperties.localenv.getProperty(name, defaultVal);
@Override public String executeQueryBody(KylinBodySearch kylinBodySearch) { StringEntity stringEntity = new StringEntity(kylinBodySearch.searchJson(), CharsetEnum.UTF_8.getCharset()); stringEntity.setContentType(MediaType.APPLICATION_JSON_UTF8_VALUE); ResponseEntity<String> responseBody = HttpClientUtil .execute(HttpRequestBuilder.post(kylinUrl + API + QUERY).setEntity(stringEntity), getHttpClient()); Callback callback = checkResult(responseBody); if (callback == Callback.RESTART) { return executeQueryBody(kylinBodySearch); } else if (callback == Callback.RETURN) { return responseBody.getBody(); } else { throw new KylinUnKnowException("responseBody is : " + responseBody); } }