List of usage examples for java.nio.charset CodingErrorAction IGNORE
CodingErrorAction IGNORE
To view the source code for java.nio.charset CodingErrorAction IGNORE.
Click Source Link
From source file:com.helger.httpclient.HttpClientFactory.java
/** * @return The connection builder used by the * {@link PoolingHttpClientConnectionManager} to create the default * connection configuration.//from w w w . j av a 2s . c o m */ @Nonnull public ConnectionConfig.Builder createConnectionConfigBuilder() { return ConnectionConfig.custom().setMalformedInputAction(CodingErrorAction.IGNORE) .setUnmappableInputAction(CodingErrorAction.IGNORE).setCharset(StandardCharsets.UTF_8); }
From source file:com.wudaosoft.net.httpclient.Request.java
protected void init() throws KeyManagementException, NoSuchAlgorithmException, KeyStoreException, CertificateException, IOException { Args.notNull(hostConfig, "Host config"); SSLConnectionSocketFactory sslConnectionSocketFactory = null; if (sslcontext == null) { if (hostConfig.getCA() != null) { // Trust root CA and all self-signed certs SSLContext sslcontext1 = SSLContexts.custom().loadTrustMaterial(hostConfig.getCA(), hostConfig.getCAPassword(), TrustSelfSignedStrategy.INSTANCE).build(); // Allow TLSv1 protocol only sslConnectionSocketFactory = new SSLConnectionSocketFactory(sslcontext1, new String[] { "TLSv1" }, null, SSLConnectionSocketFactory.getDefaultHostnameVerifier()); } else {//from www . j a v a 2 s . c o m if (isTrustAll) { SSLContext sslcontext1 = SSLContext.getInstance("TLS"); TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() { public X509Certificate[] getAcceptedIssuers() { return null; } @Override public void checkClientTrusted(java.security.cert.X509Certificate[] arg0, String arg1) throws CertificateException { } @Override public void checkServerTrusted(java.security.cert.X509Certificate[] arg0, String arg1) throws CertificateException { } } }; sslcontext1.init(null, trustAllCerts, null); sslConnectionSocketFactory = new SSLConnectionSocketFactory(sslcontext1, NoopHostnameVerifier.INSTANCE); } else { sslConnectionSocketFactory = SSLConnectionSocketFactory.getSocketFactory(); } } } else { sslConnectionSocketFactory = new SSLConnectionSocketFactory(sslcontext, new String[] { "TLSv1" }, null, SSLConnectionSocketFactory.getDefaultHostnameVerifier()); } if (keepAliveStrategy == null) { keepAliveStrategy = new ConnectionKeepAliveStrategy() { public long getKeepAliveDuration(HttpResponse response, HttpContext context) { // Honor 'keep-alive' header HeaderElementIterator it = new BasicHeaderElementIterator( response.headerIterator(HTTP.CONN_KEEP_ALIVE)); while (it.hasNext()) { HeaderElement he = it.nextElement(); String param = he.getName(); String value = he.getValue(); if (value != null && param.equalsIgnoreCase("timeout")) { try { return Long.parseLong(value) * 1000; } catch (NumberFormatException ignore) { } } } // HttpHost target = (HttpHost) // context.getAttribute(HttpClientContext.HTTP_TARGET_HOST); // if // ("xxxxx".equalsIgnoreCase(target.getHostName())) // { // // Keep alive for 5 seconds only // return 3 * 1000; // } else { // // otherwise keep alive for 30 seconds // return 30 * 1000; // } return 30 * 1000; } }; } if (retryHandler == null) { retryHandler = new HttpRequestRetryHandler() { public boolean retryRequest(IOException exception, int executionCount, HttpContext context) { if (executionCount >= 3) { // Do not retry if over max retry count return false; } if (exception instanceof InterruptedIOException) { // Timeout return false; } if (exception instanceof UnknownHostException) { // Unknown host return false; } if (exception instanceof ConnectTimeoutException) { // Connection refused return false; } if (exception instanceof SSLException) { // SSL handshake exception return false; } HttpClientContext clientContext = HttpClientContext.adapt(context); HttpRequest request = clientContext.getRequest(); boolean idempotent = !(request instanceof HttpEntityEnclosingRequest); if (idempotent) { // Retry if the request is considered idempotent return true; } return false; } }; } connManager = new PoolingHttpClientConnectionManager(RegistryBuilder.<ConnectionSocketFactory>create() .register("http", PlainConnectionSocketFactory.getSocketFactory()) .register("https", sslConnectionSocketFactory).build()); if (hostConfig.getHost() != null) { connManager.setMaxTotal(hostConfig.getPoolSize() + 60); connManager.setMaxPerRoute( new HttpRoute(hostConfig.getHost(), null, !HttpHost.DEFAULT_SCHEME_NAME.equals(hostConfig.getHost().getSchemeName())), hostConfig.getPoolSize()); connManager.setDefaultMaxPerRoute(20); } else { connManager.setMaxTotal(hostConfig.getPoolSize()); int hostCount = hostConfig.getHostCount() == 0 ? 10 : hostConfig.getHostCount(); connManager.setDefaultMaxPerRoute(hostConfig.getPoolSize() / hostCount); } // connManager.setValidateAfterInactivity(2000); // Create socket configuration SocketConfig socketConfig = SocketConfig.custom().setTcpNoDelay(true).setSoKeepAlive(isKeepAlive).build(); connManager.setDefaultSocketConfig(socketConfig); // Create connection configuration ConnectionConfig connectionConfig = ConnectionConfig.custom() .setMalformedInputAction(CodingErrorAction.IGNORE) .setUnmappableInputAction(CodingErrorAction.IGNORE) .setCharset(hostConfig.getCharset() == null ? Consts.UTF_8 : hostConfig.getCharset()).build(); connManager.setDefaultConnectionConfig(connectionConfig); new IdleConnectionMonitorThread(connManager).start(); if (requestInterceptor == null) { requestInterceptor = new SortHeadersInterceptor(hostConfig); } if (!hostConfig.isMulticlient()) { defaultHttpContext = HttpClientContext.create(); httpClient = create(); } }
From source file:org.alan.graph.binaryparsermaven.util.ParseZNOFiles.java
private void parseFile(File f, String dir, SchoolInterface s, Date dat) throws Exception { try {/* w w w . j a v a2s .c o m*/ //rs /* FileWriter fileWriter = new FileWriter(dir + f.getName() + ".csv"); CSVWriter cw = new CSVWriter(fileWriter); */ //rs int schools = 1; FileInputStream fis = new FileInputStream(f); byte[] arr = IOUtils.toByteArray(fis); byte[] split = new byte[] { 0x00, 0x01, 0x0a, 0x00, 0x00, 0x00 }; int rend = 0; int start = 0; int end = 0; byte[] data; int i1 = 0; boolean flag = true; while (flag) { schools++; //System.out.println(schools); start = indexOf(arr, split, end); end = indexOf(arr, split, start + split.length); rend = indexOf(arr, split, end + split.length - 1); if (end < start) { end = arr.length - 1; flag = false; } if (Math.abs(rend - end) <= 6 && rend > 0) { end = rend; } data = new byte[(end - start) + 1]; i1 = 0; for (int i = start; i < end; i++) { data[i1++] = arr[i]; } String[] parsedData = parseData(data, split.length, dat); /* if (s == null) { cw.writeNext(parsedData); } else {*/ Points p = new Points(); p.setValueType(f.getName()); p.setKoatyy(parsedData[0]); p.setParentKoatyy(parsedData[1]); CharsetDecoder utf8Decoder = Charset.forName("UTF-8").newDecoder(); utf8Decoder.onMalformedInput(CodingErrorAction.IGNORE); utf8Decoder.onUnmappableCharacter(CodingErrorAction.IGNORE); ByteBuffer bytes = ByteBuffer.wrap(parsedData[2].getBytes()); CharBuffer parsed = utf8Decoder.decode(bytes); String repl = String.valueOf(parsed.array()); repl = repl.replaceAll("\\x00", ""); p.setSchoolName(repl); p.setSchoolType(Integer.valueOf(parsedData[3])); p.setValue1(Double.valueOf(parsedData[4])); p.setValue2(Double.valueOf(parsedData[5])); p.setValue3(Double.valueOf(parsedData[6])); p.setValue4(Double.valueOf(parsedData[7])); p.setValue5(Double.valueOf(parsedData[8])); p.setValue6(Double.valueOf(parsedData[9])); p.setValue7(Double.valueOf(parsedData[10])); p.setValue8(Double.valueOf(parsedData[11])); p.setValue9(Double.valueOf(parsedData[12])); p.setValue10(Double.valueOf(parsedData[13])); p.setPupils(Integer.valueOf(parsedData[14])); p.setDat(dat); s.save(p); //} } // System.out.println(data); fis.close(); //csv /* fileWriter.close(); cw.close(); */ } catch (IOException ex) { Logger.getLogger(App.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:org.apache.synapse.transport.utils.config.HttpTransportConfiguration.java
private CodingErrorAction getCodingErrorAction(String action) { if ("report".equals(action)) { return CodingErrorAction.REPORT; } else if ("ignore".equals(action)) { return CodingErrorAction.IGNORE; } else if ("replace".equals(action)) { return CodingErrorAction.REPLACE; } else {//from w w w .j a v a 2 s . co m return CodingErrorAction.REPORT; } }