1
0
mirror of https://github.com/etesync/android synced 2024-11-25 17:38:13 +00:00

Revert "Contact/event/task upload: use streams directly without extra byte[] array"

This reverts commit 3bde3758fc.
This commit is contained in:
Ricki Hirner 2016-05-26 22:04:03 +02:00
parent 9b8fc983cd
commit 0d1825cbf3
4 changed files with 10 additions and 30 deletions

View File

@ -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<String> segments = new LinkedList<>(HttpUrl.parse(url).pathSegments());

View File

@ -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

View File

@ -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()
);
}

View File

@ -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