Imported initial java bindings
This commit is contained in:
152
java/src/test/org/pykix/libburnia/test/IsoFsMain.java
Normal file
152
java/src/test/org/pykix/libburnia/test/IsoFsMain.java
Normal file
@ -0,0 +1,152 @@
|
||||
/*
|
||||
* Main.java
|
||||
*
|
||||
* Copyright (c) 2007 Vreixo Formoso
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
* See COPYING file for details.
|
||||
*/
|
||||
|
||||
package org.pykix.libburnia.test;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.EnumSet;
|
||||
|
||||
import org.pykix.libburnia.libburn.BurnSource;
|
||||
import org.pykix.libburnia.libburn.Source;
|
||||
import org.pykix.libburnia.libisofs.Ecma119ExtensionFlag;
|
||||
import org.pykix.libburnia.libisofs.IsoTreeNode;
|
||||
import org.pykix.libburnia.libisofs.IsoVolSet;
|
||||
import org.pykix.libburnia.libisofs.IsoVolume;
|
||||
|
||||
public class IsoFsMain {
|
||||
|
||||
private static void usage() {
|
||||
System.out.println("Main [OPTIONS] DIRECTORY OUTPUT");
|
||||
}
|
||||
|
||||
private static void help()
|
||||
{
|
||||
System.out.println(
|
||||
"Options:\n" +
|
||||
" -J Add Joliet support\n" +
|
||||
" -R Add Rock Ridge support\n" +
|
||||
" -L <num> Set the ISO level (1 or 2)\n" +
|
||||
" -h Print this message"
|
||||
);
|
||||
}
|
||||
|
||||
private static void invalidOption(String opt) {
|
||||
System.out.println("Invalid option: " + opt +
|
||||
". Try Main -h for help");
|
||||
usage();
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
|
||||
EnumSet<Ecma119ExtensionFlag> flags =
|
||||
EnumSet.noneOf(Ecma119ExtensionFlag.class);
|
||||
int level = 1;
|
||||
|
||||
/* parse cmd line. */
|
||||
int i = 0;
|
||||
while ( i < args.length ) {
|
||||
String arg = args[i];
|
||||
|
||||
if ( arg.startsWith("-") ) {
|
||||
|
||||
if (arg.length() > 2) {
|
||||
invalidOption(arg);
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
char opt = arg.charAt(1);
|
||||
|
||||
switch (opt) {
|
||||
case 'h':
|
||||
usage();
|
||||
help();
|
||||
System.exit(0);
|
||||
break;
|
||||
case 'J':
|
||||
flags.add(Ecma119ExtensionFlag.JOLIET);
|
||||
break;
|
||||
case 'R':
|
||||
flags.add(Ecma119ExtensionFlag.ROCKRIDGE);
|
||||
break;
|
||||
case 'L':
|
||||
/* get level value */
|
||||
if ( ++i < args.length ) {
|
||||
level = Integer.parseInt(args[i]);
|
||||
} else {
|
||||
System.out.println("Level number needed");
|
||||
usage();
|
||||
help();
|
||||
System.exit(1);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
invalidOption(arg);
|
||||
System.exit(1);
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
} else {
|
||||
break; /* exit loop, no more options */
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (args.length < i + 1) {
|
||||
System.out.println("Please pass directory from which to build ISO");
|
||||
usage();
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
if (args.length < i + 2) {
|
||||
System.out.println("Please supply output file");
|
||||
usage();
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
FileOutputStream f = null;
|
||||
try {
|
||||
f = new FileOutputStream(args[i+1]);
|
||||
} catch (FileNotFoundException e) {
|
||||
System.out.println("error opening output file");
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
File dir = new File(args[i]);
|
||||
IsoTreeNode root = null;
|
||||
try {
|
||||
root = IsoTreeNode.raddDir(null, dir);
|
||||
} catch (FileNotFoundException e) {
|
||||
System.out.println("Input directory not found");
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
if ( root == null ) {
|
||||
System.out.println("Error opening input directory.");
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
IsoVolume volume = new IsoVolume("VOLID", "PUBID", "PREPID", root);
|
||||
IsoVolSet volset = new IsoVolSet( volume, "VOLSETID" );
|
||||
BurnSource src = new Source(volset, 0, level, flags);
|
||||
|
||||
byte [] buf = new byte[2048];
|
||||
while ( src.read(buf, 2048) == 2048 ) {
|
||||
f.write(buf);
|
||||
}
|
||||
f.close();
|
||||
}
|
||||
|
||||
}
|
212
java/src/test/org/pykix/libburnia/test/Test.java
Normal file
212
java/src/test/org/pykix/libburnia/test/Test.java
Normal file
@ -0,0 +1,212 @@
|
||||
/*
|
||||
* Test.java
|
||||
*
|
||||
* Copyright (c) 2007 Vreixo Formoso
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
* See COPYING file for details.
|
||||
*/
|
||||
|
||||
package org.pykix.libburnia.test;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.pykix.libburnia.libburn.BlockType;
|
||||
import org.pykix.libburnia.libburn.Burn;
|
||||
import org.pykix.libburnia.libburn.BurnException;
|
||||
import org.pykix.libburnia.libburn.BurnSource;
|
||||
import org.pykix.libburnia.libburn.Disc;
|
||||
import org.pykix.libburnia.libburn.DiscStatus;
|
||||
import org.pykix.libburnia.libburn.Drive;
|
||||
import org.pykix.libburnia.libburn.DriveInfo;
|
||||
import org.pykix.libburnia.libburn.DriveStatus;
|
||||
import org.pykix.libburnia.libburn.FormatDesc;
|
||||
import org.pykix.libburnia.libburn.Formats;
|
||||
import org.pykix.libburnia.libburn.Message;
|
||||
import org.pykix.libburnia.libburn.MultiCaps;
|
||||
import org.pykix.libburnia.libburn.Profile;
|
||||
import org.pykix.libburnia.libburn.Progress;
|
||||
import org.pykix.libburnia.libburn.ReadOpts;
|
||||
import org.pykix.libburnia.libburn.ScsiAdr;
|
||||
import org.pykix.libburnia.libburn.Session;
|
||||
import org.pykix.libburnia.libburn.Source;
|
||||
import org.pykix.libburnia.libburn.SpeedDescriptor;
|
||||
import org.pykix.libburnia.libburn.Track;
|
||||
import org.pykix.libburnia.libburn.WriteOpts;
|
||||
import org.pykix.libburnia.libburn.WriteType;
|
||||
import org.pykix.libburnia.libburn.Message.Severity;
|
||||
|
||||
public class Test {
|
||||
|
||||
private static int blankDisc(Drive drive, boolean fast)
|
||||
throws InterruptedException, BurnException {
|
||||
|
||||
DiscStatus state = drive.getDiscStatus();
|
||||
Profile profile = drive.getProfile();
|
||||
|
||||
System.out.println("Disc state: " + state);
|
||||
|
||||
if (profile == Profile.DVD_RW_RESTRICTED_OVERWITE) {
|
||||
/* formatted DVD-RW will get blanked to sequential state */
|
||||
} else if (state == DiscStatus.BLANK) {
|
||||
System.err.println(
|
||||
"IDLE: Blank media detected. Will leave it untouched");
|
||||
return 2;
|
||||
} else if (state == DiscStatus.FULL ||
|
||||
state == DiscStatus.APPENDABLE) {
|
||||
/* this is what libburner is willing to blank */
|
||||
} else if (state == DiscStatus.EMPTY) {
|
||||
System.err.println("FATAL: No media detected in drive");
|
||||
return 0;
|
||||
} else {
|
||||
System.err.println("FATAL: Unsuitable drive and media state");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if( !drive.isErasable() ) {
|
||||
System.err.println("FATAL : Media is not of erasable type");
|
||||
return 0;
|
||||
}
|
||||
|
||||
System.out.println("Beginning to " + (fast?"fast":"full") + "-blank media.");
|
||||
|
||||
drive.erase(fast);
|
||||
|
||||
Thread.sleep(1000);
|
||||
|
||||
Progress p = new Progress();
|
||||
|
||||
while ( drive.getDriveStatus(p) != DriveStatus.IDLE ) {
|
||||
|
||||
System.out.printf("Blanking ( %.1f%% done )\n",
|
||||
(float) p.getSector() * 100 / p.getSectors() );
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
|
||||
System.out.println("Done");
|
||||
return 1;
|
||||
|
||||
}
|
||||
|
||||
private static int writeImage(Drive drive, String path)
|
||||
throws InterruptedException, BurnException {
|
||||
|
||||
WriteOpts wo = drive.newWriteOpts();
|
||||
|
||||
wo.setMulti(true);
|
||||
wo.setWriteType(WriteType.SAO, BlockType.MODE2_OK);
|
||||
|
||||
BurnSource src = new Source(path, null);
|
||||
|
||||
Disc disc = new Disc();
|
||||
Session s = new Session();
|
||||
Track t = new Track();
|
||||
t.setSource(src);
|
||||
s.addTrack(t, 0);
|
||||
disc.addSession(s, 0);
|
||||
|
||||
wo.precheckWrite(disc, false);
|
||||
|
||||
drive.write(wo, disc);
|
||||
|
||||
Thread.sleep(1000);
|
||||
|
||||
Progress p = new Progress();
|
||||
|
||||
while ( drive.getDriveStatus(p) != DriveStatus.IDLE ) {
|
||||
|
||||
System.out.printf("Blanking ( %.1f%% done )\n",
|
||||
(float) p.getSector() * 100 / p.getSectors() );
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws BurnException, InterruptedException {
|
||||
|
||||
Burn.initialize();
|
||||
// Message.setSeverities(Severity.ALL, Severity.ALL, "Test: ");
|
||||
|
||||
// DriveInfo[] drives = Burn.scan();
|
||||
// Drive drive = drives[0].getDrive();
|
||||
|
||||
// drive.grab(true);
|
||||
|
||||
System.out.println(Burn.convertFsAdr("/dev/sr0"));
|
||||
|
||||
DriveInfo info = Burn.scanAndGrab("/dev/sg1", true);
|
||||
|
||||
Drive drive = info.getDrive();
|
||||
|
||||
// ScsiAdr ad = ScsiAdr.obtainScsiAdr(info.getAdr());
|
||||
// System.out.println(Burn.getVersion());
|
||||
// Burn.setSignalHandler( new Burn.SignalHandler() {
|
||||
// public int handleSignal(int signum, int flag) {
|
||||
// System.err.println("handled signal " + signum);
|
||||
// System.err.flush();
|
||||
// return -1;
|
||||
// }
|
||||
// }, 0);
|
||||
|
||||
Formats fs = drive.getFormats();
|
||||
|
||||
System.out.println("blsas = " + fs.getBlSas() +
|
||||
", size = " + fs.getSize() +
|
||||
", status = " + fs.getStatus());
|
||||
|
||||
FormatDesc fd = drive.getFormatDescr(0);
|
||||
|
||||
System.out.println(" Type = " + fd.getType() +
|
||||
", size = " + fd.getSize() );
|
||||
|
||||
// WriteOpts wo = drive.newWriteOpts();
|
||||
//
|
||||
// System.out.println(drive.getAvailableSpace(wo));
|
||||
|
||||
// drive.readAtip();
|
||||
//
|
||||
// MultiCaps mc = drive.getMultiCaps(WriteType.SAO);
|
||||
//
|
||||
// System.out.println( mc.getCurrentProfile() );
|
||||
//
|
||||
// mc = drive.getMultiCaps(WriteType.SAO);
|
||||
// System.out.println( mc.isWritingPossible() );
|
||||
|
||||
// System.out.println( drive.getTrackNwa(null, 2) );
|
||||
|
||||
// SpeedDescriptor[] sl = drive.getSpeedList();
|
||||
//
|
||||
// for ( SpeedDescriptor sd : sl ) {
|
||||
// System.out.println( sd.getWriteSpeed() + " " + sd.getSource() );
|
||||
// }
|
||||
//
|
||||
// Message msg;
|
||||
// while ( (msg = Message.obtain(Severity.ALL)) != null ) {
|
||||
// System.out.println(msg.getMsgText());
|
||||
// }
|
||||
|
||||
// blankDisc(drive, true);
|
||||
// writeImage(drive, "/home/metalpain/image.iso");
|
||||
|
||||
// ReadOpts opts = drive.newReadOpts();
|
||||
|
||||
// System.out.println( drive.getWriteSpeed() );
|
||||
|
||||
// long i = 0;
|
||||
// while( i++ < 10000000000L) {
|
||||
// //System.out.print("aa");
|
||||
// }
|
||||
|
||||
drive.release(false);
|
||||
|
||||
// drives[0].forget(0);
|
||||
info.forget(0);
|
||||
|
||||
Burn.finish();
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user