Skip to content
This repository was archived by the owner on Mar 10, 2022. It is now read-only.

Commit bfd69dd

Browse files
author
Hideki Itakura
authored
Fixed #1438 - 2.0 DB18 Blob cannot be read (#1483)
- Added unit test for Blob.getContent with 6MB+ file.
1 parent e2cec68 commit bfd69dd

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed
507 KB
Loading

android/CouchbaseLite/src/androidTest/java/com/couchbase/lite/BlobTest.java

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
package com.couchbase.lite;
22

3+
import com.couchbase.lite.utils.IOUtils;
4+
35
import org.junit.Test;
46

7+
import java.io.IOException;
8+
import java.io.InputStream;
9+
import java.util.Arrays;
10+
11+
import static org.junit.Assert.assertEquals;
512
import static org.junit.Assert.assertFalse;
13+
import static org.junit.Assert.assertNotNull;
614
import static org.junit.Assert.assertTrue;
715

816
public class BlobTest extends BaseTest {
@@ -88,4 +96,49 @@ public void testHashCode() throws CouchbaseLiteException {
8896
assertTrue(blob1a.hashCode() == data1c.hashCode());
8997
assertTrue(data1c.hashCode() == blob1a.hashCode());
9098
}
99+
100+
@Test
101+
public void testGetContent() throws IOException, CouchbaseLiteException {
102+
byte[] bytes;
103+
104+
InputStream is = getAsset("attachment.png");
105+
try {
106+
bytes = IOUtils.toByteArray(is);
107+
} finally {
108+
is.close();
109+
}
110+
111+
Blob blob = new Blob("image/png", bytes);
112+
MutableDocument mDoc = new MutableDocument("doc1");
113+
mDoc.setBlob("blob", blob);
114+
Document doc = save(mDoc);
115+
Blob savedBlob = doc.getBlob("blob");
116+
assertNotNull(savedBlob);
117+
assertEquals("image/png", savedBlob.getContentType());
118+
byte[] content = blob.getContent();
119+
assertTrue(Arrays.equals(content, bytes));
120+
}
121+
122+
// https://github.com/couchbase/couchbase-lite-android/issues/1438
123+
@Test
124+
public void testGetContent6MBFile() throws IOException, CouchbaseLiteException {
125+
byte[] bytes;
126+
127+
InputStream is = getAsset("iTunesMusicLibrary.json");
128+
try {
129+
bytes = IOUtils.toByteArray(is);
130+
} finally {
131+
is.close();
132+
}
133+
134+
Blob blob = new Blob("application/json", bytes);
135+
MutableDocument mDoc = new MutableDocument("doc1");
136+
mDoc.setBlob("blob", blob);
137+
Document doc = save(mDoc);
138+
Blob savedBlob = doc.getBlob("blob");
139+
assertNotNull(savedBlob);
140+
assertEquals("application/json", savedBlob.getContentType());
141+
byte[] content = blob.getContent();
142+
assertTrue(Arrays.equals(content, bytes));
143+
}
91144
}

0 commit comments

Comments
 (0)