我已将我的 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();
}