Follow up fix to close streams at the end.

To be really correct, the crumb API call should be using the encoding specified in the HTTP response header, but doing so involves various header parsing, which is cumbersome.

Since we know Jenkins always serve the API call in UTF-8 encoding, here I'm baking that assumption in.
This commit is contained in:
Kohsuke Kawaguchi committed 2011-07-23 07:11:06 -07:00
1 parent 386ec0d15e
commit 4ee8d6890c
2 files changed
+15 -16

No files matched your search

+2 -13
View File
@@ -26,14 +26,12 @@ package hudson;
import hudson.util.DualOutputStream;
import hudson.util.EncodingStream;
import com.thoughtworks.xstream.core.util.Base64Encoder;
import hudson.util.IOUtils;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.net.HttpRetryException;
@@ -124,7 +122,7 @@ public class Main {
HttpURLConnection con = open(new URL(home +
"crumbIssuer/api/xml?xpath=concat(//crumbRequestField,\":\",//crumb)'"));
if (auth != null) con.setRequestProperty("Authorization", auth);
String line = readFirstLine(con.getInputStream());
String line = IOUtils.readFirstLine(con.getInputStream(),"UTF-8");
String[] components = line.split(":");
if (components.length == 2) {
crumbField = components[0];
@@ -196,15 +194,6 @@ public class Main {
}
}
private static String readFirstLine(InputStream is) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
try {
return reader.readLine();
} finally {
reader.close();
}
}
/**
* Connects to the given HTTP URL and configure time out, to avoid infinite hang.
*/