Page 1 of 1

Error reading from the stream

PostPosted: Sat Dec 29, 2018 12:30 am
by kinghitesh03
Hi
I am using Docx4j4Android4
I am getting error Error reading from the stream while load word file from assets folder as InputStream

AssetManager assetManager = getApplicationContext().getAssets();
InputStream file;
WordprocessingMLPackage template = null;
try {
file = assetManager.open(fileName);
// BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(file));
// String line = null;
// while ((line = bufferedReader.readLine()) != null) {
// Log.d(TAG, line);
// }
template = WordprocessingMLPackage.load(file);

//Log.d(TAG, String.valueOf(file.read()));
} catch (IOException e) {
e.printStackTrace();
} catch (Docx4JException e) {
e.printStackTrace();
}

Its working on API >=23 but giving error in below api 23 like (22,21)

Please help me out of this

Re: Error reading from the stream

PostPosted: Mon Jan 07, 2019 10:36 pm
by kinghitesh03
Below is my app level Build.gradle

Code: Select all
apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    buildToolsVersion '28.0.3'

    defaultConfig {
        applicationId "***************"
        minSdkVersion 16
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        vectorDrawables.useSupportLibrary = true
        multiDexEnabled true

    }


    buildTypes {
        debug {
            // app-debug.apk is 6443 kb with minifyEnabled, 11025 kb otherwise
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        release {
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }


    packagingOptions {
        exclude 'META-INF/DEPENDENCIES.txt'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/dependencies.txt'
        exclude 'META-INF/LGPL2.1'
        exclude 'readme.html'
        exclude 'license.html'
        exclude 'META-INF/eclipse.inf'
    }

//    configurations {
//        compile.exclude group: "javax.xml.bind", module: "ModuleUtil"
//    }

    dexOptions {
        javaMaxHeapSize "4g"
        additionalParameters = ['--core-library']
    }

    sourceSets {
        main {
            resources.includes = ['src/main/assets/docx4j.properties']
        }
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:28.0.0'
    testImplementation 'junit:junit:4.12'
    implementation 'com.android.support:design:28.0.0'
    implementation 'javax.xml.stream:stax-api:1.0-2'
    implementation 'com.fasterxml:aalto-xml:1.0.0'
    implementation files('libs/awt-bastardised-17v8.jar')
    implementation 'org.docx4j:docx4j:6.1.0'
    implementation 'javax.xml.bind:jaxb-api:2.3.0'
    implementation 'com.sun.xml.bind:jaxb-core:2.3.0'
    implementation 'com.sun.xml.bind:jaxb-impl:2.3.0'
    implementation 'javax.activation:activation:1.1.1'
}


Code: Select all
inputStream = getApplicationContext().getAssets().open(fileName);
template = WordprocessingMLPackage.load(inputStream);


org.docx4j.openpackaging.exceptions.Docx4JException: Error reading from the stream
W/System.err: at org.docx4j.openpackaging.packages.OpcPackage.load(OpcPackage.java:404)
W/System.err: at org.docx4j.openpackaging.packages.OpcPackage.load(OpcPackage.java:376)
W/System.err: at org.docx4j.openpackaging.packages.OpcPackage.load(OpcPackage.java:341)