Commit 771f9f82 authored by lxnhan's avatar lxnhan

commit

parents

Too many changes to show.

To preserve performance only 1000 of 1000+ files are displayed.

## 0.0.1
* TODO: Describe initial release.
TODO: Add your license here.
# Flutter FileReader
<!-- [![pub package](https://git.myitsol.com/seabank-base/file_reader)](https://git.myitsol.com/seabank-base/file_reader) -->
##### A local file view widget,Support a variety of file types, such as Doc Eexcl PPT TXT and so on
## Depend on it
Add this to your package's pubspec.yaml file:
0.0.1
```yaml
dependencies:
file_reader:
git:
url: https://git.myitsol.com/seabank-base/file_reader.git
```
## Support File Type
* IOS `docx,doc,xlsx,xls,pptx,ppt,pdf,txt,jpg,jpeg,png`
* Android `docx,doc,xlsx,xls,pptx,ppt,pdf,txt`
## Usage
### Android
### IOS
### WEB
### Example
```yaml
import 'package:flutter/material.dart';
import 'package:file_reader/file_reader.dart';
class FileReaderPage extends StatefulWidget {
final String filePath;
FileReaderPage({Key: Key, this.filePath});
@override
_FileReaderPageState createState() => _FileReaderPageState();
}
class _FileReaderPageState extends State<FileReaderPage> {
Future<void> viewFile() async {
FileReader.openFile("https://gitee.com/kongkongss/flutter_file_preview/raw/master/test/docs/test_file_for.docx", localSizePermission: "Cho xin it quyen", title: "chi tiet file");
#FileReader.openFile(path, localSizePermission: "Cho xin it quyen", title: "chi tiet file");
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("doc"),
),
body: TextButton("ReadFile", onClick:(){
viewFile()}),
);
}
}
\ No newline at end of file
include: package:flutter_lints/flutter.yaml
# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options
*.iml
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures
# Default ignored files
/shelf/
/workspace.xml
file_reader
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<bytecodeTargetLevel target="11" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GradleMigrationSettings" migrationVersion="1" />
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<option name="testRunner" value="GRADLE" />
<option name="distributionType" value="DEFAULT_WRAPPED" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />
<option value="$PROJECT_DIR$/office" />
</set>
</option>
<option name="resolveModulePerSourceSet" value="false" />
</GradleProjectSettings>
</option>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RemoteRepositoriesConfiguration">
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Maven Central repository" />
<option name="url" value="https://repo1.maven.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="jboss.community" />
<option name="name" value="JBoss Community repository" />
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
</remote-repository>
<remote-repository>
<option name="id" value="MavenRepo" />
<option name="name" value="MavenRepo" />
<option name="url" value="https://repo.maven.apache.org/maven2/" />
</remote-repository>
<remote-repository>
<option name="id" value="BintrayJCenter" />
<option name="name" value="BintrayJCenter" />
<option name="url" value="https://jcenter.bintray.com/" />
</remote-repository>
<remote-repository>
<option name="id" value="maven" />
<option name="name" value="maven" />
<option name="url" value="https://jitpack.io" />
</remote-repository>
<remote-repository>
<option name="id" value="Google" />
<option name="name" value="Google" />
<option name="url" value="https://dl.google.com/dl/android/maven2/" />
</remote-repository>
<remote-repository>
<option name="id" value="maven2" />
<option name="name" value="maven2" />
<option name="url" value="https://repository.aspose.com/repo/" />
</remote-repository>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="DesignSurface">
<option name="filePathToZoomLevelMap">
<map>
<entry key="office/src/main/res/drawable/bg_office.xml" value="0.3675925925925926" />
<entry key="office/src/main/res/layout/activity_office.xml" value="0.32715477293790546" />
<entry key="office/src/main/res/layout/view_fab.xml" value="0.3605072463768116" />
</map>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="Android Studio default JDK" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">
<option name="id" value="Android" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/modules/file_reader.iml" filepath="$PROJECT_DIR$/.idea/modules/file_reader.iml" />
<module fileurl="file://$PROJECT_DIR$/.idea/modules/office/file_reader.office.iml" filepath="$PROJECT_DIR$/.idea/modules/office/file_reader.office.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
</component>
</project>
\ No newline at end of file
group 'vn.itsol.filereader.file_reader'
version '1.0'
buildscript {
ext.kotlin_version = '1.5.10'
repositories {
google()
jcenter()
mavenCentral()
maven { url "https://repository.aspose.com/repo/" }
maven { url 'https://jitpack.io' }
}
dependencies {
classpath 'com.android.tools.build:gradle:4.1.0'
classpath 'com.google.gms:google-services:4.3.10'
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version")
}
}
rootProject.allprojects {
repositories {
google()
mavenCentral()
jcenter()
maven { url "https://repository.aspose.com/repo/" }
maven { url 'https://jitpack.io' }
}
}
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 31
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
defaultConfig {
minSdkVersion 21
}
ndkVersion '22.1.7171670'
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.5.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
implementation (
group: 'com.aspose',
name: 'aspose-cells',
version: '22.3',
classifier: 'android.via.java')
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
implementation 'com.intuit.sdp:sdp-android:1.0.6'
implementation 'com.google.android.play:core:1.10.2'
def lifecycle_version = "2.0.0"
implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-runtime:$lifecycle_version"
annotationProcessor "androidx.lifecycle:lifecycle-compiler:$lifecycle_version"
//pdf_creator_dependecy
implementation 'androidx.vectordrawable:vectordrawable-animated:1.1.0'
implementation 'androidx.exifinterface:exifinterface:1.3.2'
implementation 'androidx.multidex:multidex:2.0.1'
implementation 'androidx.legacy:legacy-support-v13:1.0.0'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.recyclerview:recyclerview:1.2.1'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.preference:preference:1.1.1'
// butterknife
implementation 'com.jakewharton:butterknife:10.2.3'
annotationProcessor 'com.jakewharton:butterknife-compiler:10.2.3'
// persistence room library - for db operations
implementation 'androidx.room:room-runtime:2.3.0'
annotationProcessor 'androidx.room:room-compiler:2.3.0'
// material ripple, morphing button, material dialog, animations
implementation 'com.balysv:material-ripple:1.0.2'
implementation 'com.github.dmytrodanylyk:android-morphing-button:98a4986e56'
implementation 'com.afollestad.material-dialogs:core:0.9.6.0'
implementation 'com.airbnb.android:lottie:2.5.5'
// libraries for reading from doc and docx files
implementation group: 'org.apache.xmlbeans', name: 'xmlbeans', version: '2.4.0'
implementation group: 'org.apache.poi', name: 'poi', version: '3.9'
implementation group: 'org.apache.poi', name: 'poi-ooxml', version: '3.9'
implementation group: 'org.apache.poi', name: 'poi-ooxml-schemas', version: '3.9'
implementation group: 'org.apache.poi', name: 'poi-scratchpad', version: '3.9'
// Itext pdf library
implementation 'com.itextpdf:itextg:5.5.10'
implementation 'com.madgag.spongycastle:core:1.58.0.0'
// Picasso, image editor, image cropper
implementation 'com.squareup.picasso:picasso:2.5.2'
implementation 'jp.wasabeef:picasso-transformations:2.2.1'
implementation 'ja.burhanrashid52:photoeditor:0.2.1'
implementation 'com.theartofdev.edmodo:android-image-cropper:2.8.0'
// Viewpager transformation
implementation 'com.eftimoff:android-viewpager-transformers:1.0.1@aar'
// Image picker, and folder picker
implementation 'com.zhihu.android:matisse:0.5.3-beta3'
implementation 'lib.kashif:folderpicker:2.4'
// Zxing - for scanning qr code
implementation 'com.google.zxing:core:3.3.3'
implementation 'com.journeyapps:zxing-android-embedded:3.4.0'
// color picker
implementation 'com.github.danielnilsson9:color-picker-view:1.4.0@aar'
androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0', {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'com.google.android.material:material:1.1.0'
implementation 'com.github.Stericson:RootShell:1.6'
implementation 'com.github.SimpleMobileTools:Simple-Commons:d39bf6263d'
implementation 'io.github.elye:loaderviewlibrary:3.0.0'
implementation "com.github.danielemaddaluno.androidupdatechecker:library:+"
implementation 'com.intuit.sdp:sdp-android:1.0.6'
implementation 'com.android.support:multidex:2.0.0'
implementation 'com.github.barteksc:android-pdf-viewer:3.1.0-beta.1'
implementation "androidx.core:core-ktx:+"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.isseiaoki:simplecropview:1.1.8'
implementation 'de.hdodenhof:circleimageview:3.1.0'
implementation "androidx.exifinterface:exifinterface:1.3.3"
implementation 'com.github.novatien:SmartColorPicker:1.0.2'
implementation "com.android.billingclient:billing:4.0.0"
implementation 'pub.devrel:easypermissions:1.2.0'
implementation 'com.github.Stericson:RootTools:df729dcb13'
implementation 'com.squareup.okio:okio:1.13.0'
implementation 'com.squareup.okhttp3:okhttp:3.10.0'
implementation 'com.squareup.retrofit2:retrofit:2.1.0'
implementation 'com.squareup.retrofit2:converter-gson:2.1.0'
}
\ No newline at end of file
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
#!/usr/bin/env sh
#
# Copyright 2015 the original author or authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
##############################################################################
##
## Gradle start up script for UN*X
##
##############################################################################
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null
APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
warn () {
echo "$*"
}
die () {
echo
echo "$*"
echo
exit 1
}
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
nonstop=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
NONSTOP* )
nonstop=true
;;
esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD="java"
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
MAX_FD="$MAX_FD_LIMIT"
fi
ulimit -n $MAX_FD
if [ $? -ne 0 ] ; then
warn "Could not set maximum file descriptor limit: $MAX_FD"
fi
else
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi
# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi
# For Cygwin or MSYS, switch paths to Windows format before running java
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`
# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
SEP=""
for dir in $ROOTDIRSRAW ; do
ROOTDIRS="$ROOTDIRS$SEP$dir"
SEP="|"
done
OURCYGPATTERN="(^($ROOTDIRS))"
# Add a user-defined pattern to the cygpath arguments
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
fi
# Now convert the arguments - kludge to limit ourselves to /bin/sh
i=0
for arg in "$@" ; do
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
else
eval `echo args$i`="\"$arg\""
fi
i=`expr $i + 1`
done
case $i in
0) set -- ;;
1) set -- "$args0" ;;
2) set -- "$args0" "$args1" ;;
3) set -- "$args0" "$args1" "$args2" ;;
4) set -- "$args0" "$args1" "$args2" "$args3" ;;
5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi
# Escape application args
save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
APP_ARGS=`save "$@"`
# Collect all arguments for the java command, following the shell quoting and substitution rules
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
exec "$JAVACMD" "$@"
@rem
@rem Copyright 2015 the original author or authors.
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem https://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto execute
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto execute
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega
rootProject.name = 'file_reader'
\ No newline at end of file
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.office.allreader.allofficefilereader" xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" tools:ignore="ScopedStorage" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:hardwareAccelerated="true"
android:requestLegacyExternalStorage="true"
>
<activity
android:name="com.office.reader.viewer.activity.PdfViewerActivity"
android:exported="true" android:theme="@style/AppTheme" />
<activity
android:name="com.office.reader.viewer.activity.ScreenShotViewerActivity"
android:exported="true" android:theme="@style/AppTheme" />
<activity
android:name="com.office.reader.viewer.activity.OfficeViewerActivity"
android:exported="true"
android:launchMode="singleInstance" android:theme="@style/AppTheme"/>
</application>
</manifest>
package com.office.allreader.allofficefilereader.database;
import android.content.Context;
import android.content.SharedPreferences;
public class MyPreferences {
private static final String IS_FIRST_TIME_LAUNCH = "IsFirstTimeLaunch";
private static final String KEY_PREF_IN_APP_IS_ITEM_PURCHASE = "KEY_PREF_IN_APP_IS_ITEM_PURCHASE";
private static final String KEY_PREF_IN_APP_REVIEW = "KEY_PREF_IN_APP_REVIEW";
private static final String KEY_PREF_LANGUAGE_SELECTED = "KEY_PREF_LANGUAGE_SELECTED";
private static final String getOrderId = "getOrderId";
private static final String getPackageName = "getPackageName";
Context _context;
SharedPreferences.Editor editor;
SharedPreferences pref;
public MyPreferences(Context context) {
this._context = context;
SharedPreferences sharedPreferences = context.getSharedPreferences("com.allreader.office.allofficefilereader", 0);
this.pref = sharedPreferences;
this.editor = sharedPreferences.edit();
}
public void setFirstTimeLaunch(boolean z) {
this.editor.putBoolean(IS_FIRST_TIME_LAUNCH, z);
this.editor.commit();
}
public boolean isFirstTimeLaunch() {
return this.pref.getBoolean(IS_FIRST_TIME_LAUNCH, true);
}
public void setLanguageSelected(boolean z) {
this.editor.putBoolean(KEY_PREF_LANGUAGE_SELECTED, z);
this.editor.commit();
}
public boolean isLanguageSelected() {
return this.pref.getBoolean(KEY_PREF_LANGUAGE_SELECTED, false);
}
public boolean isItemPurchased() {
return this.pref.getBoolean(KEY_PREF_IN_APP_IS_ITEM_PURCHASE, false);
}
public void setGetOrderId(String str) {
this.editor.putString(str, str);
this.editor.commit();
}
public String getGetOrderId() {
return this.pref.getString(getOrderId, null);
}
public void setGetPackageName(String str) {
this.editor.putString(str, str);
this.editor.commit();
}
public String getGetPackageName() {
return this.pref.getString(getPackageName, null);
}
public void setKEY_PREF_IN_APP_REVIEW(boolean z) {
this.editor.putBoolean(KEY_PREF_IN_APP_REVIEW, z);
this.editor.commit();
}
public boolean isKEY_PREF_IN_APP_REVIEW() {
return this.pref.getBoolean(KEY_PREF_IN_APP_REVIEW, false);
}
}
package com.office.allreader.allofficefilereader.fc;
public class EncryptedDocumentException extends IllegalStateException
{
public EncryptedDocumentException(String s) {
super(s);
}
}
/*
* 文件名称: FCKkit.java
*
* 编译器: android2.2
* 时间: 下午4:51:48
*/
package com.office.allreader.allofficefilereader.fc;
import android.graphics.Color;
/**
* 此类只能放一些转换类算法,不能转换任何形式的数据
* <p>
* <p>
* Read版本: Read V1.0
* <p>
* 作者: ljj8494
* <p>
* 日期: 2014年1月23日
* <p>
* 负责人: ljj8494
* <p>
* 负责小组:
* <p>
* <p>
*/
public class FCKit
{
/**
*
* @param val
* @return
*/
public static int convertColor(String val)
{
if ("yellow".equals(val))
{
return Color.YELLOW;
}
else if ("green".equals(val))
{
return Color.GREEN;
}
else if ("cyan".equals(val))
{
return Color.CYAN;
}
else if ("magenta".equals(val))
{
return Color.MAGENTA;
}
else if ("blue".equals(val))
{
return Color.BLUE;
}
else if ("red".equals(val))
{
return Color.RED;
}
else if ("darkBlue".equals(val))
{
return 0xFF00008B;
}
else if ("darkCyan".equals(val))
{
return 0xFF008B8B;
}
else if ("darkGreen".equals(val))
{
return 0xFF006400;
}
else if ("darkMagenta".equals(val))
{
return 0xFF800080;
}
else if ("darkRed".equals(val))
{
return 0xFF8B0000;
}
else if ("darkYellow".equals(val))
{
return 0xFF808000;
}
else if ("darkGray".equals(val))
{
return Color.DKGRAY;
}
else if ("lightGray".equals(val))
{
return Color.LTGRAY;
}
else if ("black".equals(val))
{
return Color.BLACK;
}
return -1;
}
/**
* BGR to RGB
*/
public static int BGRtoRGB(int color)
{
// 颜色
int argbValue = color;
if (argbValue == -1 || argbValue == 0xFFFFFF)
{
argbValue = Color.BLACK;
}
else
{
int bgrValue = argbValue & 0x00FFFFFF;
argbValue = 0xFF000000 | (bgrValue & 0x0000FF ) << 16 | ( bgrValue & 0x00FF00 ) | ( bgrValue & 0xFF0000 ) >> 16;
}
return argbValue;
}
}
package com.office.allreader.allofficefilereader.fc;
import java.util.Map;
import com.office.allreader.allofficefilereader.common.autoshape.AutoShapeDataKit;
import com.office.allreader.allofficefilereader.common.bg.BackgroundAndFill;
import com.office.allreader.allofficefilereader.common.borders.Line;
import com.office.allreader.allofficefilereader.constant.MainConstant;
import com.office.allreader.allofficefilereader.fc.dom4j.Element;
import com.office.allreader.allofficefilereader.fc.openxml4j.opc.PackagePart;
import com.office.allreader.allofficefilereader.fc.openxml4j.opc.ZipPackage;
import com.office.allreader.allofficefilereader.fc.ppt.reader.BackgroundReader;
import com.office.allreader.allofficefilereader.fc.ppt.reader.ReaderKit;
import com.office.allreader.allofficefilereader.pg.model.PGMaster;
import com.office.allreader.allofficefilereader.system.IControl;
public class LineKit
{
/**
* smart
* @param control
* @param zipPackage
* @param packagePart
* @param pgMaster
* @param ln
* @return
* @throws Exception
*/
public static Line createLine(IControl control, ZipPackage zipPackage, PackagePart packagePart, PGMaster pgMaster, Element ln) throws Exception
{
int lineWidth = 1;
boolean dash = false;
BackgroundAndFill lineFill = null;
if (ln != null)
{
//border
if (ln.element("noFill") == null)
{
//line width
if(ln.attributeValue("w") != null)
{
lineWidth = Math.round(Integer.parseInt(ln.attributeValue("w")) * MainConstant.PIXEL_DPI / MainConstant.EMU_PER_INCH);
}
Element prstDash = ln.element("prstDash");
if(prstDash != null && !"solid".equalsIgnoreCase(prstDash.attributeValue("val")))
{
dash = true;
}
lineFill = BackgroundReader.instance().processBackground(control, zipPackage, packagePart, pgMaster, ln);
if(lineFill != null)
{
Line line = new Line();
line.setBackgroundAndFill(lineFill);
line.setLineWidth(lineWidth);
line.setDash(dash);
return line;
}
}
}
return null;
}
/**
* ppt and smart
* @param control
* @param zipPackage
* @param packagePart
* @param pgMaster
* @param sp
* @return
* @throws Exception
*/
public static Line createShapeLine(IControl control, ZipPackage zipPackage, PackagePart packagePart, PGMaster pgMaster, Element sp) throws Exception
{
int lineWidth = 1;
boolean dash = false;
BackgroundAndFill lineFill = null;
// border
Element ln = sp.element("spPr").element("ln");
Element style = sp.element("style");
if (ln != null)
{
//border
if (ln.element("noFill") == null)
{
//line width
if(ln.attributeValue("w") != null)
{
lineWidth = Math.round(Integer.parseInt(ln.attributeValue("w")) * MainConstant.PIXEL_DPI / MainConstant.EMU_PER_INCH);
}
Element prstDash = ln.element("prstDash");
if(prstDash != null && !"solid".equalsIgnoreCase(prstDash.attributeValue("val")))
{
dash = true;
}
lineFill = BackgroundReader.instance().processBackground(control, zipPackage, packagePart, pgMaster, ln);
if(lineFill == null && style != null && style.element("lnRef") != null)
{
lineFill = new BackgroundAndFill();
lineFill.setFillType(BackgroundAndFill.FILL_SOLID);
lineFill.setForegroundColor(ReaderKit.instance().getColor(pgMaster, style.element("lnRef")));
}
}
}
else
{
if (style != null && style.element("lnRef") != null)
{
int color = ReaderKit.instance().getColor(pgMaster, style.element("lnRef"));
if((color & 0xFFFFFF) != 0)
{
lineFill = new BackgroundAndFill();
lineFill.setFillType(BackgroundAndFill.FILL_SOLID);
lineFill.setForegroundColor(color);
}
}
}
if(lineFill != null)
{
Line line = new Line();
line.setBackgroundAndFill(lineFill);
line.setLineWidth(lineWidth);
line.setDash(dash);
return line;
}
return null;
}
public static Line createLine(IControl control, ZipPackage zipPackage, PackagePart drawingPart,
Element ln, Map<String, Integer> schemeColor)
{
int lineWidth = 1;
boolean dash = false;
BackgroundAndFill lineFill = null;
// border
if (ln != null)
{
//line width
if(ln.attributeValue("w") != null)
{
lineWidth = Math.round(Integer.parseInt(ln.attributeValue("w")) * MainConstant.PIXEL_DPI / MainConstant.EMU_PER_INCH);
}
Element prstDash = ln.element("prstDash");
if(prstDash != null && !"solid".equalsIgnoreCase(prstDash.attributeValue("val")))
{
dash = true;
}
if (ln.element("noFill") == null)
{
lineFill = AutoShapeDataKit.processBackground(control, zipPackage, drawingPart, ln, schemeColor);
}
}
if(lineFill != null)
{
Line line = new Line();
line.setBackgroundAndFill(lineFill);
line.setLineWidth(lineWidth);
line.setDash(dash);
return line;
}
return null;
}
public static Line createShapeLine(IControl control, ZipPackage zipPackage, PackagePart drawingPart,
Element sp, Map<String, Integer> schemeColor)
{
int lineWidth = 1;
boolean dash = false;
BackgroundAndFill lineFill = null;
// border
Element ln = sp.element("spPr").element("ln");
Element style = sp.element("style");
if (ln != null)
{
//line width
if(ln.attributeValue("w") != null)
{
lineWidth = Math.round(Integer.parseInt(ln.attributeValue("w")) * MainConstant.PIXEL_DPI / MainConstant.EMU_PER_INCH);
}
Element prstDash = ln.element("prstDash");
if(prstDash != null && !"solid".equalsIgnoreCase(prstDash.attributeValue("val")))
{
dash = true;
}
if (ln.element("noFill") == null)
{
lineFill = AutoShapeDataKit.processBackground(control, zipPackage, drawingPart, ln, schemeColor);
if(lineFill == null && style != null && style.element("lnRef") != null)
{
lineFill = new BackgroundAndFill();
lineFill.setFillType(BackgroundAndFill.FILL_SOLID);
lineFill.setForegroundColor(AutoShapeDataKit.getColor(schemeColor, style.element("lnRef")));
}
}
}
else
{
if (style != null && style.element("lnRef") != null)
{
lineFill = new BackgroundAndFill();
lineFill.setFillType(BackgroundAndFill.FILL_SOLID);
lineFill.setForegroundColor(AutoShapeDataKit.getColor(schemeColor, style.element("lnRef")));
}
}
if(lineFill != null)
{
Line line = new Line();
line.setBackgroundAndFill(lineFill);
line.setLineWidth(lineWidth);
line.setDash(dash);
return line;
}
return null;
}
public static Line createChartLine(IControl control, ZipPackage zipPackage, PackagePart drawingPart,
Element ln, Map<String, Integer> schemeColor)
{
// border
if (ln != null)
{
int lineWidth = 1;
boolean dash = false;
BackgroundAndFill lineFill = null;
//line width
if(ln.attributeValue("w") != null)
{
lineWidth = Math.round(Integer.parseInt(ln.attributeValue("w")) * MainConstant.PIXEL_DPI / MainConstant.EMU_PER_INCH);
}
Element prstDash = ln.element("prstDash");
if(prstDash != null && !"solid".equalsIgnoreCase(prstDash.attributeValue("val")))
{
dash = true;
}
if (ln.element("noFill") == null)
{
lineFill = AutoShapeDataKit.processBackground(control, zipPackage, drawingPart, ln, schemeColor);
if(lineFill != null)
{
Line line = new Line();
line.setBackgroundAndFill(lineFill);
line.setLineWidth(lineWidth);
line.setDash(dash);
return line;
}
}
}
else
{
//auto line
Line line = new Line();
BackgroundAndFill lineFill = new BackgroundAndFill();
lineFill.setFillType(BackgroundAndFill.FILL_SOLID);
lineFill.setForegroundColor(0xFF747474);
line.setBackgroundAndFill(lineFill);
line.setLineWidth(1);
return line;
}
return null;
}
}
package com.office.allreader.allofficefilereader.fc;
/**
* Base class of all the exceptions that POI throws in the event
* that it's given a file that's older than currently supported.
*/
public abstract class OldFileFormatException extends IllegalArgumentException {
public OldFileFormatException(String s) {
super(s);
}
}
package com.office.allreader.allofficefilereader.fc;
/**
* Common Parent for Text Extractors
* of POI Documents.
* You will typically find the implementation of
* a given format's text extractor under
* org.apache.poi.[format].extractor .
* @see com.wxiwei.fc.hssf.extractor.ExcelExtractor
* @see arc.fc.hslf.extractor.poi.hslf.extractor.PowerPointExtractor
* @see org.apache.poi.hdgf.extractor.VisioTextExtractor
* @see arc.fc.hwpf.extractor.poi.hwpf.extractor.WordExtractor
*/
public abstract class POITextExtractor {
/** The POIDocument that's open */
protected POIDocument document;
/**
* Creates a new text extractor for the given document
*/
public POITextExtractor(POIDocument document) {
this.document = document;
}
/**
* Creates a new text extractor, using the same
* document as another text extractor. Normally
* only used by properties extractors.
*/
protected POITextExtractor(POITextExtractor otherExtractor) {
this.document = otherExtractor.document;
}
/**
* Retrieves all the text from the document.
* How cells, paragraphs etc are separated in the text
* is implementation specific - see the javadocs for
* a specific project for details.
* @return All the text from the document
*/
public abstract String getText();
/**
* Returns another text extractor, which is able to
* output the textual content of the document
* metadata / properties, such as author and title.
*/
public abstract POITextExtractor getMetadataTextExtractor();
}
package com.office.allreader.allofficefilereader.fc;
import java.util.List;
import java.util.Map;
import com.office.allreader.allofficefilereader.common.autoshape.AutoShapeDataKit;
import com.office.allreader.allofficefilereader.common.bg.BackgroundAndFill;
import com.office.allreader.allofficefilereader.common.bg.Gradient;
import com.office.allreader.allofficefilereader.common.bg.LinearGradientShader;
import com.office.allreader.allofficefilereader.common.bg.RadialGradientShader;
import com.office.allreader.allofficefilereader.common.bg.TileShader;
import com.office.allreader.allofficefilereader.common.picture.Picture;
import com.office.allreader.allofficefilereader.constant.MainConstant;
import com.office.allreader.allofficefilereader.fc.dom4j.Element;
import com.office.allreader.allofficefilereader.fc.ppt.reader.ReaderKit;
import com.office.allreader.allofficefilereader.pg.model.PGMaster;
public class ShaderKit
{
/**
* PPTX gradient read
* @param master
* @param gradFill
* @return
*/
public static Gradient readGradient(PGMaster master, Element gradFill)
{
Element gsLstElement= gradFill.element("gsLst");
//Gradient stops list
List<Element> gsLst = gsLstElement.elements("gs");
if(gsLst == null || gsLst.size() == 0)
{
return null;
}
int gsCnt = gsLst.size();
int[] colors = new int[gsCnt];
float[] positions = new float[gsCnt];
for(int i = 0; i < gsCnt; i++)
{
Element gs = gsLst.get(i);
String pos = gs.attributeValue("pos");
positions[i] = Integer.parseInt(pos) / 100000.f;
colors[i] = ReaderKit.instance().getColor(master, gs);
}
Element ele = gradFill.element("lin");
if(ele != null)
{
//linear gradient property
float angle = Integer.parseInt(ele.attributeValue("ang")) / 60000;
return new LinearGradientShader(angle, colors, positions);
}
else if((ele = gradFill.element("path")) != null)
{
int type = getGradientType(gradFill);
int radialCenterType = getRadialCenterType(ele.element("fillToRect"));
if(type == BackgroundAndFill.FILL_SHADE_RADIAL
|| type == BackgroundAndFill.FILL_SHADE_RECT
|| type == BackgroundAndFill.FILL_SHADE_SHAPE)
{
return new RadialGradientShader(radialCenterType, colors, positions);
}
}
return null;
}
/**
* XLSX gradient read
* @param schemeColor
* @param gradFill
* @return
*/
public static Gradient readGradient(Map<String, Integer> schemeColor, Element gradFill)
{
Element gsLstElement= gradFill.element("gsLst");
//Gradient stops list
List<Element> gsLst = gsLstElement.elements("gs");
if(gsLst == null || gsLst.size() == 0)
{
return null;
}
int gsCnt = gsLst.size();
int[] colors = new int[gsCnt];
float[] positions = new float[gsCnt];
for(int i = 0; i < gsCnt; i++)
{
Element gs = gsLst.get(i);
String pos = gs.attributeValue("pos");
positions[i] = Integer.parseInt(pos) / 100000.f;
colors[i] = AutoShapeDataKit.getColor(schemeColor, gs);
}
Element ele = gradFill.element("lin");
if(ele != null)
{
//linear gradient property
float angle = Integer.parseInt(ele.attributeValue("ang")) / 60000;
return new LinearGradientShader(angle, colors, positions);
}
else if((ele = gradFill.element("path")) != null)
{
int type = getGradientType(gradFill);
int radialCenterType = getRadialCenterType(ele.element("fillToRect"));
if(type == BackgroundAndFill.FILL_SHADE_RADIAL
|| type == BackgroundAndFill.FILL_SHADE_RECT
|| type == BackgroundAndFill.FILL_SHADE_SHAPE)
{
return new RadialGradientShader(radialCenterType, colors, positions);
}
}
else
{
return new LinearGradientShader(270, colors, positions);
}
return null;
}
/**
*
* @param path
* @return
*/
public static byte getGradientType(Element gradFill)
{
Element ele = gradFill.element("lin");
if(ele != null)
{
return BackgroundAndFill.FILL_SHADE_LINEAR;
}
else if((ele = gradFill.element("path")) != null)
{
String path = ele.attributeValue("path");
if("circle".equalsIgnoreCase(path))
{
return BackgroundAndFill.FILL_SHADE_RADIAL;
}
else if("rect".equalsIgnoreCase(path))
{
return BackgroundAndFill.FILL_SHADE_RECT;
}
else if("shape".equalsIgnoreCase(path))
{
return BackgroundAndFill.FILL_SHADE_SHAPE;
}
}
return BackgroundAndFill.FILL_SHADE_LINEAR;
}
/**
*
* @param fillToRect
* @return
*/
private static int getRadialCenterType(Element fillToRect)
{
if(fillToRect != null)
{
String l = fillToRect.attributeValue("l");
String t = fillToRect.attributeValue("t");
String r = fillToRect.attributeValue("r");
String b = fillToRect.attributeValue("b");
if("100000".equalsIgnoreCase(r) && "100000".equalsIgnoreCase(b))
{
return RadialGradientShader.Center_TL;
}
else if("100000".equalsIgnoreCase(l) && "100000".equalsIgnoreCase(b))
{
return RadialGradientShader.Center_TR;
}
if("100000".equalsIgnoreCase(r) && "100000".equalsIgnoreCase(t))
{
return RadialGradientShader.Center_BL;
}
else if("100000".equalsIgnoreCase(l) && "100000".equalsIgnoreCase(t))
{
return RadialGradientShader.Center_BR;
}
else if("50000".equalsIgnoreCase(l) && "50000".equalsIgnoreCase(t)
&& "50000".equalsIgnoreCase(r) && "50000".equalsIgnoreCase(b))
{
return RadialGradientShader.Center_Center;
}
}
return RadialGradientShader.Center_TL;
}
/**
*
* @param picture
* @param tile
* @return
*/
public static TileShader readTile(Picture picture, Element tile)
{
int flip = getFlipType(tile.attributeValue("flip"));
float horiRatio = Integer.parseInt(tile.attributeValue("sx")) / 100000.f;
float vertRatio = Integer.parseInt(tile.attributeValue("sy")) / 100000.f;
int offsetX = Math.round(Integer.parseInt(tile.attributeValue("tx")) * MainConstant.PIXEL_DPI / MainConstant.EMU_PER_INCH);
int offsetY = Math.round(Integer.parseInt(tile.attributeValue("ty")) * MainConstant.PIXEL_DPI / MainConstant.EMU_PER_INCH);
return new TileShader(picture, flip, horiRatio, vertRatio, offsetX, offsetY);
}
/**
* mirror postion
* @param flip
* @return
*/
private static int getFlipType(String flip)
{
if("x".equalsIgnoreCase(flip))
{
return TileShader.Flip_Horizontal;
}
else if("y".equalsIgnoreCase(flip))
{
return TileShader.Flip_Vertical;
}
else if("xy".equalsIgnoreCase(flip))
{
return TileShader.Flip_Both;
}
return TileShader.Flip_None;
}
}
package com.office.allreader.allofficefilereader.fc.codec;
public abstract class BaseNCodec implements BinaryEncoder, BinaryDecoder {
public static final int MIME_CHUNK_SIZE = 76;
public static final int PEM_CHUNK_SIZE = 64;
private static final int DEFAULT_BUFFER_RESIZE_FACTOR = 2;
private static final int DEFAULT_BUFFER_SIZE = 8192;
protected static final int MASK_8BITS = 0xff;
protected static final byte PAD_DEFAULT = '='; // Allow static access to default
protected final byte PAD = PAD_DEFAULT; // instance variable just in case it needs to vary later
private final int unencodedBlockSize;
private final int encodedBlockSize;
protected final int lineLength;
private final int chunkSeparatorLength;
protected byte[] buffer;
protected int pos;
private int readPos;
protected boolean eof;
protected int currentLinePos;
protected int modulus;
protected BaseNCodec(int unencodedBlockSize, int encodedBlockSize, int lineLength, int chunkSeparatorLength){
this.unencodedBlockSize = unencodedBlockSize;
this.encodedBlockSize = encodedBlockSize;
this.lineLength = (lineLength > 0 && chunkSeparatorLength > 0) ? (lineLength / encodedBlockSize) * encodedBlockSize : 0;
this.chunkSeparatorLength = chunkSeparatorLength;
}
boolean hasData() { // package protected for access from I/O streams
return this.buffer != null;
}
int available() { // package protected for access from I/O streams
return buffer != null ? pos - readPos : 0;
}
protected int getDefaultBufferSize() {
return DEFAULT_BUFFER_SIZE;
}
private void resizeBuffer() {
if (buffer == null) {
buffer = new byte[getDefaultBufferSize()];
pos = 0;
readPos = 0;
} else {
byte[] b = new byte[buffer.length * DEFAULT_BUFFER_RESIZE_FACTOR];
System.arraycopy(buffer, 0, b, 0, buffer.length);
buffer = b;
}
}
protected void ensureBufferSize(int size){
if ((buffer == null) || (buffer.length < pos + size)){
resizeBuffer();
}
}
int readResults(byte[] b, int bPos, int bAvail) { // package protected for access from I/O streams
if (buffer != null) {
int len = Math.min(available(), bAvail);
System.arraycopy(buffer, readPos, b, bPos, len);
readPos += len;
if (readPos >= pos) {
buffer = null; // so hasData() will return false, and this method can return -1
}
return len;
}
return eof ? -1 : 0;
}
protected static boolean isWhiteSpace(byte byteToCheck) {
switch (byteToCheck) {
case ' ' :
case '\n' :
case '\r' :
case '\t' :
return true;
default :
return false;
}
}
private void reset() {
buffer = null;
pos = 0;
readPos = 0;
currentLinePos = 0;
modulus = 0;
eof = false;
}
public Object encode(Object pObject) throws EncoderException {
if (!(pObject instanceof byte[])) {
throw new EncoderException("Parameter supplied to Base-N encode is not a byte[]");
}
return encode((byte[]) pObject);
}
public String encodeToString(byte[] pArray) {
return StringUtils.newStringUtf8(encode(pArray));
}
public Object decode(Object pObject) throws DecoderException {
if (pObject instanceof byte[]) {
return decode((byte[]) pObject);
} else if (pObject instanceof String) {
return decode((String) pObject);
} else {
throw new DecoderException("Parameter supplied to Base-N decode is not a byte[] or a String");
}
}
public byte[] decode(String pArray) {
return decode(StringUtils.getBytesUtf8(pArray));
}
public byte[] decode(byte[] pArray) {
reset();
if (pArray == null || pArray.length == 0) {
return pArray;
}
decode(pArray, 0, pArray.length);
decode(pArray, 0, -1); // Notify decoder of EOF.
byte[] result = new byte[pos];
readResults(result, 0, result.length);
return result;
}
public byte[] encode(byte[] pArray) {
reset();
if (pArray == null || pArray.length == 0) {
return pArray;
}
encode(pArray, 0, pArray.length);
encode(pArray, 0, -1); // Notify encoder of EOF.
byte[] buf = new byte[pos - readPos];
readResults(buf, 0, buf.length);
return buf;
}
public String encodeAsString(byte[] pArray){
return StringUtils.newStringUtf8(encode(pArray));
}
abstract void encode(byte[] pArray, int i, int length); // package protected for access from I/O streams
abstract void decode(byte[] pArray, int i, int length); // package protected for access from I/O streams
protected abstract boolean isInAlphabet(byte value);
public boolean isInAlphabet(byte[] arrayOctet, boolean allowWSPad) {
for (int i = 0; i < arrayOctet.length; i++) {
if (!isInAlphabet(arrayOctet[i]) &&
(!allowWSPad || (arrayOctet[i] != PAD) && !isWhiteSpace(arrayOctet[i]))) {
return false;
}
}
return true;
}
public boolean isInAlphabet(String basen) {
return isInAlphabet(StringUtils.getBytesUtf8(basen), true);
}
protected boolean containsAlphabetOrPad(byte[] arrayOctet) {
if (arrayOctet == null) {
return false;
}
for (int i = 0; i < arrayOctet.length; i++) {
if (PAD == arrayOctet[i] || isInAlphabet(arrayOctet[i])) {
return true;
}
}
return false;
}
public long getEncodedLength(byte[] pArray) {
long len = ((pArray.length + unencodedBlockSize-1) / unencodedBlockSize) * (long) encodedBlockSize;
if (lineLength > 0) { // We're using chunking
len += ((len + lineLength-1) / lineLength) * chunkSeparatorLength;
}
return len;
}
}
package com.office.allreader.allofficefilereader.fc.codec;
public class BinaryCodec implements BinaryDecoder, BinaryEncoder {
private static final char[] EMPTY_CHAR_ARRAY = new char[0];
private static final byte[] EMPTY_BYTE_ARRAY = new byte[0];
private static final int BIT_0 = 1;
private static final int BIT_1 = 0x02;
private static final int BIT_2 = 0x04;
private static final int BIT_3 = 0x08;
private static final int BIT_4 = 0x10;
private static final int BIT_5 = 0x20;
private static final int BIT_6 = 0x40;
private static final int BIT_7 = 0x80;
private static final int[] BITS = {BIT_0, BIT_1, BIT_2, BIT_3, BIT_4, BIT_5, BIT_6, BIT_7};
public byte[] encode(byte[] raw) {
return toAsciiBytes(raw);
}
public Object encode(Object raw) throws EncoderException {
if (!(raw instanceof byte[])) {
throw new EncoderException("argument not a byte array");
}
return toAsciiChars((byte[]) raw);
}
public Object decode(Object ascii) throws DecoderException {
if (ascii == null) {
return EMPTY_BYTE_ARRAY;
}
if (ascii instanceof byte[]) {
return fromAscii((byte[]) ascii);
}
if (ascii instanceof char[]) {
return fromAscii((char[]) ascii);
}
if (ascii instanceof String) {
return fromAscii(((String) ascii).toCharArray());
}
throw new DecoderException("argument not a byte array");
}
public byte[] decode(byte[] ascii) {
return fromAscii(ascii);
}
public byte[] toByteArray(String ascii) {
if (ascii == null) {
return EMPTY_BYTE_ARRAY;
}
return fromAscii(ascii.toCharArray());
}
public static byte[] fromAscii(char[] ascii) {
if (ascii == null || ascii.length == 0) {
return EMPTY_BYTE_ARRAY;
}
byte[] l_raw = new byte[ascii.length >> 3];
for (int ii = 0, jj = ascii.length - 1; ii < l_raw.length; ii++, jj -= 8) {
for (int bits = 0; bits < BITS.length; ++bits) {
if (ascii[jj - bits] == '1') {
l_raw[ii] |= BITS[bits];
}
}
}
return l_raw;
}
public static byte[] fromAscii(byte[] ascii) {
if (isEmpty(ascii)) {
return EMPTY_BYTE_ARRAY;
}
byte[] l_raw = new byte[ascii.length >> 3];
for (int ii = 0, jj = ascii.length - 1; ii < l_raw.length; ii++, jj -= 8) {
for (int bits = 0; bits < BITS.length; ++bits) {
if (ascii[jj - bits] == '1') {
l_raw[ii] |= BITS[bits];
}
}
}
return l_raw;
}
private static boolean isEmpty(byte[] array) {
return array == null || array.length == 0;
}
public static byte[] toAsciiBytes(byte[] raw) {
if (isEmpty(raw)) {
return EMPTY_BYTE_ARRAY;
}
byte[] l_ascii = new byte[raw.length << 3];
for (int ii = 0, jj = l_ascii.length - 1; ii < raw.length; ii++, jj -= 8) {
for (int bits = 0; bits < BITS.length; ++bits) {
if ((raw[ii] & BITS[bits]) == 0) {
l_ascii[jj - bits] = '0';
} else {
l_ascii[jj - bits] = '1';
}
}
}
return l_ascii;
}
public static char[] toAsciiChars(byte[] raw) {
if (isEmpty(raw)) {
return EMPTY_CHAR_ARRAY;
}
char[] l_ascii = new char[raw.length << 3];
for (int ii = 0, jj = l_ascii.length - 1; ii < raw.length; ii++, jj -= 8) {
for (int bits = 0; bits < BITS.length; ++bits) {
if ((raw[ii] & BITS[bits]) == 0) {
l_ascii[jj - bits] = '0';
} else {
l_ascii[jj - bits] = '1';
}
}
}
return l_ascii;
}
public static String toAsciiString(byte[] raw) {
return new String(toAsciiChars(raw));
}
}
package com.office.allreader.allofficefilereader.fc.codec;
public interface BinaryDecoder extends Decoder {
byte[] decode(byte[] source) throws DecoderException;
}
package com.office.allreader.allofficefilereader.fc.codec;
public interface BinaryEncoder extends Encoder {
byte[] encode(byte[] source) throws EncoderException;
}
package com.office.allreader.allofficefilereader.fc.codec;
public class CharEncoding {
public static final String ISO_8859_1 = "ISO-8859-1";
public static final String US_ASCII = "US-ASCII";
public static final String UTF_16 = "UTF-16";
public static final String UTF_16BE = "UTF-16BE";
public static final String UTF_16LE = "UTF-16LE";
public static final String UTF_8 = "UTF-8";
}
package com.office.allreader.allofficefilereader.fc.codec;
public interface Decoder {
Object decode(Object source) throws DecoderException;
}
package com.office.allreader.allofficefilereader.fc.codec;
public class DecoderException extends Exception {
private static final long serialVersionUID = 1L;
public DecoderException() {
super();
}
public DecoderException(String message) {
super(message);
}
public DecoderException(String message, Throwable cause) {
super(message, cause);
}
public DecoderException(Throwable cause) {
super(cause);
}
}
package com.office.allreader.allofficefilereader.fc.codec;
public interface Encoder {
Object encode(Object source) throws EncoderException;
}
package com.office.allreader.allofficefilereader.fc.codec;
public class EncoderException extends Exception {
private static final long serialVersionUID = 1L;
public EncoderException() {
super();
}
public EncoderException(String message) {
super(message);
}
public EncoderException(String message, Throwable cause) {
super(message, cause);
}
public EncoderException(Throwable cause) {
super(cause);
}
}
package com.office.allreader.allofficefilereader.fc.codec;
import java.io.UnsupportedEncodingException;
public class Hex implements BinaryEncoder, BinaryDecoder {
public static final String DEFAULT_CHARSET_NAME = CharEncoding.UTF_8;
private static final char[] DIGITS_LOWER = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
private static final char[] DIGITS_UPPER = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
public static byte[] decodeHex(char[] data) throws DecoderException {
int len = data.length;
if ((len & 0x01) != 0) {
throw new DecoderException("Odd number of characters.");
}
byte[] out = new byte[len >> 1];
// two characters form the hex value.
for (int i = 0, j = 0; j < len; i++) {
int f = toDigit(data[j], j) << 4;
j++;
f = f | toDigit(data[j], j);
j++;
out[i] = (byte) (f & 0xFF);
}
return out;
}
public static char[] encodeHex(byte[] data) {
return encodeHex(data, true);
}
public static char[] encodeHex(byte[] data, boolean toLowerCase) {
return encodeHex(data, toLowerCase ? DIGITS_LOWER : DIGITS_UPPER);
}
protected static char[] encodeHex(byte[] data, char[] toDigits) {
int l = data.length;
char[] out = new char[l << 1];
// two characters form the hex value.
for (int i = 0, j = 0; i < l; i++) {
out[j++] = toDigits[(0xF0 & data[i]) >>> 4];
out[j++] = toDigits[0x0F & data[i]];
}
return out;
}
public static String encodeHexString(byte[] data) {
return new String(encodeHex(data));
}
protected static int toDigit(char ch, int index) throws DecoderException {
int digit = Character.digit(ch, 16);
if (digit == -1) {
throw new DecoderException("Illegal hexadecimal character " + ch + " at index " + index);
}
return digit;
}
private final String charsetName;
public Hex() {
// use default encoding
this.charsetName = DEFAULT_CHARSET_NAME;
}
public Hex(String csName) {
this.charsetName = csName;
}
public byte[] decode(byte[] array) throws DecoderException {
try {
return decodeHex(new String(array, getCharsetName()).toCharArray());
} catch (UnsupportedEncodingException e) {
throw new DecoderException(e.getMessage(), e);
}
}
public Object decode(Object object) throws DecoderException {
try {
char[] charArray = object instanceof String ? ((String) object).toCharArray() : (char[]) object;
return decodeHex(charArray);
} catch (ClassCastException e) {
throw new DecoderException(e.getMessage(), e);
}
}
public byte[] encode(byte[] array) {
return StringUtils.getBytesUnchecked(encodeHexString(array), getCharsetName());
}
public Object encode(Object object) throws EncoderException {
try {
byte[] byteArray = object instanceof String ? ((String) object).getBytes(getCharsetName()) : (byte[]) object;
return encodeHex(byteArray);
} catch (ClassCastException e) {
throw new EncoderException(e.getMessage(), e);
} catch (UnsupportedEncodingException e) {
throw new EncoderException(e.getMessage(), e);
}
}
public String getCharsetName() {
return this.charsetName;
}
public String toString() {
return super.toString() + "[charsetName=" + this.charsetName + "]";
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment