Java Code Examples for org.apache.commons.codec.Charsets#UTF_8

The following examples show how to use org.apache.commons.codec.Charsets#UTF_8 . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Dsmlv2Engine.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Processes the Request document
 * 
 * @return the XML response in DSMLv2 Format
 */
private String processDSML()
{
    try
    {
        ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
        processDSML( byteOut );
        return new String( byteOut.toByteArray(), Charsets.UTF_8 );
    }
    catch ( IOException e )
    {
        LOG.error( I18n.err( I18n.ERR_02000_FAILED_PROCESSING_DSML ), e );
    }

    return null;
}
 
Example 2
Source File: ECRLoginStep.java    From pipeline-aws-plugin with Apache License 2.0 6 votes vote down vote up
@Override
protected String run() throws Exception {
	AmazonECR ecr = AWSClientFactory.create(AmazonECRClientBuilder.standard(), this.getContext());

	GetAuthorizationTokenRequest request = new GetAuthorizationTokenRequest();
	List<String> registryIds;
	if((registryIds = this.step.getRegistryIds()) != null) {
		request.setRegistryIds(registryIds);
	}
	GetAuthorizationTokenResult token = ecr.getAuthorizationToken(request);

	if (token.getAuthorizationData().size() != 1) {
		throw new RuntimeException("Did not get authorizationData from AWS");
	}

	AuthorizationData authorizationData = token.getAuthorizationData().get(0);
	byte[] bytes = org.apache.commons.codec.binary.Base64.decodeBase64(authorizationData.getAuthorizationToken());
	String data = new String(bytes, Charsets.UTF_8);
	String[] parts = data.split(":");
	if (parts.length != 2) {
		throw new RuntimeException("Got invalid authorizationData from AWS");
	}

	String emailString = this.step.getEmail() ? "-e none" : "";
	return String.format("docker login -u %s -p %s %s %s", parts[0], parts[1], emailString, authorizationData.getProxyEndpoint());
}
 
Example 3
Source File: Gobbler.java    From antsdb with GNU Lesser General Public License v3.0 5 votes vote down vote up
public String getMessage() {
    int size = getSize();
    byte[] bytes = new byte[size];
    for (int i=0; i<size; i++) {
        bytes[i] = Unsafe.getByte(this.addr + OFFSET_MESSAGE + i);
    }
    return new String(bytes, Charsets.UTF_8);
}
 
Example 4
Source File: UploadInfo.java    From tus-java-server with MIT License 5 votes vote down vote up
private String decode(String encodedValue) {
    if (encodedValue == null) {
        return null;
    } else {
        return new String(Base64.decodeBase64(encodedValue), Charsets.UTF_8);
    }
}
 
Example 5
Source File: LargeInputTest.java    From tarql with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test public void testDummyContentSource() throws IOException {
	final int lines = 5;
	BufferedReader r = new BufferedReader(
			new InputStreamReader(new DummyContentSource(lines).open(), Charsets.UTF_8));
	int readLines = 0;
	while (r.readLine() != null) {
		readLines++;
	}
	assertEquals(lines, readLines);
}
 
Example 6
Source File: BackupFile.java    From antsdb with GNU Lesser General Public License v3.0 5 votes vote down vote up
private static String readUtf(DataInputStream in) throws IOException {
    int length = in.readInt();
    byte[] bytes = new byte[length];
    IOUtils.readFully(in, bytes);
    String result = new String(bytes, Charsets.UTF_8);
    return result;
}
 
Example 7
Source File: QuotedPrintableCodec.java    From text_converter with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Default constructor, assumes default charset of {@link Charsets#UTF_8}
 */
public QuotedPrintableCodec() {
    this(Charsets.UTF_8, false);
}
 
Example 8
Source File: QCodec.java    From pivaa with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Default constructor.
 */
public QCodec() {
    this(Charsets.UTF_8);
}
 
Example 9
Source File: QuotedPrintableCodec.java    From pivaa with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Default constructor, assumes default charset of {@link Charsets#UTF_8}
 */
public QuotedPrintableCodec() {
    this(Charsets.UTF_8, false);
}
 
Example 10
Source File: BCodec.java    From pivaa with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Default constructor.
 */
public BCodec() {
    this(Charsets.UTF_8);
}
 
Example 11
Source File: HAWK.java    From NLIWOD with GNU Affero General Public License v3.0 4 votes vote down vote up
public void search(IQuestion question, String language) throws Exception {
		String questionString;
		if (!question.getLanguageToQuestion().containsKey(language)) {
			return;
		}
		questionString = question.getLanguageToQuestion().get(language);
		log.debug(this.getClass().getSimpleName() + ": " + questionString);

		RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(this.timeout).build();
		HttpClient client = HttpClientBuilder.create().setDefaultRequestConfig(requestConfig).build();
		URIBuilder builder = new URIBuilder().setScheme("http")
				.setHost("hawk.aksw.org:8181").setPath("/search")
				.setParameter("q", questionString);
		if(this.setLangPar){
			builder = builder.setParameter("lang", language);
		}
		URI iduri = builder.build();
		HttpGet httpget = new HttpGet(iduri);
		HttpResponse idresponse = client.execute(httpget);
		
		//Test if error occured
		if(idresponse.getStatusLine().getStatusCode()>=400){
			throw new Exception("HAWK Server (ID) could not answer due to: "+idresponse.getStatusLine());
		}
		
		String id = responseparser.responseToString(idresponse);
		JSONParser parser = new JSONParser();
//http://hawk.aksw.org:8181/
		//URI quri = new URIBuilder().setScheme("http")
		//		.setHost("139.18.2.164:8181").setPath("/status")
		//		.setParameter("UUID", id.substring(1, id.length() - 2)).build();
		URI quri = new URIBuilder().setScheme("http")
				.setHost("hawk.aksw.org:8181").setPath("/status")
				.setParameter("UUID", id.substring(1, id.length() - 2)).build();

		int j = 0;
		do {
			Thread.sleep(50);
			HttpGet questionpost = new HttpGet(quri);
			HttpResponse questionresponse = client.execute(questionpost);
			
			//Test if error occured
			if(questionresponse.getStatusLine().getStatusCode()>=400){
				throw new Exception("HAWK Server (Question) could not answer due to: "+questionresponse.getStatusLine());
			}
			
			JSONObject responsejson = (JSONObject) parser.parse(responseparser
					.responseToString(questionresponse));
			if (responsejson.containsKey("answer")) {
				JSONArray answerlist = (JSONArray) responsejson.get("answer");
				HashSet<String> result = new HashSet<String>();
				for (int i = 0; i < answerlist.size(); i++) {
					JSONObject answer = (JSONObject) answerlist.get(i);
					result.add(answer.get("URI").toString());
				}
				question.setGoldenAnswers(result);
				if (responsejson.containsKey("final_sparql_base64")) {
					String sparqlQuery = responsejson
							.get("final_sparql_base64").toString();
					sparqlQuery = new String(
							based64Decoder.decode(sparqlQuery), Charsets.UTF_8);
					question.setSparqlQuery(sparqlQuery);
				}
			}
			j = j + 1;
		} while (j < 500);
	}
 
Example 12
Source File: FinishMarker.java    From flume-plugin with Apache License 2.0 4 votes vote down vote up
private BufferedReader getReader() throws FileNotFoundException {
    return new BufferedReader(new InputStreamReader(new FileInputStream(target), Charsets.UTF_8));
}
 
Example 13
Source File: FinishMarker.java    From flume-plugin with Apache License 2.0 4 votes vote down vote up
public BufferedWriter getWriter(File target, boolean append) throws FileNotFoundException {
    return new BufferedWriter(new OutputStreamWriter(new FileOutputStream(target, append), Charsets.UTF_8));
}
 
Example 14
Source File: QCodec.java    From text_converter with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Default constructor.
 */
public QCodec() {
    this(Charsets.UTF_8);
}
 
Example 15
Source File: S3DataManager.java    From aws-codebuild-jenkins-plugin with Apache License 2.0 4 votes vote down vote up
public static String getZipMD5(File zipFile) throws IOException {
    return new String(encodeBase64(DigestUtils.md5(new FileInputStream(zipFile))), Charsets.UTF_8);
}
 
Example 16
Source File: Gobbler.java    From antsdb with GNU Lesser General Public License v3.0 4 votes vote down vote up
public String getDdl() {
    int size = getSize() - OFFSET_DDL + LogEntry.HEADER_SIZE;
    byte[] bytes = new byte[size];
    Unsafe.getBytes(this.addr + OFFSET_DDL, bytes);
    return new String(bytes, Charsets.UTF_8);
}
 
Example 17
Source File: PacketEncoder.java    From antsdb with GNU Lesser General Public License v3.0 4 votes vote down vote up
private boolean writeBinaryValueFast(PacketWriter buffer, FieldMeta meta, long pValue) {
    DataType type = meta.getType();
    byte format = Value.getFormat(null, pValue);
    if (type.getSqlType() == Types.TINYINT) {
        if (format == Value.FORMAT_INT4) {
            buffer.writeByte((byte)Int4.get(pValue));
            return true;
        }
        else if (format == Value.FORMAT_INT8) {
            buffer.writeByte((byte)Int8.get(null, pValue));
            return true;
        }
    }
    else if (type.getJavaType() == Boolean.class) {
        boolean b = FishBool.get(null, pValue);
        buffer.writeByte((byte)(b ? 1 : 0));
        return true;
    }
    else if (type.getJavaType() == Integer.class) {
        if (format == Value.FORMAT_INT4) {
            buffer.writeUB4(Int4.get(pValue));
            return true;
        }
        else if (format == Value.FORMAT_INT8) {
            buffer.writeUB4((int) Int8.get(null, pValue));
            return true;
        }
    }
    else if (type.getJavaType() == Long.class) {
        if (format == Value.FORMAT_INT4) {
            buffer.writeLongLong(Int4.get(pValue));
            return true;
        }
        else if (format == Value.FORMAT_INT8) {
            buffer.writeLongLong(Int8.get(null, pValue));
            return true;
        }
    }
    else if (type.getJavaType() == Float.class) {
        if (format == Value.FORMAT_FLOAT4) {
            buffer.writeUB4(Float.floatToIntBits(Float4.get(null, pValue)));
            return true;
        }
    }
    else if (type.getJavaType() == Double.class) {
        if (format == Value.FORMAT_FLOAT4) {
            buffer.writeLongLong(Double.doubleToLongBits(Float8.get(null, pValue)));
            return true;
        }
    }
    else if (type.getJavaType() == String.class) {
        if (format == Value.FORMAT_UTF8 && getEncoder() == Charsets.UTF_8) {
            buffer.writeLenStringUtf8(pValue);
            return true;
        }
    }
    return false;
}
 
Example 18
Source File: QuotedPrintableCodec.java    From text_converter with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Constructor which allows for the selection of the strict mode.
 *
 * @param strict
 *            if {@code true}, soft line breaks will be used
 * @since 1.10
 */
public QuotedPrintableCodec(final boolean strict) {
    this(Charsets.UTF_8, strict);
}
 
Example 19
Source File: QuotedPrintableCodec.java    From pivaa with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Constructor which allows for the selection of the strict mode.
 *
 * @param strict
 *            if {@code true}, soft line breaks will be used
 * @since 1.10
 */
public QuotedPrintableCodec(final boolean strict) {
    this(Charsets.UTF_8, strict);
}
 
Example 20
Source File: CommonCodecUtils.java    From cos-java-sdk-v4 with MIT License 2 votes vote down vote up
/**
 * 对二进制数据进行BASE64编码
 * 
 * @param binaryData 二进制数据
 * @return 编码后的字符串
 */
public static String Base64Encode(byte[] binaryData) {
    String encodedstr = new String(Base64.encodeBase64(binaryData, false), Charsets.UTF_8);
    return encodedstr;
}