summaryrefslogtreecommitdiff
path: root/src/de
diff options
context:
space:
mode:
Diffstat (limited to 'src/de')
-rw-r--r--src/de/blinkt/openvpn/FileSelect.java45
-rw-r--r--src/de/blinkt/openvpn/FileSelectLayout.java10
-rw-r--r--src/de/blinkt/openvpn/Settings_Basic.java2
3 files changed, 42 insertions, 15 deletions
diff --git a/src/de/blinkt/openvpn/FileSelect.java b/src/de/blinkt/openvpn/FileSelect.java
index b76dbc93..0778b56b 100644
--- a/src/de/blinkt/openvpn/FileSelect.java
+++ b/src/de/blinkt/openvpn/FileSelect.java
@@ -5,6 +5,7 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
+import java.io.InputStream;
import android.app.ActionBar;
import android.app.ActionBar.Tab;
@@ -16,6 +17,7 @@ import android.app.FragmentTransaction;
import android.content.Intent;
import android.os.Bundle;
import android.os.Environment;
+import android.util.Base64;
public class FileSelect extends Activity {
public static final String RESULT_DATA = "RESULT_PATH";
@@ -23,6 +25,8 @@ public class FileSelect extends Activity {
public static final String WINDOW_TITLE = "WINDOW_TILE";
public static final String NO_INLINE_SELECTION = "de.blinkt.openvpn.NO_INLINE_SELECTION";
public static final String SHOW_CLEAR_BUTTON = "de.blinkt.openvpn.SHOW_CLEAR_BUTTON";
+ public static final String DO_BASE64_ENCODE = "de.blinkt.openvpn.BASE64ENCODE";
+
private FileSelectionFragment mFSFragment;
private InlineFileTab mInlineFragment;
private String mData;
@@ -30,6 +34,7 @@ public class FileSelect extends Activity {
private Tab fileExplorerTab;
private boolean mNoInline;
private boolean mShowClear;
+ private boolean mBase64Encode;
public void onCreate(Bundle savedInstanceState)
@@ -50,6 +55,7 @@ public class FileSelect extends Activity {
mNoInline = getIntent().getBooleanExtra(NO_INLINE_SELECTION, false);
mShowClear = getIntent().getBooleanExtra(SHOW_CLEAR_BUTTON, false);
+ mBase64Encode = getIntent().getBooleanExtra(DO_BASE64_ENCODE, false);
ActionBar bar = getActionBar();
bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
@@ -114,16 +120,15 @@ public class FileSelect extends Activity {
File ifile = new File(path);
Exception fe = null;
try {
- FileInputStream fis = new FileInputStream(ifile);
- String data =VpnProfile.INLINE_TAG;
- byte buf[] =new byte[16384];
- int len=fis.read(buf);
- while(len >0) {
- data += new String(buf,0,len);
- len=fis.read(buf);
- }
- fis.close();
+ String data =VpnProfile.INLINE_TAG;
+
+ byte[] filedata = readBytesFromFile(ifile) ;
+ if(mBase64Encode)
+ data += Base64.encodeToString(filedata, Base64.DEFAULT);
+ else
+ data += new String(filedata);
+
mData =data;
mInlineFragment.setData(data);
getActionBar().selectTab(inlineFileTab);
@@ -141,6 +146,28 @@ public class FileSelect extends Activity {
}
}
+ private byte[] readBytesFromFile(File file) throws IOException {
+ InputStream input = new FileInputStream(file);
+
+ long len= file.length();
+
+
+ // Create the byte array to hold the data
+ byte[] bytes = new byte[(int) len];
+
+ // Read in the bytes
+ int offset = 0;
+ int bytesRead = 0;
+ while (offset < bytes.length
+ && (bytesRead=input.read(bytes, offset, bytes.length-offset)) >= 0) {
+ offset += bytesRead;
+ }
+
+ input.close();
+ return bytes;
+ }
+
+
public void setFile(String path) {
Intent intent = new Intent();
intent.putExtra(RESULT_DATA, path);
diff --git a/src/de/blinkt/openvpn/FileSelectLayout.java b/src/de/blinkt/openvpn/FileSelectLayout.java
index fb563f5d..93e438fc 100644
--- a/src/de/blinkt/openvpn/FileSelectLayout.java
+++ b/src/de/blinkt/openvpn/FileSelectLayout.java
@@ -19,7 +19,7 @@ public class FileSelectLayout extends LinearLayout implements OnClickListener {
private Fragment mFragment;
private int mTaskId;
private Button mSelectButton;
- private boolean mNoInline;
+ private boolean mBase64Encode;
private String mTitle;
private boolean mShowClear;
@@ -50,8 +50,8 @@ public class FileSelectLayout extends LinearLayout implements OnClickListener {
Intent startFC = new Intent(getContext(),FileSelect.class);
startFC.putExtra(FileSelect.START_DATA, mData);
startFC.putExtra(FileSelect.WINDOW_TITLE,mTitle);
- if(mNoInline)
- startFC.putExtra(FileSelect.NO_INLINE_SELECTION, true);
+ if(mBase64Encode)
+ startFC.putExtra(FileSelect.DO_BASE64_ENCODE, true);
if(mShowClear)
startFC.putExtra(FileSelect.SHOW_CLEAR_BUTTON, true);
mFragment.startActivityForResult(startFC,mTaskId);
@@ -80,8 +80,8 @@ public class FileSelectLayout extends LinearLayout implements OnClickListener {
}
}
- public void setNoline() {
- mNoInline=true;
+ public void setBase64Encode() {
+ mBase64Encode =true;
}
public void setShowClear() {
diff --git a/src/de/blinkt/openvpn/Settings_Basic.java b/src/de/blinkt/openvpn/Settings_Basic.java
index c99bb4df..9c85094a 100644
--- a/src/de/blinkt/openvpn/Settings_Basic.java
+++ b/src/de/blinkt/openvpn/Settings_Basic.java
@@ -126,7 +126,7 @@ public class Settings_Basic extends Fragment implements View.OnClickListener, On
addFileSelectLayout(mClientCert);
addFileSelectLayout(mClientKey);
addFileSelectLayout(mpkcs12);
- mpkcs12.setNoline();
+ mpkcs12.setBase64Encode();
mCaCert.setShowClear();