title: Storing Byte Array inside an Object, and then converting it to ObjectOutputStream? (Stuck)
body: <p>I'm kind of stuck with this problem.</p>
  
  <p>I have this FileDetails class which stores details/metadata of the file along with
  the complete file in a byte array. I want to send the FileDetails object inside ObjectOutputStream across network, where the receiver will
  simple read the file and cast it back to FileDetails.</p>
  
  <p>Here is the code:</p>
  
  <pre><code>class FileDetails {
  
      private String fileName;
      private long fileSize;
      private byte[] fileData;
  
      public FileDetails(String fileName, long fileSize, byte[] fileData) {
          this.fileName = fileName;
          this.fileSize = fileSize;       
          this.fileData = fileData;
      }
  
      public String getFileName() {
          return fileName;
      }
  
      public long getFileSize() {
          return fileSize;
      }
  
      public byte[] getFileData() {
          return fileData;
      }
  
  }
  
  
  File file = new File("C://test.dat");
  RandomAccessFile randFileAccess = new RandomAccessFile(file, "r");
  byte[] buff = new byte[(int) file.length()];
  randFileAccess.readFully(buff);
  
  FileDetails fd = new FileDetails(file.getname(), file.length(); buff);
  
  FileOutputStream fos = = new FileOutputStream(C://oos.dat);
  ObjectOutputStream oos = new ObjectOutputStream(fos);
  oos.writeObject(fd);
  oos.write(buff);
  </code></pre>
  
  <p>The problem is that the file "test.dat" is quite large and it's not optimal to read it fully into the buffer(very large) in one go. I could have read the
  file into the buffer in chunks, but that would require me to create file and save data into the disk, which I cannot do as FileDetails object takes byte array.</p>
  
  <p>How can I solve this problem? I want this approach only, i.e. Storing data as byte array in FileDetails object and then converting it to ObjectOutputStream, because I will be appending 
  the appending an mp3 file infornt of the ObjectOutStream file and sending it over the internet.</p>
  
  <p>Any suggetions? Or alternative approach?</p>
  
  <p><strong>Edit:</strong> <em>Actually I am developing an android app. Where it stores the metadata of the file in a FileDetails object along with the file data in byte array. 
  This FileDetails object is converted into an ObjectOutputStream file. Now an a specific mp3 file is appended in front of this ObjectOutputStream file, which is used to recognize that the file has been sent by my app.
  This combined mp3 file (which contains "hidden" ObjectOutputStream file) is send via a "popular" message app to the receiver.
  The receiver downloads the mp3 file through his "popular" message app. Now my app comes into action. It recognizes the mp3 file. And extracts the  ObjectOutputStream file from the mp3 file. And casts it back to FileDetails and retrieves the Original file with it's metadata.
  Is my approach correct? Is there any other way to recognize my appended/hidden file?</em></p>
  
  <p>Thanks a lot in advance.</p>