📄 cdrecordcontroller.java
字号:
cdrecordProcess.destroy(); } catch(Exception e){ System.out.println("Something went wrong!"); e.printStackTrace(); } medium.setMediumInfo(mediumIsCD, mediumIsDVD, mediumCapasity); } /** * METHOD - Finding out what type and options this drive has */ public void deviceCapabilities(Device device) { boolean atapi = device.getAtapi(); int scsibus = device.getScsibus(); int target = device.getTarget(); int lun = device.getLun(); try{ String addString = ""; if (atapi == true) { addString = "ATAPI:"; } String shellCommand = "cdrecord dev=" + addString + scsibus + "," + target + "," + lun + " -prcap"; Process cdrecordProcess = Runtime.getRuntime().exec(shellCommand); // Get inputstream InputStream cdrecordStream = cdrecordProcess.getInputStream(); InputStreamReader cdrecordStreamReader = new InputStreamReader(cdrecordStream); BufferedReader cdrecordBuffer = new BufferedReader(cdrecordStreamReader); String deviceType = new String(), vendorInfo = new String(), identification = new String(), revision = new String(), description = new String(); int responseFormat = 0, version = 0; boolean isCDdevice = false, isDVDdevice = false, writeCDr = false, writeCDrw = false, writeDVDr = false, writeDVDram = false; //System.out.println("----- PRINTING PROCESS -----"); String bufferLine = cdrecordBuffer.readLine(); while (bufferLine != null) { if (bufferLine.contains(":")) { String[] lineBite = bufferLine.split(":"); if ((lineBite.length > 1) && (lineBite[1] != "") && (lineBite[1] != "\n")) { while ((lineBite[1].startsWith(" ")) || lineBite[1].startsWith("'")) { lineBite[1] = lineBite[1].substring(1); } while ((lineBite[1].endsWith(" ")) || lineBite[1].endsWith("'")) { lineBite[1] = lineBite[1].substring(0, lineBite[1].length()-1); } if (lineBite[0].contains("Device type")) { deviceType = lineBite[1]; } else if (lineBite[0].contains("Version")) { version = Integer.parseInt(lineBite[1]); } else if (lineBite[0].contains("Respons Format")) { responseFormat = Integer.parseInt(lineBite[1]); } else if (lineBite[0].contains("Vendor_info")) { vendorInfo = lineBite[1]; } else if (lineBite[0].contains("Identifikation")) { identification = lineBite[1]; } else if (lineBite[0].contains("Revision")) { revision = lineBite[1]; } else if (lineBite[0].contains("Device seems to be")) { description = lineBite[1]; } } } if (bufferLine.contains("Does")) { if ((bufferLine.contains("read CD-R media")) && (!bufferLine.contains("not"))){ isCDdevice = true; } else if ((bufferLine.contains("read DVD-R media")) && (!bufferLine.contains("not"))){ isDVDdevice = true; } else if ((bufferLine.contains("write CD-R media")) && (!bufferLine.contains("not"))){ writeCDr = true; } else if ((bufferLine.contains("write CD-RW media")) && (!bufferLine.contains("not"))){ writeCDrw = true; } else if ((bufferLine.contains("write DVD-R media")) && (!bufferLine.contains("not"))){ writeDVDr = true; } else if ((bufferLine.contains("write DVD-RAM media")) && (!bufferLine.contains("not"))){ writeDVDram = true; } } //System.out.println(bufferLine); bufferLine = cdrecordBuffer.readLine(); } device.setDeviceInfo(deviceType, version, responseFormat, vendorInfo, identification, revision, description); device.setDeviceCdDvdInfo(isCDdevice, isDVDdevice, writeCDr, writeCDrw, writeDVDr, writeDVDram); cdrecordProcess.destroy(); //System.out.println("----- DESTROYING PROCESS -----"); } catch(Exception e){ System.out.println("Something went wrong!"); e.printStackTrace(); } } /** * METHOD - Burn ISO-file to optical medium */ public boolean burnIso(Device device, String isoFilePath) { boolean result = false; boolean atapi = device.getAtapi(); int scsibus = device.getScsibus(); int target = device.getTarget(); int lun = device.getLun(); try{ String addString = ""; if (atapi == true) { addString = "ATAPI:"; } String burnOptions = "gracetime=0 -sao -eject -v"; int speed = 10; String burnCommand = "cdrecord" + " dev=" + addString + scsibus + "," + target + "," + lun + " speed=" + speed + " " + burnOptions + " " + isoFilePath; System.out.println(burnCommand); Process cdrecordProcess = Runtime.getRuntime().exec(burnCommand); System.out.println("Writing lead in..."); this.fireBurnProcessUpdate(0, 0, "Writing lead in..."); // Get inputstream InputStream cdrecordStream = cdrecordProcess.getInputStream(); InputStreamReader cdrecordStreamReader = new InputStreamReader(cdrecordStream); BufferedReader cdrecordBuffer = new BufferedReader(cdrecordStreamReader); // Get ErrorStream InputStream errorStream = cdrecordProcess.getErrorStream(); InputStreamReader errorStreamReader = new InputStreamReader(errorStream); BufferedReader errorBuffer = new BufferedReader(errorStreamReader); String bufferLine = ""; while (bufferLine != null) { if ((bufferLine.contains("Track 01:")) && (bufferLine.contains("MB written"))) { // Splitting the status string String[] temp = bufferLine.split(":"); String secondPart = temp[1]; temp = secondPart.split("of"); String statusStr = temp[0]; secondPart = temp[1]; temp = secondPart.split("MB"); String goalStr = temp[0]; secondPart = temp[1]; Float burnSpeedFloat = (float)speed; if (secondPart.contains("buf")) { temp = secondPart.split("%]"); secondPart = temp[1]; temp = secondPart.split("x"); String burnSpeedStr = temp[0]; // Converting to number types String burnSpeed = burnSpeedStr.trim(); burnSpeedFloat = Float.valueOf(burnSpeed); } // Converting to number types String status = statusStr.trim(); String goal = goalStr.trim(); Integer goalInt = Integer.valueOf(goal); Integer statusInt = Integer.valueOf(status); // Calculating Burning-status double procentDone = 100.0*((double)statusInt/(double)goalInt); double mbPrSecond = burnSpeedFloat * 0.146; int mbLeft = goalInt - statusInt; int secondsLeft = 0; if (mbLeft != 0) { double secondsFeftDbl = mbLeft/mbPrSecond; secondsLeft = (int)secondsFeftDbl; } System.out.println("Burning... " + statusInt + " of " + goalInt + " MB. Writing Speed: " + burnSpeedFloat); System.out.println("Burning process: " + (int)procentDone + "% done. Estimated time left: " + secondsLeft + " sec."); this.fireBurnProcessUpdate((int)procentDone, secondsLeft, "Burning..."); } if (bufferLine.contains("Fixating...")) { System.out.println(bufferLine); this.fireBurnProcessUpdate(100, 0, "Fixating..."); result = true; } //if(bufferLine.startsWith("Fixating time")) finished = true; if (errorBuffer.ready()) { bufferLine = errorBuffer.readLine(); //System.out.println("ERROR: " + bufferLine); } else { bufferLine = cdrecordBuffer.readLine(); //System.out.println(bufferLine); } } /* String errorLine = errorBuffer.readLine(); while (errorLine != null) { System.out.print("ERROR-BUFFER: "); System.out.println(errorLine); errorLine = errorBuffer.readLine(); }*/ //Thread.sleep(500); System.out.println("Burning process was finalized!"); cdrecordProcess.destroy(); } catch(Exception e){ System.out.println("Something went wrong!"); e.printStackTrace(); } return result; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -