本文整理汇总了Java中java.net.URLConnection.getHeaderFieldInt方法的典型用法代码示例。如果您正苦于以下问题:Java URLConnection.getHeaderFieldInt方法的具体用法?Java URLConnection.getHeaderFieldInt怎么用?Java URLConnection.getHeaderFieldInt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.net.URLConnection
的用法示例。
在下文中一共展示了URLConnection.getHeaderFieldInt方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: shoutcastProxyReaderLoop
import java.net.URLConnection; //导入方法依赖的package包/类
private void shoutcastProxyReaderLoop(Socket proxy, URLConnection connection) throws IOException {
connection.setConnectTimeout(5000);
connection.setReadTimeout(5000);
connection.setRequestProperty("Icy-MetaData", "1");
connection.connect();
InputStream in = connection.getInputStream();
OutputStream out = proxy.getOutputStream();
out.write(("HTTP/1.0 200 OK\r\n" +
"Pragma: no-cache\r\n" +
"Content-Type: " + connection.getContentType() +
"\r\n\r\n").getBytes(StandardCharsets.UTF_8));
byte buf[] = new byte[16384]; // one second of 128kbit stream
int count = 0;
int total = 0;
int metadataSize = 0;
final int metadataOffset = connection.getHeaderFieldInt("icy-metaint", 0);
int bitRate = Math.max(connection.getHeaderFieldInt("icy-br", 128), 32);
LogHelper.v(LOG_TAG, "createProxyConnection: connected, icy-metaint " + metadataOffset + " icy-br " + bitRate);
while (true) {
count = Math.min(in.available(), buf.length);
if (count <= 0) {
count = Math.min(bitRate * 64, buf.length); // buffer half-second of stream data
}
if (metadataOffset > 0) {
count = Math.min(count, metadataOffset - total);
}
count = in.read(buf, 0, count);
if (count == 0) {
continue;
}
if (count < 0) {
break;
}
out.write(buf, 0, count);
total += count;
if (metadataOffset > 0 && total >= metadataOffset) {
// read metadata
total = 0;
count = in.read();
if (count < 0) {
break;
}
count *= 16;
metadataSize = count;
if (metadataSize == 0) {
continue;
}
// maximum metadata length is 4080 bytes
total = 0;
while (total < metadataSize) {
count = in.read(buf, total, count);
if (count < 0) {
break;
}
if (count == 0) {
continue;
}
total += count;
count = metadataSize - total;
}
total = 0;
String[] metadata = new String(buf, 0, metadataSize, StandardCharsets.UTF_8).split(";");
for (String s : metadata) {
if (s.indexOf(TransistorKeys.SHOUTCAST_STREAM_TITLE_HEADER) == 0 &&
s.length() >= TransistorKeys.SHOUTCAST_STREAM_TITLE_HEADER.length() + 1) {
handleMetadataString(s.substring(TransistorKeys.SHOUTCAST_STREAM_TITLE_HEADER.length(), s.length() - 1));
// break;
}
}
}
}
}