DB ファイルをバイト配列に変換し、サーバーに保存するために Web サービスに渡したいと考えています。私のデータベースのサイズは 5 mb ですが、soap_request に追加しているときにメモリ不足の例外が発生しています....以下のようにコードを添付しています。
File file = new File(filePath);
int size = (int) file.length();
byte[] bytes = new byte[size];
Log.v(TAG, "File size in byte ==>"+size);
try {
BufferedInputStream buf = new BufferedInputStream(new FileInputStream(file));
buf.read(bytes, 0, bytes.length);
buf.close();
Log.v(TAG, "ByteArray = "+bytes.length);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
SoapObject soap_request = new SoapObject(NAMESPACE, METHOD_NAME);
fileName = "TraceBaleAndroid_"+UserID+"_"+backupDateTime+".db";
Log.v(TAG, "FileName = "+fileName);
soap_request.addProperty("_FileName", fileName);
soap_request.addProperty("_ByteArray",bytes);
soap_request.addProperty("UserID", UserID);
Log.v(TAG, "soap_request _FileName= >>"+soap_request.getProperty(0));
//Log.v(TAG, "soap_request _ByteArray= >>"+soap_request.getProperty(1));
Log.v(TAG, "soap_request UserID= >>"+soap_request.getProperty(2));
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
new MarshalBase64().register(envelope);
envelope.setOutputSoapObject(soap_request);
envelope.dotNet = true;
Log.v(TAG,"Calling webservice....");
androidHttpTransportSE = new HttpTransportSE(URL);
androidHttpTransportSE.debug = true;
androidHttpTransportSE.call(SOAP_ACTION, envelope);
Log.v(TAG,"Getting result from webservice....");
SoapObject result = (SoapObject) envelope.bodyIn;
JSONObject response = new JSONObject(result.getProperty(0).toString());
Log.v(TAG, "Web Response...." + response.get(" Result "));
if (response.get(" Result ").equals("Uploading DataBase Backup To Server successfully"))
{
flag = true;
Log.v(TAG, "Database is uploaded .........");
}
} catch (Exception e) {
e.printStackTrace();
}
finally
{
androidHttpTransportSE.reset();
}