List of usage examples for org.apache.commons.lang CharEncoding US_ASCII
String US_ASCII
To view the source code for org.apache.commons.lang CharEncoding US_ASCII.
Click Source Link
Seven-bit ASCII, also known as ISO646-US, also known as the Basic Latin block of the Unicode character set.
From source file:com.cmcc.util.StringUtils.java
/** * Encodes the given string into a sequence of bytes using the US-ASCII charset, storing the result into a new byte * array.// w ww . j a v a 2s .co m * * @param string * the String to encode, may be <code>null</code> * @return encoded bytes, or <code>null</code> if the input string was <code>null</code> * @throws IllegalStateException * Thrown when the charset is missing, which should be never according the the Java specification. * @see <a href="http://download.oracle.com/javase/1.5.0/docs/api/java/nio/charset/Charset.html">Standard charsets</a> * @see #getBytesUnchecked(String, String) */ public static byte[] getBytesUsAscii(String string) { return StringUtils.getBytesUnchecked(string, CharEncoding.US_ASCII); }
From source file:mitm.common.fetchmail.FetchmailPropertiesImpl.java
@Override public FetchmailConfig getFetchmailConfig() throws HierarchicalPropertiesException { FetchmailConfig config = null;// www . j av a 2 s . c o m String xml = getFetchmailXMLConfig(); try { if (StringUtils.isNotEmpty(xml)) { config = FetchmailConfigFactory.unmarshall(IOUtils.toInputStream(xml, CharEncoding.US_ASCII)); } } catch (JAXBException e) { throw new HierarchicalPropertiesException("Error unmarshalling XML.", e); } catch (IOException e) { throw new HierarchicalPropertiesException("Error reading XML.", e); } if (config == null) { config = new FetchmailConfig(); } return config; }
From source file:mitm.common.fetchmail.FetchmailPropertiesImpl.java
@Override public void setFetchmailConfig(FetchmailConfig config) throws HierarchicalPropertiesException { String xml = null;/*from www . j a va2 s . c o m*/ if (config != null) { ByteArrayOutputStream bos = new ByteArrayOutputStream(); try { FetchmailConfigFactory.marshall(config, bos); xml = new String(bos.toByteArray(), CharEncoding.US_ASCII); } catch (JAXBException e) { throw new HierarchicalPropertiesException("Error marshalling FetchmailConfig.", e); } catch (UnsupportedEncodingException e) { throw new HierarchicalPropertiesException("Error decoding.", e); } } properties.setProperty(PROPERTY_NAME, xml, true /* encrypt */); }
From source file:mitm.application.djigzo.james.mailets.OTPPasswordGenerator.java
@Override public void initMailet() throws MessagingException { super.initMailet(); encoding = getInitParameter(Parameter.ENCODING.name); if (StringUtils.isEmpty(encoding)) { encoding = CharEncoding.US_ASCII; }//from w w w.ja va 2 s. c o m defaultSecret = getInitParameter(Parameter.DEFAULT_SECRET.name); otpGenerator = SystemServices.getOTPGenerator(); }
From source file:mitm.common.security.ca.handlers.comodo.AutoAuthorize.java
private void handleResponse(int statusCode, HttpMethod httpMethod) throws IOException { if (statusCode != HttpStatus.SC_OK) { throw new IOException("Error Authorize. Message: " + httpMethod.getStatusLine()); }//w ww . j av a2 s . c o m InputStream input = httpMethod.getResponseBodyAsStream(); if (input == null) { throw new IOException("Response body is null."); } /* * we want to set a max on the number of bytes to download. We do not want a rogue server to return 1GB. */ InputStream limitInput = new SizeLimitedInputStream(input, MAX_HTTP_RESPONSE_SIZE); String response = IOUtils.toString(limitInput, CharEncoding.US_ASCII); if (logger.isDebugEnabled()) { logger.debug("Response:\r\n" + response); } LineNumberReader lineReader = new LineNumberReader(new StringReader(response)); String statusParameter = lineReader.readLine(); errorCode = CustomClientStatusCode.fromCode(statusParameter); if (errorCode.getID() < CustomClientStatusCode.SUCCESSFUL.getID()) { error = true; errorMessage = lineReader.readLine(); } else { error = false; } }
From source file:mitm.common.security.ca.handlers.comodo.CollectCustomClientCert.java
private void handleResponse(int statusCode, HttpMethod httpMethod) throws IOException { if (statusCode != HttpStatus.SC_OK) { throw new IOException("Error Collecting certificate. Message: " + httpMethod.getStatusLine()); }//from ww w.j av a2s. co m InputStream input = httpMethod.getResponseBodyAsStream(); if (input == null) { throw new IOException("Response body is null."); } /* * we want to set a max on the number of bytes to download. We do not want a rogue server to return 1GB. */ InputStream limitInput = new SizeLimitedInputStream(input, MAX_HTTP_RESPONSE_SIZE); String response = IOUtils.toString(limitInput, CharEncoding.US_ASCII); if (logger.isDebugEnabled()) { logger.debug("Response:\r\n" + response); } LineNumberReader lineReader = new LineNumberReader(new StringReader(response)); String statusParameter = lineReader.readLine(); errorCode = CustomClientStatusCode.fromCode(statusParameter); if (errorCode.getID() < CustomClientStatusCode.SUCCESSFUL.getID()) { error = true; errorMessage = lineReader.readLine(); } else { error = false; if (errorCode == CustomClientStatusCode.CERTIFICATES_ATTACHED) { /* * The certificate is base64 encoded between -----BEGIN CERTIFICATE----- and -----END CERTIFICATE----- */ StrBuilder base64 = new StrBuilder(4096); /* * Skip -----BEGIN CERTIFICATE----- */ String line = lineReader.readLine(); if (!"-----BEGIN CERTIFICATE-----".equalsIgnoreCase(line)) { throw new IOException("-----BEGIN CERTIFICATE----- expected but got: " + line); } do { line = lineReader.readLine(); if ("-----END CERTIFICATE-----".equalsIgnoreCase(line)) { break; } if (line != null) { base64.append(line); } } while (line != null); try { byte[] decoded = Base64.decodeBase64(MiscStringUtils.toAsciiBytes(base64.toString())); Collection<X509Certificate> certificates = CertificateUtils .readX509Certificates(new ByteArrayInputStream(decoded)); if (certificates != null && certificates.size() > 0) { certificate = certificates.iterator().next(); } } catch (CertificateException e) { throw new IOException(e); } catch (NoSuchProviderException e) { throw new IOException(e); } } } }
From source file:mitm.common.security.ca.handlers.comodo.ApplyCustomClientCert.java
private void handleResponse(int statusCode, HttpMethod httpMethod) throws IOException { if (statusCode != HttpStatus.SC_OK) { throw new IOException("Error applying for Custom Client Cert. Message: " + httpMethod.getStatusLine()); }// www. j a v a 2 s . c om InputStream input = httpMethod.getResponseBodyAsStream(); if (input == null) { throw new IOException("Response body is null."); } /* * we want to set a max on the number of bytes to download. We do not want a rogue server to return 1GB. */ InputStream limitInput = new SizeLimitedInputStream(input, MAX_HTTP_RESPONSE_SIZE); String response = IOUtils.toString(limitInput, CharEncoding.US_ASCII); if (logger.isDebugEnabled()) { logger.debug("Response:\r\n" + response); } Map<String, String[]> parameters = NetUtils.parseQuery(response); String errorCodeParam = getValue(parameters, "errorCode"); if (!StringUtils.isEmpty(errorCodeParam)) { errorCode = CustomClientStatusCode.fromCode(errorCodeParam); error = true; errorMessage = getValue(parameters, "errorMessage"); } else { error = false; orderNumber = getValue(parameters, "orderNumber"); collectionCode = getValue(parameters, "collectionCode"); if (StringUtils.isEmpty(orderNumber)) { throw new IOException(new CustomClientCertException("orderNumber is missing.")); } } }
From source file:mitm.common.security.ca.handlers.comodo.Tier2PartnerDetails.java
private void handleResponse(int statusCode, HttpMethod httpMethod) throws IOException { if (statusCode != HttpStatus.SC_OK) { throw new IOException("Error Tier2 partner details. Message: " + httpMethod.getStatusLine()); }//from w w w . j a va2 s . com InputStream input = httpMethod.getResponseBodyAsStream(); if (input == null) { throw new IOException("Response body is null."); } /* * we want to set a max on the number of bytes to download. We do not want a rogue server to return 1GB. */ InputStream limitInput = new SizeLimitedInputStream(input, MAX_HTTP_RESPONSE_SIZE); String response = IOUtils.toString(limitInput, CharEncoding.US_ASCII); if (logger.isDebugEnabled()) { logger.debug("Response:\r\n" + response); } Map<String, String[]> parameters = NetUtils.parseQuery(response); errorCode = CustomClientStatusCode.fromCode(getValue(parameters, "errorCode")); if (errorCode.getID() < CustomClientStatusCode.SUCCESSFUL.getID()) { error = true; errorMessage = getValue(parameters, "errorMessage"); } else { error = false; verificationLevel = getValue(parameters, "verificationLevel"); accountStatus = getValue(parameters, "accountStatus"); resellerStatus = getValue(parameters, "resellerStatus"); webHostResellerStatus = getValue(parameters, "webHostResellerStatus"); epkiStatus = getValue(parameters, "epkiStatus"); capLiveCCCs = getValue(parameters, "capLiveCCCs"); peakLiveCCCs = getValue(parameters, "peakLiveCCCs"); currentLiveCCCs = getValue(parameters, "currentLiveCCCs"); authorizedDomains = getValue(parameters, "authorizedDomains"); } }
From source file:mitm.common.dlp.impl.MimeMessageTextExtractorImpl.java
private void extractMimeMessageMetaInfo(MimeMessage message, PartContext context) throws MessagingException { TextExtractorContext extractorContext = new TextExtractorContextImpl(); extractorContext.setEncoding(CharEncoding.US_ASCII); extractorContext.setName("headers"); StrBuilder sb = new StrBuilder(4096); try {/*from ww w . j a va 2s . c om*/ for (Enumeration<?> headerEnum = message.getAllHeaders(); headerEnum.hasMoreElements();) { Header header = (Header) headerEnum.nextElement(); if (header == null) { continue; } if (skipHeaders != null && skipHeaders.contains(StringUtils.lowerCase(header.getName()))) { continue; } sb.append(header.getName()).append(": ").appendln(HeaderUtils.decodeTextQuietly(header.getValue())); } } catch (MessagingException e) { /* * Fallback to raw headers */ for (Enumeration<?> headerEnum = message.getAllHeaderLines(); headerEnum.hasMoreElements();) { sb.appendln(headerEnum.nextElement()); } } byte[] headerBytes = MiscStringUtils.toUTF8Bytes(sb.toString()); RewindableInputStream input = new RewindableInputStream(new ByteArrayInputStream(headerBytes), MEM_THRESHOLD); ExtractedPart part = new ExtractedPartImpl(extractorContext, input, headerBytes.length); try { context.update(part, true /* add */); } catch (IOException e) { throw new MessagingException("Error adding part to context.", e); } }
From source file:com.cmcc.util.StringUtils.java
/** * Constructs a new <code>String</code> by decoding the specified array of bytes using the US-ASCII charset. * /*from w w w . j a v a2s .c o m*/ * @param bytes * The bytes to be decoded into characters * @return A new <code>String</code> decoded from the specified array of bytes using the US-ASCII charset, * or <code>null</code> if the input byte array was <code>null</code>. * @throws IllegalStateException * Thrown when a {@link UnsupportedEncodingException} is caught, which should never happen since the * charset is required. */ public static String newStringUsAscii(byte[] bytes) { return StringUtils.newString(bytes, CharEncoding.US_ASCII); }