Subversion Repositories display

Rev

Rev 425 | Blame | Compare with Previous | Last modification | View Log | RSS feed

/*
 * Copyright (C) 2007 Steve Ratcliffe
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License version 2 as
 *  published by the Free Software Foundation.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *
 * Author: Steve Ratcliffe
 * Create date: 20-Oct-2007
 */

package test;

import uk.me.parabola.imgfmt.FileSystemParam;
import uk.me.parabola.imgfmt.fs.FileSystem;
import uk.me.parabola.imgfmt.fs.ImgChannel;
import uk.me.parabola.imgfmt.sys.FileImgChannel;
import uk.me.parabola.imgfmt.sys.ImgFS;

import java.io.File;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.List;

/**
 * Combines several files into one .img file.
 * Kind of the opposite of ExtractFile.
 * @author Steve Ratcliffe
 */

public class ZipFile {
        public static void main(String[] args) throws IOException {
                FileSystemParam params = new FileSystemParam();

                boolean first = true;
                String outfile = "63240001.img";
                List<String> inlist = new ArrayList<>();
                for (String arg : args) {
                        if (arg.startsWith("--block-size")) {
                                int bsize = Integer.parseInt(arg.substring(13));
                                params.setBlockSize(bsize);
                        } else if (first) {
                                outfile = arg;
                                first = false;
                        } else {
                                inlist.add(arg);
                        }
                }

                FileSystem fs = ImgFS.createFs(outfile, params);

                for (String name : inlist) {
                        System.out.println("file " + name);
                        File f = new File(name);
                        try (FileImgChannel fin = new FileImgChannel(name, "r");
                                 ImgChannel fout = fs.create(f.getName().toUpperCase()))
                        {
                                ByteBuffer buf = ByteBuffer.allocate(64*1024);
                                while (fin.read(buf) > 0) {
                                        buf.flip();
                                        fout.write(buf);
                                        buf.compact();
                                }
                        }
                }

                fs.sync();
                fs.close();
        }
}