final String xmlFile = getXmlFile();
if (xmlFile != null && xmlFile.length() > 0) {
// We just add placeholder text for file content
postedBody.append("Filename: ").append(xmlFile).append("\n");
postedBody.append("<actual file content, not shown here>");
post.setRequestEntity(new RequestEntity() {
public boolean isRepeatable() {
return true;
}
public void writeRequest(OutputStream out) throws IOException {
InputStream in = null;
try{
in = new FileInputStream(xmlFile);
IOUtils.copy(in, out);
out.flush();
} finally {
IOUtils.closeQuietly(in);
}
}
public long getContentLength() {
switch(length){
case -1:
return -1;
case 0: // No header provided
return (new File(xmlFile)).length();
default:
return length;
}
}
public String getContentType() {
// TODO do we need to add a charset for the file contents?
return DEFAULT_CONTENT_TYPE; // $NON-NLS-1$
}
});
} else {
postedBody.append(getXmlData());
post.setRequestEntity(new RequestEntity() {
public boolean isRepeatable() {
return true;
}
public void writeRequest(OutputStream out) throws IOException {