summaryrefslogtreecommitdiff
path: root/java/src/com/zerotier/one/AndroidFileProvider.java
blob: 0988f9dfa4ea459a6ae53d06f8f81129e7d36952 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package com.zerotier.one;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

import android.content.Context;
import android.util.Log;

public class AndroidFileProvider implements DataStoreFileProvider {
	private static final String TAG = "AndroidFileProvider";

	Context _ctx;
		
	public AndroidFileProvider(Context ctx) {
		this._ctx = ctx;
	}

	@Override
	public FileInputStream getInputFileStream(String name)
			throws FileNotFoundException {
		Log.d(TAG, "Returning FileInputStream for: " + name);
		return _ctx.openFileInput(name);
	}

	@Override
	public FileOutputStream getOutputFileStream(String name)
			throws FileNotFoundException {
		Log.d(TAG, "Returning FileOutputStream for: " + name);
		return _ctx.openFileOutput(name, Context.MODE_PRIVATE);
	}

	@Override
	public void deleteFile(String name) throws IOException {
		boolean success = _ctx.deleteFile(name);
		if(!success)
		{
			throw new IOException("Unable to delete file.");
		}
	}

}