1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-11-26 00:02:06 +01:00

Use HttpURLConnection.setFixedLengthStreamingMode(long)

now that we are on Android 19.
This commit is contained in:
Florian Schmaus 2019-08-04 23:04:00 +02:00
parent ca7529c192
commit 699905a1de

View file

@ -387,11 +387,6 @@ public final class HttpFileUploadManager extends Manager {
private void uploadFile(final File file, final Slot slot, UploadProgressListener listener) throws IOException { private void uploadFile(final File file, final Slot slot, UploadProgressListener listener) throws IOException {
final long fileSize = file.length(); final long fileSize = file.length();
// TODO Remove once Smack's minimum Android API level is 19 or higher. See also comment below.
if (fileSize >= Integer.MAX_VALUE) {
throw new IllegalArgumentException("File size " + fileSize + " must be less than " + Integer.MAX_VALUE);
}
final int fileSizeInt = (int) fileSize;
// Construct the FileInputStream first to make sure we can actually read the file. // Construct the FileInputStream first to make sure we can actually read the file.
final FileInputStream fis = new FileInputStream(file); final FileInputStream fis = new FileInputStream(file);
@ -403,8 +398,7 @@ public final class HttpFileUploadManager extends Manager {
urlConnection.setRequestMethod("PUT"); urlConnection.setRequestMethod("PUT");
urlConnection.setUseCaches(false); urlConnection.setUseCaches(false);
urlConnection.setDoOutput(true); urlConnection.setDoOutput(true);
// TODO Change to using fileSize once Smack's minimum Android API level is 19 or higher. urlConnection.setFixedLengthStreamingMode(fileSize);
urlConnection.setFixedLengthStreamingMode(fileSizeInt);
urlConnection.setRequestProperty("Content-Type", "application/octet-stream;"); urlConnection.setRequestProperty("Content-Type", "application/octet-stream;");
for (Entry<String, String> header : slot.getHeaders().entrySet()) { for (Entry<String, String> header : slot.getHeaders().entrySet()) {
urlConnection.setRequestProperty(header.getKey(), header.getValue()); urlConnection.setRequestProperty(header.getKey(), header.getValue());