summaryrefslogtreecommitdiffstats
path: root/pki/base/java-tools
diff options
context:
space:
mode:
authorvakwetu <vakwetu@c9f7a03b-bd48-0410-a16d-cbbf54688b0b>2011-01-07 20:18:30 +0000
committervakwetu <vakwetu@c9f7a03b-bd48-0410-a16d-cbbf54688b0b>2011-01-07 20:18:30 +0000
commit40b9cffbfe62e1fc130ed8aa271182bf569e08a7 (patch)
tree5c337aead20f433e2384241a30f0ab6026374b59 /pki/base/java-tools
parent81b802dea554ca492f3a1d50c07deccc566635fd (diff)
downloadpki-40b9cffbfe62e1fc130ed8aa271182bf569e08a7.tar.gz
pki-40b9cffbfe62e1fc130ed8aa271182bf569e08a7.tar.xz
pki-40b9cffbfe62e1fc130ed8aa271182bf569e08a7.zip
Bugzilla Bug 662156 - HttpClient is hard-coded to handle only up to 5000 bytes
git-svn-id: svn+ssh://svn.fedorahosted.org/svn/pki/trunk@1711 c9f7a03b-bd48-0410-a16d-cbbf54688b0b
Diffstat (limited to 'pki/base/java-tools')
-rw-r--r--pki/base/java-tools/src/com/netscape/cmstools/HttpClient.java60
1 files changed, 36 insertions, 24 deletions
diff --git a/pki/base/java-tools/src/com/netscape/cmstools/HttpClient.java b/pki/base/java-tools/src/com/netscape/cmstools/HttpClient.java
index f81a7114a..1cfc72456 100644
--- a/pki/base/java-tools/src/com/netscape/cmstools/HttpClient.java
+++ b/pki/base/java-tools/src/com/netscape/cmstools/HttpClient.java
@@ -72,18 +72,42 @@ public class HttpClient
_secure = true;
}
+ public static byte[] getBytesFromFile(String filename) throws IOException {
+ File file = new File(filename);
+ FileInputStream is = new FileInputStream(file);
+
+ long length = file.length();
+
+ if (length > Integer.MAX_VALUE) {
+ throw new IOException("Input file " + filename +
+ " is too large. Must be smaller than " + Integer.MAX_VALUE);
+ }
+
+ byte[] bytes = new byte[(int)length];
+
+ int offset = 0;
+ int numRead = 0;
+ while (offset < bytes.length
+ && (numRead=is.read(bytes, offset, bytes.length-offset)) >= 0) {
+ offset += numRead;
+ }
+
+ if (offset < bytes.length) {
+ throw new IOException("Could not completely read file "+filename);
+ }
+
+ is.close();
+ return bytes;
+ }
+
+
public void send(String ifilename, String ofilename, String dbdir,
String nickname, String password, String servlet, String clientmode)
throws Exception
- {
- byte[] b = new byte[5000];
- FileInputStream fis = new FileInputStream(ifilename);
- int totalnum = 0;
- while (fis.available() > 0) {
- int num = fis.read(b, 0, 4999);
- totalnum += num;
- }
- System.out.println("Total number of bytes read = "+totalnum);
+ {
+ byte[] b = getBytesFromFile(ifilename);
+
+ System.out.println("Total number of bytes read = "+b.length);
DataOutputStream dos = null;
InputStream is = null;
@@ -155,7 +179,7 @@ public class HttpClient
String s = "POST "+servlet+" HTTP/1.0\r\n";
dos.writeBytes(s);
}
- dos.writeBytes("Content-length: " + totalnum + "\r\n");
+ dos.writeBytes("Content-length: " + b.length + "\r\n");
dos.writeBytes("\r\n");
dos.write(b);
dos.flush();
@@ -189,22 +213,10 @@ public class HttpClient
} catch (IOException e) {
}
fof.close();
- fis.close();
-
- b = new byte[10000];
- fis = new FileInputStream(ofilename);
- totalnum = 0;
- while (fis.available() > 0) {
- int num = fis.read(b, 0, 10000);
- totalnum += num;
- }
- System.out.println("Total number of bytes read = "+totalnum);
+ byte[] bout = getBytesFromFile(ofilename);
+ System.out.println("Total number of bytes read = "+ bout.length);
- byte[] bout = new byte[totalnum];
- for (int i=0; i<totalnum; i++) {
- bout[i] = b[i];
- }
ByteArrayOutputStream bs = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(bs);
ps.print(com.netscape.osutil.OSUtil.BtoA(bout));