From f5efd73d33e80657b1d4af300f0916ea756e5753 Mon Sep 17 00:00:00 2001 From: Thialfihar Date: Fri, 16 Jul 2010 20:13:12 +0000 Subject: set svn:eol-style to LF for all code/resource files --- src/org/thialfihar/android/apg/DataSource.java | 176 ++++++++++++------------- 1 file changed, 88 insertions(+), 88 deletions(-) (limited to 'src/org/thialfihar/android/apg/DataSource.java') diff --git a/src/org/thialfihar/android/apg/DataSource.java b/src/org/thialfihar/android/apg/DataSource.java index 159cdb349..34583ab59 100644 --- a/src/org/thialfihar/android/apg/DataSource.java +++ b/src/org/thialfihar/android/apg/DataSource.java @@ -1,88 +1,88 @@ -package org.thialfihar.android.apg; - -import java.io.ByteArrayInputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; - -import org.thialfihar.android.apg.Apg.GeneralException; - -import android.content.Context; -import android.net.Uri; -import android.os.Environment; - -public class DataSource { - private Uri mContentUri = null; - private String mText = null; - private byte[] mData = null; - - public DataSource() { - - } - - public void setUri(Uri uri) { - mContentUri = uri; - } - - public void setUri(String uri) { - if (uri.startsWith("/")) { - setUri(Uri.parse("file://" + uri)); - } else { - setUri(Uri.parse(uri)); - } - } - - public void setText(String text) { - mText = text; - } - - public void setData(byte[] data) { - mData = data; - } - - public InputData getInputData(Context context, boolean withSize) - throws GeneralException, FileNotFoundException, IOException { - InputStream in = null; - long size = 0; - - if (mContentUri != null) { - if (mContentUri.getScheme().equals("file")) { - // get the rest after "file://" - String path = mContentUri.toString().substring(6); - if (path.startsWith(Environment.getExternalStorageDirectory().getAbsolutePath())) { - if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { - throw new GeneralException(context.getString(R.string.error_externalStorageNotReady)); - } - } - in = new FileInputStream(path); - File file = new File(path); - if (withSize) { - size = file.length(); - } - } else { - in = context.getContentResolver().openInputStream(mContentUri); - if (withSize) { - InputStream tmp = context.getContentResolver().openInputStream(mContentUri); - size = Apg.getLengthOfStream(tmp); - tmp.close(); - } - } - } else if (mText != null || mData != null) { - byte[] bytes = null; - if (mData != null) { - bytes = mData; - } else { - bytes = mText.getBytes(); - } - in = new ByteArrayInputStream(bytes); - if (withSize) { - size = bytes.length; - } - } - - return new InputData(in, size); - } - -} +package org.thialfihar.android.apg; + +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; + +import org.thialfihar.android.apg.Apg.GeneralException; + +import android.content.Context; +import android.net.Uri; +import android.os.Environment; + +public class DataSource { + private Uri mContentUri = null; + private String mText = null; + private byte[] mData = null; + + public DataSource() { + + } + + public void setUri(Uri uri) { + mContentUri = uri; + } + + public void setUri(String uri) { + if (uri.startsWith("/")) { + setUri(Uri.parse("file://" + uri)); + } else { + setUri(Uri.parse(uri)); + } + } + + public void setText(String text) { + mText = text; + } + + public void setData(byte[] data) { + mData = data; + } + + public InputData getInputData(Context context, boolean withSize) + throws GeneralException, FileNotFoundException, IOException { + InputStream in = null; + long size = 0; + + if (mContentUri != null) { + if (mContentUri.getScheme().equals("file")) { + // get the rest after "file://" + String path = mContentUri.toString().substring(6); + if (path.startsWith(Environment.getExternalStorageDirectory().getAbsolutePath())) { + if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { + throw new GeneralException(context.getString(R.string.error_externalStorageNotReady)); + } + } + in = new FileInputStream(path); + File file = new File(path); + if (withSize) { + size = file.length(); + } + } else { + in = context.getContentResolver().openInputStream(mContentUri); + if (withSize) { + InputStream tmp = context.getContentResolver().openInputStream(mContentUri); + size = Apg.getLengthOfStream(tmp); + tmp.close(); + } + } + } else if (mText != null || mData != null) { + byte[] bytes = null; + if (mData != null) { + bytes = mData; + } else { + bytes = mText.getBytes(); + } + in = new ByteArrayInputStream(bytes); + if (withSize) { + size = bytes.length; + } + } + + return new InputData(in, size); + } + +} -- cgit v1.2.3