Search code examples
javafile-iocoldfusioncfmldefault-constructor

How to accommodate a FileInputStream object for InputStream object in the constructor call to the class while initializing?


1 To create and initialize the object for myDocDesigner:

Here is the definition of myDocDesignerclass with contructor as:

public myDocDesigner(customDocFormat doc, InputStream imageStream, int page) throws IOException 
{
    docImageStream(imageStream);
    calculatePageSize(doc, page);
}

2 From generateOutputDoc() in myFileManager class as:

jMyDocDesigner = createObject("java"
                            ,"myPackage.visible.myDocDesigner")
                            .init(jMyLocalDoc ,myImageFileStream,1);

3 With attributes defined as:

/* load document : `customDocFormat` isn't only a format it also returns the document object of the type `customDocFormat` to be used in #1 & #2 above */

    //document & image file paths
    lStrInputFilePath = "#expandPath('sampledocs')#\mySampleDoc.pdf";
    lStrImageFilePath = "#expandPath('sampledocs')#\myPlacementLogo.png";
    //java FileInputStream object for the PDF file
    lOsPDFInput = CreateObject("java","java.io.FileInputStream")
                     .init(CreateObject("java","java.io.File").init(lStrInputPDFfile));
    jMyLocalDoc = createObject("java","myPackage.docModel.customDocFormat");
    jMyLocalDoc.load(lOsPDFInput);
    //FileInputStream Object for image
    lSignImage  = CreateObject("java","java.io.FileOutputStream")
                      .init(CreateObject("java","java.io.File").init(lStrImageFilePath));

4 Problem:

To be clear and make things easy: I have tried every possible option to the best of my knowledge of Java. But I cannot get this working. This portion of code is a part of project to manipulate documents based upon some internal requirement and conventions. Every thing is working perfectly...I step debugged the whole code, but this portion is hampering everything....I tried 4-5 variations to convert and pass the FileInputStream object to the contructor as InputStream but everytime I am getting this error, which is understood, as it is not accepting the parameters I am throwing at it:

enter image description here

I updated my question, since I found out the cause for the problem lied within the FileInputStream object itself that I initialized as pointed out by Leigh in his answer, comes out I was not going the right way, thanks to him...I was able to move forward with my code and here's the only bug in my code that is stopping the project to be finalized :( :

The <code>PDDocument</code> after loading the original Input document via <code>FileInputStream</code> object has this value of <code>int</code> field <code>UNKNOWN_NUMBER_OF_PAGES</code> as <code>-1</code> every time and to cross-verify that I also called <code>getPageCount()</code> function which returns a value of <code>0</code> irrespective of the no. of pages in my PDF document and no matter how many types of document I use....the surprising thing is that the stream is correctly fetched which might look like the problem in this case...because I was able to construct the duplicate copy using the stream of bytes I read from the stream object. Please help me on this! SOS

Here are the Java files for PDDocument & PDDocumentInformation classes that I dealing with, and for which I get the incorrect no. of pages after the document is loaded through it: go here


Solution

  • Found it, works perfectly! The arguments signature for myDocDesigneraccepts the FileInputStream and OutputStreamobjects for the input and output documents. The whole problem was my lacks of java knowledge I admit it but thanks to the group and after some study and testing I made some changes and magically it works. Really happy since I can proceed forward now. Thanks Leigh for your help.

            fis = createObject("java", "java.io.FileInputStream");
            lOsPDFInput = createObject("java", "java.io.BufferedInputStream").init(fis.init(arguments.lStrInputPDFfile));
            fos = createObject("java", "java.io.FileOutputStream");
            lOsPDFOutput = createObject("java", "java.io.BufferedOutputStream").init(fos.init(arguments.lStrOutputPDFfile));
            fimgs = createObject("java", "java.io.FileInputStream");
            lSignImage = createObject("java", "java.io.BufferedInputStream").init(fimgs.init(arguments.lStrSignImageFile));
            fkeys = createObject("java", "java.io.FileInputStream");
            lKeyStoreFileStream = createObject("java", "java.io.BufferedInputStream").init(fkeys.init(arguments.lStrKeyStoreFilePath));