title: mp4 file doesn't get played after being copied and written again
body: <p>When I try to copy an mp4 from one folder to another inside one of the methods of Mp4Parse, everything works fine. When I tried to utilise one of the methods' outputs to make new objects and then use those in order to write the file in another folder, things didn't quite work out. Below is the code that I use:</p>
  <p><strong>I use this class to extract metadata and create videoFile objects with the corresponding data</strong>(The comments are leftover code I used to make sure it was working)</p>
  <p>EDIT 1:
  After some testing I figured out that FOR SOME REASON, EVEN THOUGH <code>temp</code> from Mp4Parse.NoChunkMethod is NOT null or empty (I checked by printing all of its contents) the method returns a byte array of only 0s</p>
  <pre><code>import java.io.File;
  import java.io.FileInputStream;
  import java.io.FileOutputStream;
  import java.io.IOException;
  import java.nio.file.*;
  import java.util.ArrayList;
  
  import org.apache.tika.exception.TikaException;
  import org.apache.tika.metadata.Metadata;
  import org.apache.tika.parser.ParseContext;
  import org.apache.tika.parser.mp4.MP4Parser;
  import org.apache.tika.sax.BodyContentHandler;
  
  import org.xml.sax.SAXException;
  
  public class Mp4Parse {
  
      static int chunk_size = 512;
  
  
      public ArrayList&lt;videoFile&gt; chunkingMethod(String arg) throws IOException,SAXException, TikaException {
  
          String sourcefilePath = arg;
  //      String outputfilePath = &quot;C:\\Users\\ilias-vasilis\\Desktop\\test1\\video0.mp4&quot;;
  
  
          //Next 2 lines exist only to give me the size of the file in bytes
          Path path = Paths.get(sourcefilePath);
          long fileSize = Files.size(path);
  
          int chunk_num = (int)fileSize/chunk_size;
          byte[] temp = new byte[(int)fileSize];
  
          //data structure to store the chunks in
          ArrayList&lt;byte[]&gt; chunks = new ArrayList&lt;&gt;(chunk_num);
  
          //videoFile data structure
          ArrayList&lt;videoFile&gt; video = new ArrayList&lt;&gt;(chunk_num);
  
          //detecting the file type
          BodyContentHandler handler = new BodyContentHandler();
          Metadata metadata = new Metadata();
          FileInputStream inputstream = new FileInputStream(sourcefilePath);
          ParseContext pcontext = new ParseContext();
  
          //Html parser
          MP4Parser MP4Parser = new MP4Parser();
          MP4Parser.parse(inputstream, handler, metadata,pcontext);
          System.out.println(&quot;Contents of the document:  :&quot; + handler.toString());
          System.out.println(&quot;Metadata of the document:&quot;);
          String[] metadataNames = metadata.names();
  
          for(String name : metadataNames) {
              System.out.println(name + &quot;: &quot; + metadata.get(name));
          }
          inputstream.close();
  
          FileInputStream myInputStream = new FileInputStream(new File(sourcefilePath));
  //      FileOutputStream outputStream = new FileOutputStream(new File(outputfilePath));
          while(myInputStream.available() != 0) {
              myInputStream.read(temp);
          }
  
          for(int j = 0; j &lt; chunk_num; j++){
              chunks.add(new byte[512]);
              //Copy the elements of temp in chunks of &quot;chunk_size&quot;
              System.arraycopy(temp, j * chunk_size, chunks.get(j), 0, chunk_size);
          }
  
  
          int i = 0;
          //After splitting the mp4 in chunks make the videoFile objects
          for(byte[] b:chunks) {
  //          outputStream.write(b);
              video.add(new videoFile(b,null));
              i++;
          }
          myInputStream.close();
          return video;
  //      outputStream.close();
     }
  
  
  //##########################################################################################################################
  
      //Simple transfer without splitting
     public videoFile NoChunkMethod(String arg) throws IOException,SAXException, TikaException{
         String sourcefilePath = arg;
  //      String outputfilePath = &quot;C:\\Users\\ilias-vasilis\\Desktop\\Distributed-Systems-Project-main\\Files\\test\\video1.mp4&quot;;
  
  
         //Next 2 lines exist only to give me the size of the file in bytes
         Path path = Paths.get(sourcefilePath);
         long fileSize = Files.size(path);
         byte[] temp = new byte[(int)fileSize];
  
  
         //detecting the file type
         BodyContentHandler handler = new BodyContentHandler();
         Metadata metadata = new Metadata();
         FileInputStream inputstream = new FileInputStream(sourcefilePath);
         ParseContext pcontext = new ParseContext();
  
         //Html parser
         MP4Parser MP4Parser = new MP4Parser();
         MP4Parser.parse(inputstream, handler, metadata,pcontext);
         System.out.println(&quot;Contents of the document:  :&quot; + handler.toString());
         System.out.println(&quot;Metadata of the document:&quot;);
         String[] metadataNames = metadata.names();
  
         for(String name : metadataNames) {
             System.out.println(name + &quot;: &quot; + metadata.get(name));
         }
         inputstream.close();
  
         FileInputStream myInputStream = new FileInputStream(new File(sourcefilePath));
  //       FileOutputStream outputStream = new FileOutputStream(new File(outputfilePath));
  
         int bytesRead;
         while(myInputStream.available() != 0) {
             bytesRead = myInputStream.read(temp);
  //           outputStream.write(temp, 0, bytesRead);
         }
  
         myInputStream.close();
         videoFile video = new videoFile(temp, null);
         return video;
     }
  }
  </code></pre>
  <p><strong>This is pretty much the class I want to store the video in. I will start giving values to the metadata at a later time</strong></p>
  <pre><code>import java.io.Serializable;
  import java.util.*;
  
  public class videoFile implements Serializable {
  
      private static final long serialVersionUID = 1L;
  
      String videoName; //Name of the video (video title)
      String channelName; //Name of the channel it was posted on
      String dateCreated; //The date it was uploaded or the date it is created (taken from metadata if possible)
      String length; //Length of the video in seconds (Maybe declare it as int)
      String framerate; //Self explanatory (maybe declare as int)
      String frameWidth; //Width of the viewing window (maybe declare as int)
      String frameHeight; //Same as above but with height
      ArrayList&lt;String&gt; associatedHashtags; //Hashtags the publisher tagged the video with
      byte[] videoFileChunk; //Byte array, possibly just used to store the entire vid or a single chunk to send over the Internet
      int serialNumber = 0;
  
      public videoFile(){
          videoName = null;
          channelName = null;
          dateCreated = null;
          length = null;
          framerate = null;
          frameWidth = null;
          frameHeight = null;
          associatedHashtags = null;
          videoFileChunk = null;
          serialNumber++;
      }
  
      public videoFile(byte[] chunk, String channelName){
          videoName = null;
          this.channelName = channelName;
          dateCreated = null;
          length = null;
          framerate = null;
          frameWidth = null;
          frameHeight = null;
          associatedHashtags = null;
          videoFileChunk = new byte[chunk.length];
          System.arraycopy(videoFileChunk, 0, chunk, 0, chunk.length);
          serialNumber++;
      }
  
      public videoFile(String vname, String chname, String creationdate, String length,
                       String framerate, String frameWidth, String frameHeight,
                       ArrayList&lt;String&gt; hashtags, byte[] chunk)
      {
          videoName = vname;
          channelName = chname;
          dateCreated = creationdate;
          this.length = length;
          this.frameHeight = framerate;
          this.frameWidth = frameWidth;
          this.frameHeight = frameHeight;
          associatedHashtags = new ArrayList&lt;&gt;(hashtags);
          videoFileChunk = new byte[chunk.length];
          System.arraycopy(videoFileChunk, 0, chunk, 0, chunk.length);
          serialNumber++;
      }
  
      public videoFile(videoFile vidFile){
          videoFileChunk = new byte[vidFile.videoFileChunk.length];
          System.arraycopy(videoFileChunk, 0, vidFile.videoFileChunk,
                  0, vidFile.videoFileChunk.length);
  
          this.channelName = vidFile.channelName;
          videoName = null;
          dateCreated = null;
          length = null;
          framerate = null;
          frameWidth = null;
          frameHeight = null;
          associatedHashtags = null;
      }
  
      public videoFile(videoFile vidFile, String channelName){
  
          this.channelName = channelName;
          videoFileChunk = new byte[vidFile.videoFileChunk.length];
          System.arraycopy(videoFileChunk, 0, vidFile.videoFileChunk,
                  0, vidFile.videoFileChunk.length);
  
          videoName = null;
          dateCreated = null;
          length = null;
          framerate = null;
          frameWidth = null;
          frameHeight = null;
          associatedHashtags = null;
      }
  
      public byte[] getVideoFileChunk(){
          return videoFileChunk;
      }
  
  }
  </code></pre>
  <p><strong>This is the code I use for testing outside of Mp4Parse</strong></p>
  <pre><code>String path = &quot;Files/ConsumerFiles/video1.mp4&quot;;
  Mp4Parse mp4 = new Mp4Parse();
  videoFile temp = new videoFile(mp4.NoChunkMethod(path));
  videoFile video = new videoFile(temp, channelName);
  
  FileOutputStream fop = new FileOutputStream(&quot;Files/test/video1.mp4&quot;);
  fop.write(video.getVideoFileChunk());
  fop.close();
  </code></pre>
  <p>This code does succeed in copying the mp4 file with the correct size but the video doesn't play and Windows gives me a notification that it might be corrupted.</p>