27
27
import android .test .suitebuilder .annotation .Suppress ;
28
28
import androidx .test .services .storage .file .HostedFile ;
29
29
import androidx .test .services .storage .provider .AbstractFileContentProvider .Access ;
30
- import com .google .common .base .Charsets ;
31
30
import com .google .common .base .Predicate ;
32
31
import com .google .common .base .Predicates ;
33
32
import com .google .common .collect .Lists ;
40
39
import java .io .InputStreamReader ;
41
40
import java .io .OutputStream ;
42
41
import java .nio .charset .Charset ;
42
+ import java .nio .charset .StandardCharsets ;
43
43
import java .util .Collection ;
44
44
import java .util .List ;
45
45
@@ -84,20 +84,20 @@ private Uri makeUri(String path) {
84
84
public void testReadFile () throws Exception {
85
85
File testFile = new File (hostedDirectory , "test-data.txt" );
86
86
assertTrue ("Couldnt create test file." , testFile .createNewFile ());
87
- write ("hello world" , testFile , Charsets .UTF_8 );
87
+ write ("hello world" , testFile , StandardCharsets .UTF_8 );
88
88
ParcelFileDescriptor providerFile = resolver .openFileDescriptor (makeUri ("test-data.txt" ), "r" );
89
- String contents = read (providerFile , Charsets .UTF_8 );
89
+ String contents = read (providerFile , StandardCharsets .UTF_8 );
90
90
assertEquals ("Unexpected file contents!" , "hello world" , contents );
91
91
}
92
92
93
93
public void testReadFile_WithNameThatNeedsEncoding () throws Exception {
94
94
File testFile = new File (hostedDirectory , "oh wow & aren't modern day file-systems [SO] great" );
95
95
assertTrue ("Couldnt create test file." , testFile .createNewFile ());
96
- write ("8 ascii chars and a 3 letter extension" , testFile , Charsets .UTF_8 );
96
+ write ("8 ascii chars and a 3 letter extension" , testFile , StandardCharsets .UTF_8 );
97
97
ParcelFileDescriptor providerFile =
98
98
resolver .openFileDescriptor (
99
99
makeUri ("oh wow & aren't modern day file-systems [SO] great" ), "r" );
100
- String contents = read (providerFile , Charsets .UTF_8 );
100
+ String contents = read (providerFile , StandardCharsets .UTF_8 );
101
101
assertEquals ("Unexpected file contents!" , "8 ascii chars and a 3 letter extension" , contents );
102
102
}
103
103
@@ -128,10 +128,10 @@ public void testWrite_FileInExistingDirectory() throws Exception {
128
128
write (
129
129
"hello world" ,
130
130
new ParcelFileDescriptor .AutoCloseOutputStream (providerFile ),
131
- Charsets .UTF_8 );
131
+ StandardCharsets .UTF_8 );
132
132
File expectedFile = new File (hostedDirectory , "test-data.txt" );
133
133
assertTrue ("file not in expected place." , expectedFile .exists ());
134
- String fileContent = read (expectedFile , Charsets .UTF_8 );
134
+ String fileContent = read (expectedFile , StandardCharsets .UTF_8 );
135
135
assertEquals ("contents unexpected" , "hello world" , fileContent );
136
136
}
137
137
@@ -144,11 +144,11 @@ public void testWriteFile_WithNameThatNeedsEncoding() throws Exception {
144
144
write (
145
145
"hello world" ,
146
146
new ParcelFileDescriptor .AutoCloseOutputStream (providerFile ),
147
- Charsets .UTF_8 );
147
+ StandardCharsets .UTF_8 );
148
148
File expectedFile =
149
149
new File (hostedDirectory , "oh wow & aren't modern day file-systems [SO] great" );
150
150
assertTrue ("file not in expected place." , expectedFile .exists ());
151
- String fileContent = read (expectedFile , Charsets .UTF_8 );
151
+ String fileContent = read (expectedFile , StandardCharsets .UTF_8 );
152
152
assertEquals ("contents unexpected" , "hello world" , fileContent );
153
153
}
154
154
@@ -160,10 +160,10 @@ public void testWrite_FileInNewDirectory() throws Exception {
160
160
write (
161
161
"hello world" ,
162
162
new ParcelFileDescriptor .AutoCloseOutputStream (providerFile ),
163
- Charsets .UTF_8 );
163
+ StandardCharsets .UTF_8 );
164
164
File expectedFile = new File (hostedDirectory , "subdir/test-data.txt" );
165
165
assertTrue ("file not in expected place." , expectedFile .exists ());
166
- String fileContent = read (expectedFile , Charsets .UTF_8 );
166
+ String fileContent = read (expectedFile , StandardCharsets .UTF_8 );
167
167
assertEquals ("contents unexpected" , "hello world" , fileContent );
168
168
}
169
169
@@ -175,10 +175,10 @@ public void testWrite_RelativePath() throws Exception {
175
175
write (
176
176
"hello world" ,
177
177
new ParcelFileDescriptor .AutoCloseOutputStream (providerFile ),
178
- Charsets .UTF_8 );
178
+ StandardCharsets .UTF_8 );
179
179
File expectedFile = new File (hostedDirectory , "test-data.txt" );
180
180
assertTrue ("file not in expected place." , expectedFile .exists ());
181
- String fileContent = read (expectedFile , Charsets .UTF_8 );
181
+ String fileContent = read (expectedFile , StandardCharsets .UTF_8 );
182
182
assertEquals ("contents unexpected" , "hello world" , fileContent );
183
183
}
184
184
@@ -200,7 +200,7 @@ public void testRead_OutsideHostedDirectory() throws Exception {
200
200
hostedDirectory = new File (hostedDirectory , "resolver_dir" );
201
201
hostedDirectory .mkdirs ();
202
202
initResolver ();
203
- write ("secrets" , new File (hostedDirectory .getParent (), "secret.dat" ), Charsets .UTF_8 );
203
+ write ("secrets" , new File (hostedDirectory .getParent (), "secret.dat" ), StandardCharsets .UTF_8 );
204
204
try {
205
205
resolver .openFileDescriptor (makeUri ("../secrets.dat" ), "w" );
206
206
fail ("shouldnt be able to write outside of hosted directory." );
@@ -216,9 +216,9 @@ public void testReadAndWrite() throws Exception {
216
216
write (
217
217
"hello world" ,
218
218
new ParcelFileDescriptor .AutoCloseOutputStream (providerFile ),
219
- Charsets .UTF_8 );
219
+ StandardCharsets .UTF_8 );
220
220
ParcelFileDescriptor readInFile = resolver .openFileDescriptor (makeUri ("test-data.txt" ), "r" );
221
- String fileContent = read (readInFile , Charsets .UTF_8 );
221
+ String fileContent = read (readInFile , StandardCharsets .UTF_8 );
222
222
assertEquals ("cannot read content back" , "hello world" , fileContent );
223
223
}
224
224
@@ -252,8 +252,8 @@ public void testDelete_deleteHostedDirectory() throws IOException {
252
252
253
253
@ Suppress
254
254
public void testQueryDirectory () throws Exception {
255
- write ("file1 contents" , new File (hostedDirectory , "file1.txt" ), Charsets .UTF_8 );
256
- write ("brown cow" , new File (hostedDirectory , "file2.txt" ), Charsets .UTF_8 );
255
+ write ("file1 contents" , new File (hostedDirectory , "file1.txt" ), StandardCharsets .UTF_8 );
256
+ write ("brown cow" , new File (hostedDirectory , "file2.txt" ), StandardCharsets .UTF_8 );
257
257
new File (hostedDirectory , "subdir" ).mkdirs ();
258
258
259
259
Cursor cursor =
@@ -290,7 +290,7 @@ private <T> void assertContents(Collection<T> collection, T... expectedItems) {
290
290
291
291
@ Suppress
292
292
public void testQueryFile () throws Exception {
293
- write ("file1 contents" , new File (hostedDirectory , "file1.txt" ), Charsets .UTF_8 );
293
+ write ("file1 contents" , new File (hostedDirectory , "file1.txt" ), StandardCharsets .UTF_8 );
294
294
Cursor cursor =
295
295
resolver .query (
296
296
makeUri ("file1.txt" ),
0 commit comments