Merge pull request #32 from willshen/master

A couple cleanup and bug fix in the code base
This commit is contained in:
macdonst 2011-12-01 10:11:44 -08:00
commit 26408fabe4
3 changed files with 20 additions and 26 deletions

View File

@ -1054,7 +1054,7 @@ public class ContactAccessorSdk5 extends ContactAccessor {
if (organizations != null) { if (organizations != null) {
for (int i=0; i<organizations.length(); i++) { for (int i=0; i<organizations.length(); i++) {
JSONObject org = (JSONObject)organizations.get(i); JSONObject org = (JSONObject)organizations.get(i);
String orgId = getJsonString(org, "id");; String orgId = getJsonString(org, "id");
// This is a new organization so do a DB insert // This is a new organization so do a DB insert
if (orgId==null) { if (orgId==null) {
ContentValues contentValues = new ContentValues(); ContentValues contentValues = new ContentValues();
@ -1094,7 +1094,7 @@ public class ContactAccessorSdk5 extends ContactAccessor {
if (ims != null) { if (ims != null) {
for (int i=0; i<ims.length(); i++) { for (int i=0; i<ims.length(); i++) {
JSONObject im = (JSONObject)ims.get(i); JSONObject im = (JSONObject)ims.get(i);
String imId = getJsonString(im, "id");; String imId = getJsonString(im, "id");
// This is a new IM so do a DB insert // This is a new IM so do a DB insert
if (imId==null) { if (imId==null) {
ContentValues contentValues = new ContentValues(); ContentValues contentValues = new ContentValues();
@ -1150,7 +1150,7 @@ public class ContactAccessorSdk5 extends ContactAccessor {
if (websites != null) { if (websites != null) {
for (int i=0; i<websites.length(); i++) { for (int i=0; i<websites.length(); i++) {
JSONObject website = (JSONObject)websites.get(i); JSONObject website = (JSONObject)websites.get(i);
String websiteId = getJsonString(website, "id");; String websiteId = getJsonString(website, "id");
// This is a new website so do a DB insert // This is a new website so do a DB insert
if (websiteId==null) { if (websiteId==null) {
ContentValues contentValues = new ContentValues(); ContentValues contentValues = new ContentValues();
@ -1603,10 +1603,8 @@ public class ContactAccessorSdk5 extends ContactAccessor {
} }
} catch (RemoteException e) { } catch (RemoteException e) {
Log.e(LOG_TAG, e.getMessage(), e); Log.e(LOG_TAG, e.getMessage(), e);
newId = null;
} catch (OperationApplicationException e) { } catch (OperationApplicationException e) {
Log.e(LOG_TAG, e.getMessage(), e); Log.e(LOG_TAG, e.getMessage(), e);
newId = null;
} }
return newId; return newId;
} }

View File

@ -322,14 +322,13 @@ public class FileUtils extends Plugin {
* @param newName for the file directory to be called, if null use existing file name * @param newName for the file directory to be called, if null use existing file name
* @param move if false do a copy, if true do a move * @param move if false do a copy, if true do a move
* @return a Entry object * @return a Entry object
* @throws FileExistsException
* @throws NoModificationAllowedException * @throws NoModificationAllowedException
* @throws IOException * @throws IOException
* @throws InvalidModificationException * @throws InvalidModificationException
* @throws EncodingException * @throws EncodingException
* @throws JSONException * @throws JSONException
*/ */
private JSONObject transferTo(String fileName, JSONObject newParent, String newName, boolean move) throws JSONException, FileExistsException, NoModificationAllowedException, IOException, InvalidModificationException, EncodingException { private JSONObject transferTo(String fileName, JSONObject newParent, String newName, boolean move) throws JSONException, NoModificationAllowedException, IOException, InvalidModificationException, EncodingException {
// Check for invalid file name // Check for invalid file name
if (newName != null && newName.contains(":")) { if (newName != null && newName.contains(":")) {
throw new EncodingException("Bad file name"); throw new EncodingException("Bad file name");
@ -528,10 +527,9 @@ public class FileUtils extends Plugin {
* @return a DirectoryEntry object * @return a DirectoryEntry object
* @throws JSONException * @throws JSONException
* @throws IOException * @throws IOException
* @throws NoModificationAllowedException
* @throws InvalidModificationException * @throws InvalidModificationException
*/ */
private JSONObject moveDirectory(File srcDir, File destinationDir) throws JSONException, FileExistsException, NoModificationAllowedException, InvalidModificationException { private JSONObject moveDirectory(File srcDir, File destinationDir) throws JSONException, InvalidModificationException {
// Renaming a file to an existing directory should fail // Renaming a file to an existing directory should fail
if (destinationDir.exists() && destinationDir.isFile()) { if (destinationDir.exists() && destinationDir.isFile()) {
throw new InvalidModificationException("Can't rename a file to a directory"); throw new InvalidModificationException("Can't rename a file to a directory");

View File

@ -18,8 +18,8 @@
*/ */
package com.phonegap; package com.phonegap;
import java.io.EOFException;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import org.apache.http.HttpEntity; import org.apache.http.HttpEntity;
@ -56,27 +56,25 @@ public class HttpHandler {
return entity; return entity;
} }
private void writeToDisk(HttpEntity entity, String file) throws EOFException private void writeToDisk(HttpEntity entity, String file) throws IllegalStateException, IOException
/** /**
* writes a HTTP entity to the specified filename and location on disk * writes a HTTP entity to the specified filename and location on disk
*/ */
{ {
int i=0; int i=0;
String FilePath="/sdcard/" + file; String FilePath="/sdcard/" + file;
try { InputStream in = entity.getContent();
InputStream in = entity.getContent(); byte buff[] = new byte[1024];
byte buff[] = new byte[1024]; FileOutputStream out=
FileOutputStream out= new FileOutputStream(FilePath);
new FileOutputStream(FilePath); do {
do { int numread = in.read(buff);
int numread = in.read(buff); if (numread <= 0)
if (numread <= 0) break;
break; out.write(buff, 0, numread);
out.write(buff, 0, numread); i++;
i++; } while (true);
} while (true); out.flush();
out.flush(); out.close();
out.close();
} catch (Exception e) { e.printStackTrace(); }
} }
} }