本文整理了Java中akka.util.ByteString.decodeString()
方法的一些代码示例,展示了ByteString.decodeString()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ByteString.decodeString()
方法的具体详情如下:
包路径:akka.util.ByteString
类名称:ByteString
方法名:decodeString
暂无
代码示例来源:origin: com.typesafe.play/play-test_2.12
/**
* Extracts the content as a String.
*
* @param result The result to extract the content from.
* @param mat The materializer to use to extract the body from the result stream.
* @return The content of the result as a String.
*/
public static String contentAsString(Result result, Materializer mat) {
return contentAsBytes(result, mat, DEFAULT_TIMEOUT)
.decodeString(result.charset().orElse("utf-8"));
}
代码示例来源:origin: com.typesafe.play/play-test_2.11
/**
* Extracts the content as a String.
*
* @param result The result to extract the content from.
* @param mat The materializer to use to extract the body from the result stream.
* @return The content of the result as a String.
*/
public static String contentAsString(Result result, Materializer mat) {
return contentAsBytes(result, mat, DEFAULT_TIMEOUT)
.decodeString(result.charset().orElse("utf-8"));
}
代码示例来源:origin: com.typesafe.play/play-test_2.12
/**
* Extracts the content as a String.
*
* @param result The result to extract the content from.
* @param mat The materializer to use to extract the body from the result stream.
* @param timeout The amount of time, in milliseconds, to wait for the body to be produced.
* @return The content of the result as a String.
*/
public static String contentAsString(Result result, Materializer mat, long timeout) {
return contentAsBytes(result, mat, timeout)
.decodeString(result.charset().orElse("utf-8"));
}
代码示例来源:origin: com.typesafe.play/play-test_2.11
/**
* Extracts the content as a String.
*
* @param result The result to extract the content from.
* @param mat The materializer to use to extract the body from the result stream.
* @param timeout The amount of time, in milliseconds, to wait for the body to be produced.
* @return The content of the result as a String.
*/
public static String contentAsString(Result result, Materializer mat, long timeout) {
return contentAsBytes(result, mat, timeout)
.decodeString(result.charset().orElse("utf-8"));
}
代码示例来源:origin: com.typesafe.play/play-test_2.11
/**
* Extracts the content as a String.
* <p>
* This method is only capable of extracting the content of results with strict entities. To extract the content of
* results with streamed entities, use {@link Helpers#contentAsString(Result, Materializer)}.
*
* @param result The result to extract the content from.
* @return The content of the result as a String.
* @throws UnsupportedOperationException if the result does not have a strict entity.
*/
public static String contentAsString(Result result) {
return contentAsBytes(result)
.decodeString(result.charset().orElse("utf-8"));
}
代码示例来源:origin: com.typesafe.play/play-test_2.12
/**
* Extracts the content as a String.
* <p>
* This method is only capable of extracting the content of results with strict entities. To extract the content of
* results with streamed entities, use {@link Helpers#contentAsString(Result, Materializer)}.
*
* @param result The result to extract the content from.
* @return The content of the result as a String.
* @throws UnsupportedOperationException if the result does not have a strict entity.
*/
public static String contentAsString(Result result) {
return contentAsBytes(result)
.decodeString(result.charset().orElse("utf-8"));
}
代码示例来源:origin: com.typesafe.play/play_2.12
@Override
protected Map<String, String[]> parse(Http.RequestHeader request, ByteString bytes) throws Exception {
String charset = request.charset().orElse("UTF-8");
String urlEncodedString = bytes.decodeString("UTF-8");
return FormUrlEncodedParser.parseAsJavaArrayValues(urlEncodedString, charset);
}
}
代码示例来源:origin: com.typesafe.play/play_2.11
@Override
protected Map<String, String[]> parse(Http.RequestHeader request, ByteString bytes) throws Exception {
String charset = request.charset().orElse("UTF-8");
String urlEncodedString = bytes.decodeString("UTF-8");
return FormUrlEncodedParser.parseAsJavaArrayValues(urlEncodedString, charset);
}
}
代码示例来源:origin: com.typesafe.play/play
@Override
protected Map<String, String[]> parse(Http.RequestHeader request, ByteString bytes) throws Exception {
String charset = request.charset().orElse("UTF-8");
String urlEncodedString = bytes.decodeString("UTF-8");
return FormUrlEncodedParser.parseAsJavaArrayValues(urlEncodedString, charset);
}
}
代码示例来源:origin: com.typesafe.play/play
@Override
protected String parse(Http.RequestHeader request, ByteString bytes) throws Exception {
// Per RFC 7231:
// The default charset of ISO-8859-1 for text media types has been removed; the default is now
// whatever the media type definition says.
// Per RFC 6657:
// The default "charset" parameter value for "text/plain" is unchanged from [RFC2046] and remains as "US-ASCII".
// https://tools.ietf.org/html/rfc6657#section-4
Charset charset = request.charset().map(Charset::forName).orElse(US_ASCII);
try {
CharsetDecoder decoder = charset.newDecoder().onMalformedInput(CodingErrorAction.REPORT);
return decoder.decode(bytes.toByteBuffer()).toString();
} catch (CharacterCodingException e) {
String msg = String.format("Parser tried to parse request %s as text body with charset %s, but it contains invalid characters!", request.id(), charset);
logger.warn(msg);
return bytes.decodeString(charset); // parse and return with unmappable characters.
} catch (Exception e) {
String msg = "Unexpected exception while parsing text/plain body";
logger.error(msg, e);
return bytes.decodeString(charset);
}
}
}
代码示例来源:origin: com.typesafe.play/play_2.12
@Override
protected String parse(Http.RequestHeader request, ByteString bytes) throws Exception {
// Per RFC 7231:
// The default charset of ISO-8859-1 for text media types has been removed; the default is now
// whatever the media type definition says.
// Per RFC 6657:
// The default "charset" parameter value for "text/plain" is unchanged from [RFC2046] and remains as "US-ASCII".
// https://tools.ietf.org/html/rfc6657#section-4
Charset charset = request.charset().map(Charset::forName).orElse(US_ASCII);
try {
CharsetDecoder decoder = charset.newDecoder().onMalformedInput(CodingErrorAction.REPORT);
return decoder.decode(bytes.toByteBuffer()).toString();
} catch (CharacterCodingException e) {
String msg = String.format("Parser tried to parse request %s as text body with charset %s, but it contains invalid characters!", request.id(), charset);
logger.warn(msg);
return bytes.decodeString(charset); // parse and return with unmappable characters.
} catch (Exception e) {
String msg = "Unexpected exception while parsing text/plain body";
logger.error(msg, e);
return bytes.decodeString(charset);
}
}
}
代码示例来源:origin: com.typesafe.play/play_2.11
@Override
protected String parse(Http.RequestHeader request, ByteString bytes) throws Exception {
// Per RFC 7231:
// The default charset of ISO-8859-1 for text media types has been removed; the default is now
// whatever the media type definition says.
// Per RFC 6657:
// The default "charset" parameter value for "text/plain" is unchanged from [RFC2046] and remains as "US-ASCII".
// https://tools.ietf.org/html/rfc6657#section-4
Charset charset = request.charset().map(Charset::forName).orElse(US_ASCII);
try {
CharsetDecoder decoder = charset.newDecoder().onMalformedInput(CodingErrorAction.REPORT);
return decoder.decode(bytes.toByteBuffer()).toString();
} catch (CharacterCodingException e) {
String msg = String.format("Parser tried to parse request %s as text body with charset %s, but it contains invalid characters!", request.id(), charset);
logger.warn(msg);
return bytes.decodeString(charset); // parse and return with unmappable characters.
} catch (Exception e) {
String msg = "Unexpected exception while parsing text/plain body";
logger.error(msg, e);
return bytes.decodeString(charset);
}
}
}
代码示例来源:origin: com.typesafe.play/play_2.12
return bytes.decodeString(charset);
});
});
代码示例来源:origin: com.typesafe.play/play_2.11
return bytes.decodeString(charset);
});
});
代码示例来源:origin: com.typesafe.play/play
return bytes.decodeString(charset);
});
});
代码示例来源:origin: com.typesafe.play/play-ahc-ws-standalone
@Override
public String getBody() {
return getBodyAsBytes().decodeString(AhcWSUtils.getCharset(getContentType()));
}
代码示例来源:origin: com.typesafe.play/play-ahc-ws-standalone_2.12
@Override
public String getBody() {
return getBodyAsBytes().decodeString(AhcWSUtils.getCharset(getContentType()));
}
代码示例来源:origin: com.typesafe.play/play-ahc-ws-standalone
String bodyString = inMemoryBody.body().get().decodeString(charset);
代码示例来源:origin: com.typesafe.play/play-ahc-ws-standalone_2.12
String bodyString = inMemoryBody.body().get().decodeString(charset);
代码示例来源:origin: com.lightbend.akka/akka-stream-alpakka-file
/**
* Java API: Read the entire contents of a file as text lines, and then when the end is reached,
* keep reading newly appended data. Like the unix command `tail -f`.
*
* <p>If a line is longer than `maxChunkSize` the stream will fail.
*
* <p>Aborting the stage can be done by combining with a [[akka.stream.KillSwitch]]
*
* @param path a file path to tail
* @param maxLineSize The max emitted size of the `ByteString`s
* @param pollingInterval When the end has been reached, look for new content with this interval
* @param lf The character or characters used as line separator
* @param charset The charset of the file
*/
public static Source<String, NotUsed> createLines(
Path path, int maxLineSize, FiniteDuration pollingInterval, String lf, Charset charset) {
return create(path, maxLineSize, 0, pollingInterval)
.via(Framing.delimiter(ByteString.fromString(lf, charset.name()), maxLineSize))
.map(bytes -> bytes.decodeString(charset));
}
内容来源于网络,如有侵权,请联系作者删除!