Results 1 to 4 of 4
  1. #1
    P5music is offline Member
    Join Date
    Oct 2010
    Posts
    2
    Rep Power
    0

    Default passing an entire file to a c++ function

    Hello
    I made a java application that is hosted in audio/midi sequencer Sonar through jVSTwrapper.
    This application create a .zip file and then pass to the host in getChunk() function. My implementation is:

    Java Code:
    public int getChunk(byte[][] data, boolean isPreset)
    {
    
    int length = 0;
    data = new byte[1][1];
    String fileName="filename.zip";
    
    File zipFile=new File(fileName);
    FileInputStream fis=null;
            
    
    	try {
                 fis = new FileInputStream(zipFile);
            } catch (FileNotFoundException ex) {
                Logger.getLogger(myclass.getName()).log(Level.SEVERE, null, ex);
            }
    
    
    length=(int)zipFile.length();data[0]=new byte[length];
    
    
            try {
    
                fis.read(data[0], 0, length);
    
            } catch (IOException ex) {
                Logger.getLogger(myclass.getName()).log(Level.SEVERE, null, ex);
            }
    
    
    length = data[0].length;
    
            try {
                fis.close();
            } catch (IOException ex) {
                Logger.getLogger(myclass.getName()).log(Level.SEVERE, null, ex);
            }
    
    return length;
    }
    then, when requested, retrieves it from host and saves on disk with:

    Java Code:
    public int setChunk(byte[] data, int byteSize, boolean isPreset)
    {
        char[] arraychar=new char[byteSize];
        int i;
       
        FileOutputStream outStream=null;
        File outf=new File("filename.zip");
    
            try {
                outStream = new FileOutputStream(outf);
            } catch (FileNotFoundException ex) {
                Logger.getLogger(arpStylerVSTWrapper.class.getName()).log(Level.SEVERE, null, ex);
            }
            try {
    
                outStream.write(data,0,byteSize);
    
            } catch (IOException ex) {
                Logger.getLogger(arpStylerVSTWrapper.class.getName()).log(Level.SEVERE, null, ex);
            }
            try {
                outStream.close();
            } catch (IOException ex) {
                Logger.getLogger(arpStylerVSTWrapper.class.getName()).log(Level.SEVERE, null, ex);
            }
    
    
    return 0;}
    The fact is that the restored file has the same size of the original one but I am not able to open it with winZip or winRar because I get an error like "damaged file or unknown format".
    Thanks in advance for your help.

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,418
    Rep Power
    25

    Default

    For more information, do you have a compare program that can compare the two files?
    You expect them to be byte for byte equal?
    Or write a simple java program that reads bytes from each and prints out when the bytes are different.

  3. #3
    P5music is offline Member
    Join Date
    Oct 2010
    Posts
    2
    Rep Power
    0

    Default

    the two file turn to be completely different, this is a sample:

    right file
    Java Code:
    PK   A=            &   C:\myfolder\myfile.asy풿j0w!ON,K,;J7C1
    Eˡ#%n$Q(%}t2&E1" [oz&~l~j_0Lm3}X3ukiVf4ٳ1|uK!*+EDPJ0$4%Rf@DJ(dJeB
    *
    /`܍vS*+
    FјTѵ^?SXx%~lgCo5}dӛPKC %   ?  PK   A=               C:\myfolder\m_s.asyKw#׵&x	>  L A""P"E%յ$Kt-Kr.,[Rj)I夻G=̜T1?5tSuk*Uu	8c}$g+}ӒkXdq\atb߉?ş5O~vwŷ4oMV$xS~poZĶ4zoG_>X-
    #V[G|u<z囒,yӈݛk_7E\Pg_I]_Xb.zu	;vH̘%~PkS4x<2ey	Vm#,ox$
    K/LXVD9\r-MI9yyΣ߿ϜG$au|Lrhu_Uxʊ
    wrong file
    Java Code:
     B4    Oa  B4    OP  B4    O*  B4    OT   B4    O  " B4    O   $ B4    O   & B4    O   ( B4    O   * B4    O   , B4    O   . B4    O4 0 B4    OPi 2 B4    O  4 B4    O   6 B4    O  8 B4    O   : B4    O  < B4    O   B4            с[E^ `                -    R	4!0 *	   HK   j   `    HK   j           HK   t   -    HK   Hq           HK   Hq   h    HK          HK              HK   ȅ   h.    HK   H       HK           HK              HK   H       HK      1    HK   H   .    HK   H   o    HK              HK      )    HK   H       HK   H   v    HK   H               Zk^   /0(0@0X0p00*000004         $0      \         <0         

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,418
    Rep Power
    25

    Default

    Why do you think that binary data will make it thru the reads and writes that you are doing and stay unchanged. Are there other programs that read/write the data besides the two methods you show?

    What does the "host" have to do with the transportation(reading/writing) of this data from the input zip file to the output file? Can the "host" have encoded/decoded the data?

Similar Threads

  1. Passing an Array index into a function?
    By dpedroia15 in forum New To Java
    Replies: 3
    Last Post: 06-01-2010, 07:51 PM
  2. Example for passing string to a function.?
    By mlibot in forum New To Java
    Replies: 1
    Last Post: 03-19-2010, 06:36 AM
  3. Replies: 15
    Last Post: 03-18-2009, 10:59 PM
  4. how use string array while passing to a function
    By sks9s9 in forum New To Java
    Replies: 2
    Last Post: 02-03-2009, 12:44 PM
  5. Passing a Vector object to a function
    By evapisces in forum New To Java
    Replies: 4
    Last Post: 09-27-2008, 03:18 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •