From 0d1825cbf345d8e974567b525eff1046670c9a61 Mon Sep 17 00:00:00 2001 From: Ricki Hirner Date: Thu, 26 May 2016 22:04:03 +0200 Subject: [PATCH] Revert "Contact/event/task upload: use streams directly without extra byte[] array" This reverts commit 3bde3758fc5f45a762bbf08a55b8ba7b8a1c3c63. --- .../java/at/bitfire/davdroid/DavUtils.java | 22 ------------------- .../syncadapter/CalendarSyncManager.java | 6 +++-- .../syncadapter/ContactsSyncManager.java | 5 ++--- .../syncadapter/TasksSyncManager.java | 7 +++--- 4 files changed, 10 insertions(+), 30 deletions(-) diff --git a/app/src/main/java/at/bitfire/davdroid/DavUtils.java b/app/src/main/java/at/bitfire/davdroid/DavUtils.java index a8d04bf0..8664f467 100644 --- a/app/src/main/java/at/bitfire/davdroid/DavUtils.java +++ b/app/src/main/java/at/bitfire/davdroid/DavUtils.java @@ -12,18 +12,11 @@ import android.support.annotation.NonNull; import org.apache.commons.lang3.StringUtils; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.OutputStream; import java.util.Collections; import java.util.LinkedList; import java.util.List; -import lombok.Cleanup; import okhttp3.HttpUrl; -import okhttp3.MediaType; -import okhttp3.RequestBody; -import okio.BufferedSink; public class DavUtils { @@ -33,21 +26,6 @@ public class DavUtils { return String.format("#%06X%02X", color, alpha); } - public static RequestBody requestBody(final MediaType mediaType, @NonNull final ByteArrayOutputStream dataStream) throws IOException { - return new RequestBody() { - @Override - public MediaType contentType() { - return mediaType; - } - - @Override - public void writeTo(BufferedSink sink) throws IOException { - @Cleanup OutputStream os = sink.outputStream(); - dataStream.writeTo(os); - } - }; - } - public static String lastSegmentOfUrl(@NonNull String url) { // the list returned by HttpUrl.pathSegments() is unmodifiable, so we have to create a copy List segments = new LinkedList<>(HttpUrl.parse(url).pathSegments()); diff --git a/app/src/main/java/at/bitfire/davdroid/syncadapter/CalendarSyncManager.java b/app/src/main/java/at/bitfire/davdroid/syncadapter/CalendarSyncManager.java index 592d9b4b..488ac52e 100644 --- a/app/src/main/java/at/bitfire/davdroid/syncadapter/CalendarSyncManager.java +++ b/app/src/main/java/at/bitfire/davdroid/syncadapter/CalendarSyncManager.java @@ -39,7 +39,6 @@ import at.bitfire.davdroid.AccountSettings; import at.bitfire.davdroid.App; import at.bitfire.davdroid.ArrayUtils; import at.bitfire.davdroid.Constants; -import at.bitfire.davdroid.DavUtils; import at.bitfire.davdroid.InvalidAccountException; import at.bitfire.davdroid.R; import at.bitfire.davdroid.resource.LocalCalendar; @@ -98,7 +97,10 @@ public class CalendarSyncManager extends SyncManager { protected RequestBody prepareUpload(LocalResource resource) throws IOException, CalendarStorageException { LocalEvent local = (LocalEvent)resource; App.log.log(Level.FINE, "Preparing upload of event " + local.getFileName(), new Object[] { local.getEvent() }); - return DavUtils.requestBody(DavCalendar.MIME_ICALENDAR, local.getEvent().toStream()); + return RequestBody.create( + DavCalendar.MIME_ICALENDAR, + local.getEvent().toStream().toByteArray() + ); } @Override diff --git a/app/src/main/java/at/bitfire/davdroid/syncadapter/ContactsSyncManager.java b/app/src/main/java/at/bitfire/davdroid/syncadapter/ContactsSyncManager.java index 4d055e9a..06f2474c 100644 --- a/app/src/main/java/at/bitfire/davdroid/syncadapter/ContactsSyncManager.java +++ b/app/src/main/java/at/bitfire/davdroid/syncadapter/ContactsSyncManager.java @@ -41,7 +41,6 @@ import at.bitfire.davdroid.AccountSettings; import at.bitfire.davdroid.App; import at.bitfire.davdroid.ArrayUtils; import at.bitfire.davdroid.Constants; -import at.bitfire.davdroid.DavUtils; import at.bitfire.davdroid.HttpClient; import at.bitfire.davdroid.InvalidAccountException; import at.bitfire.davdroid.R; @@ -132,9 +131,9 @@ public class ContactsSyncManager extends SyncManager { protected RequestBody prepareUpload(LocalResource resource) throws IOException, ContactsStorageException { LocalContact local = (LocalContact)resource; App.log.log(Level.FINE, "Preparing upload of contact " + local.getFileName(), new Object[] { local.getContact() }); - return DavUtils.requestBody( + return RequestBody.create( hasVCard4 ? DavAddressBook.MIME_VCARD4 : DavAddressBook.MIME_VCARD3_UTF8, - local.getContact().toStream(hasVCard4 ? VCardVersion.V4_0 : VCardVersion.V3_0) + local.getContact().toStream(hasVCard4 ? VCardVersion.V4_0 : VCardVersion.V3_0).toByteArray() ); } diff --git a/app/src/main/java/at/bitfire/davdroid/syncadapter/TasksSyncManager.java b/app/src/main/java/at/bitfire/davdroid/syncadapter/TasksSyncManager.java index fc64748a..518d365a 100644 --- a/app/src/main/java/at/bitfire/davdroid/syncadapter/TasksSyncManager.java +++ b/app/src/main/java/at/bitfire/davdroid/syncadapter/TasksSyncManager.java @@ -19,7 +19,6 @@ import org.apache.commons.lang3.StringUtils; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; -import java.io.PipedInputStream; import java.nio.charset.Charset; import java.util.HashMap; import java.util.LinkedList; @@ -38,7 +37,6 @@ import at.bitfire.davdroid.AccountSettings; import at.bitfire.davdroid.App; import at.bitfire.davdroid.ArrayUtils; import at.bitfire.davdroid.Constants; -import at.bitfire.davdroid.DavUtils; import at.bitfire.davdroid.InvalidAccountException; import at.bitfire.davdroid.R; import at.bitfire.davdroid.resource.LocalResource; @@ -93,7 +91,10 @@ public class TasksSyncManager extends SyncManager { protected RequestBody prepareUpload(LocalResource resource) throws IOException, CalendarStorageException { LocalTask local = (LocalTask)resource; App.log.log(Level.FINE, "Preparing upload of task " + local.getFileName(), new Object[] { local.getTask() }); - return DavUtils.requestBody(DavCalendar.MIME_ICALENDAR, local.getTask().toStream()); + return RequestBody.create( + DavCalendar.MIME_ICALENDAR, + local.getTask().toStream().toByteArray() + ); } @Override