Java; Saving AudioinputStream to FileDocument

0
I have a TestFile entity inheriting FileDocument and I use it to store WAV files. I have custom java that takes one of these FileDocuments, copies it, and uses Audiostream to concatenate the two copies (just duplicating the sound one after another).  If I save the audiostream back to a local file on my laptop when running the app against localhost, it saves the new WAV file just fine. I can open it and hear it. But if I save the contents back to a FileDocument Type (naming it “TEST.WAV”)… the object shows up in my database and the “Size” and “HasContents” attributes appear correct. When I download it and try to play it I get this error:   “This file isn't playable. That might be because the file type is unsupported, the file extension is incorrect, or the file is corrupt.” Is there something I need to do to get the FIleDocument to recognize the audioinputstream I’m saving to it? Here’s the code. The last two lines (1) successfully save it to my filesystem as a wav file and (2) attempt to save it as a FileDocument which appears to work but its corrupted   InputStream is; InputStream is2; InputStream iscopy; InputStream is2copy; is = Core.getFileDocumentContent(getContext(), myobject.getMendixObject()); is2 = Core.getFileDocumentContent(getContext(), myobject.getMendixObject()); iscopy = Core.getFileDocumentContent(getContext(), myobject.getMendixObject()); is2copy = Core.getFileDocumentContent(getContext(), myobject.getMendixObject()); AudioInputStream clip1 = AudioSystem.getAudioInputStream(new BufferedInputStream(is)); AudioInputStream clip2 = AudioSystem.getAudioInputStream(new BufferedInputStream(is2)); AudioInputStream clip1copy = AudioSystem.getAudioInputStream(new BufferedInputStream(iscopy)); AudioInputStream clip2copy = AudioSystem.getAudioInputStream(new BufferedInputStream(is2copy)); AudioInputStream appendedFiles = new AudioInputStream(new SequenceInputStream(clip1, clip2), clip1.getFormat(), clip1.getFrameLength() + clip2.getFrameLength()); AudioInputStream appendedFiles2 = new AudioInputStream(new SequenceInputStream(clip1copy, clip2copy), clip1copy.getFormat(), clip1copy.getFrameLength() + clip2copy.getFrameLength()); AudioSystem.write(appendedFiles, AudioFileFormat.Type.WAVE, new File("C:\\test\\wavAppended.wav")); IMendixObject newobject = Core.instantiate(getContext(), "MusicBack.TestFile"); Core.storeFileDocumentContent(getContext(), newobject, "TEST.WAV", appendedFiles2);  
asked
0 answers