Example #1
0
 static void copy(InputStream is, int size, String name) throws IOException {
   //        System.out.print("Writing " + name + " (" + size + " bytes)... ");
   byte[] b = new byte[size];
   Composition.readFully(is, b, 0, size);
   OutputStream os = new FileOutputStream(name);
   os.write(b);
   os.close();
   //        System.out.println("done");
 }
Example #2
0
  static Composition read(InputStream stream, String path) throws IOException, DecodingException {
    byte[] bytes = new byte[HeaderSize];
    if (HeaderSize != stream.read(bytes)) throw error("Cannot read");
    Composition c = Codecs.decode(codec, bytes);
    if (!c.sign.equals("Nemo Fi\0")) throw error("Not a composition file");

    bytes = new byte[c.componentsSize + 4];
    stream.mark(4096 + c.compcsz);

    InputStream is = (c.componentsSize == c.compcsz) ? stream : new InflaterInputStream(stream);

    ByteBuffer.wrap(bytes).putInt(c.componentsCount);
    //        if (c.componentsSize != is.read(bytes, 4, c.componentsSize)) throw error("Cannot read
    // components");
    readFully(is, bytes, 4, c.componentsSize);

    ComponentList list = Codecs.decode(cListCodec, bytes);
    c.components = list.components;

    stream.reset();
    stream.skip(c.compcsz);
    is = (c.objcsz == c.objsz) ? stream : new InflaterInputStream(stream);
    int totalSize = c.componentsSize + HeaderSize;

    for (int i = 0, componentsLength = c.components.length; i < componentsLength; i++) {
      Component component = i == 0 ? null : c.components[i - 1];
      int size;
      String name;
      size = c.components[i].getOffset() - totalSize;
      name = component == null ? "00000_PARAMETEROPERATION" : componentFileName(component);
      copy(is, size, path + name);
      totalSize += size;
    }
    Component component = c.components[c.components.length - 1];
    int size = c.objsz - component.getOffset() + c.componentsSize + HeaderSize;
    String name = componentFileName(component);
    copy(is, size, path + name);

    return c;
  }