I have written an Android application which downloads pdf files through web service. I am using kSoap2 android library to parse the response of web service which basically contains file name & file data.
I have written following code. Please review & tell how to increase the speed I think there is some small defect in code which reduces the speed. I am using version 2.5.1 of kSoap2.
public void downloadPdfFiles(File fileDocsDir, int noOfFiles)
throws NullPointerException, SoapFault, XmlPullParserException,
FileNotFoundException, IOException, Exception {
System.gc();
// Download files from web service and save them in the folder.
soapObject = new SoapObject(NAMESPACE, METHOD_NAME);
soapObject.addProperty("startingFile", noOfFiles);
soapObject.addProperty("deviceId", deviceId);
soapObject.addProperty("loginId", loginId);
soapObject.addProperty("byoinId", "1");
envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(soapObject);
// Calling the web service
System.gc();
androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.call(SOAP_ACTION, envelope);
// Getting Response through xml mainly generated as soap:reponse.
responseBean = (SoapObject) envelope.getResponse();
// Array of PDFInfoBean.
list = (SoapObject) responseBean.getProperty(0);
FileOutputStream outputStream = null;
BufferedOutputStream bufferedOutputStream = null;
// Get Individual PDF Details from Array.
SoapObject pdfDetails = null;
mIncrement = noOfFiles;
// Log.i("Increment Values", String.valueOf(mIncrement));
File pdfFile = null;
for (int i = 0; i < list.getPropertyCount(); i++) {
pdfDetails = (SoapObject) list.getProperty(i);
// Get PDF File Name.
pdfDocName = pdfDetails.getProperty(1).toString();
Log.i(TAG, "File Name: " + pdfDocName);
// Check for last file.
if (pdfDocName.equalsIgnoreCase("EOF")) {
mFlag = false;
break;
}
// Creating PDF File.
pdfFile = new File(fileDocsDir, pdfDocName);
// Writing PDF file received through web service.
if (pdfFile.exists()) {
Log.i(TAG, pdfFile.getName() + " File Already Exists");
} else {
outputStream = new FileOutputStream(pdfFile);
bufferedOutputStream = new BufferedOutputStream(outputStream);
bufferedOutputStream.write(Base64Coder.decode(pdfDetails
.getProperty(0).toString()));
mIncrement = mIncrement + 1;
bufferedOutputStream.close();
outputStream.close();
bufferedOutputStream = null;
outputStream = null;
}
pdfDetails = null;
pdfDocName = null;
pdfFile = null;
System.gc();
}
soapObject = null;
envelope = null;
responseBean = null;
list = null;
androidHttpTransport = null;
System.gc();
}