本文整理匯總了Java中com.sun.net.httpserver.Headers.putAll方法的典型用法代碼示例。如果您正苦於以下問題:Java Headers.putAll方法的具體用法?Java Headers.putAll怎麽用?Java Headers.putAll使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.sun.net.httpserver.Headers
的用法示例。
在下文中一共展示了Headers.putAll方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: writeOutcome
import com.sun.net.httpserver.Headers; //導入方法依賴的package包/類
private void writeOutcome( Outcome outcome, HttpExchange exchange )
throws IOException
{
// Headers
Headers headers = exchange.getResponseHeaders();
headers.putAll( outcome.responseHeader().headers().allValues() );
// Body
InputStream bodyStream = null;
int chunkSize = HTTP_BUF_SIZE;
final long responseLength;
if( outcome instanceof ChunkedInputOutcome )
{
ChunkedInputOutcome chunked = (ChunkedInputOutcome) outcome;
bodyStream = chunked.inputStream();
chunkSize = chunked.chunkSize();
responseLength = 0;
}
else if( outcome instanceof InputStreamOutcome )
{
InputStreamOutcome input = (InputStreamOutcome) outcome;
bodyStream = input.bodyInputStream();
responseLength = input.contentLength();
}
else if( outcome instanceof SimpleOutcome )
{
SimpleOutcome simple = (SimpleOutcome) outcome;
bodyStream = simple.body().asStream();
responseLength = 0;
}
else
{
responseLength = -1;
}
// Status and Content-Length
exchange.sendResponseHeaders( outcome.responseHeader().status().code(), responseLength );
// Body if any
if( bodyStream != null )
{
InputStreams.transferTo( bodyStream, exchange.getResponseBody(), chunkSize );
}
}