private boolean readack() throws IOException { byte[] laBuffer = new byte[1]; if (_read(laBuffer, 0, 1) > 0) { switch (laBuffer[0]) { case 1: return true; case -4: Logfile.Write("Disk is Busy (Record/Replay in Progress)"); /* * Busy Loop */ try { Thread.sleep(1000); rewrite(); } catch (InterruptedException e) { e.printStackTrace(); } return readack(); case -7: Logfile.Write("Disk is staring up..."); return readack(); } } return false; }
public int GetActiveThreadCount() { Lock(); Logfile.Write("Active Threads " + m_nActivePostCopyThreads); int lnReturn = m_nActivePostCopyThreads; Unlock(); return lnReturn; }
/* * Remove a File from the Receiver FS */ public boolean Rm(DvrFile poFile) throws Exception { if (!poFile.isRecNo()) { System.out.println("File has no unique Record Number (Not implemented)"); return false; } Lock(); Logfile.Write("Removing File " + poFile); boolean lbOk = false; ByteArrayOutputStream loLowLevelCommand = new ByteArrayOutputStream(); DataOutputStream loCommand = new DataOutputStream(loLowLevelCommand); byte lbResponse = 0; try { loCommand.writeByte(0x17); loCommand.writeShort(poFile.getRecNo()); write(loLowLevelCommand.toByteArray()); lbResponse = readbyte(); if (lbResponse == 1) { lbOk = true; poFile.m_oParent.m_oFiles.remove(poFile); } else System.out.println("Error in Receiver Response (RM Command) " + lbResponse); } catch (IOException e) { e.printStackTrace(); } Unlock(); return lbOk; }
private BufferedOutputStream createdstfile(String pcDstFile) throws IOException { File loTsFile = new File(pcDstFile); if (loTsFile.exists()) { if (Props.Get("SAFEITY").equals("1")) { Logfile.Write("Error File " + pcDstFile + " already exists!"); throw new IOException("Error File " + pcDstFile + " already exists!"); } } FileOutputStream loFileWriter = new FileOutputStream(pcDstFile); BufferedOutputStream loFastFileWriter = new BufferedOutputStream(loFileWriter); return loFastFileWriter; }
private boolean resumeread(byte pbFlag) throws InterruptedException, IOException { if (pbFlag >= 0) return true; switch (pbFlag) { case -4: case -7: Logfile.Write("Device is Busy!"); break; case (byte) 0xff: return false; default: throw new IOException("Unknown Protocol Flag " + pbFlag); } return true; }
public void run() { try { Runtime loRt = Runtime.getRuntime(); String[] lcCommand = new String[] {m_cCommand, m_cDstFile, String.valueOf(m_oFile.getIndex())}; // Logfile.Write("Execute: "+lcCommand); Process loProc = loRt.exec(lcCommand); try { int lnExitCode = loProc.waitFor(); m_oProcessor.Lock(); Logfile.Write("PostCopyScript exited with Exit Code " + lnExitCode); m_oProcessor.m_nActivePostCopyThreads--; m_oProcessor.Unlock(); } catch (InterruptedException e) { e.printStackTrace(); } } catch (IOException e) { e.printStackTrace(); } }
/* * Download a File from the Reciever to the * Destination File specified in pcDstFile */ public boolean Download(DvrFile poFile, String pcDstFile) { /* * Parameter Checks */ if (pcDstFile.endsWith("/")) { pcDstFile = pcDstFile + poFile.getUniqueFileName(); } String lcPostCopyAction = Props.Get("POSTCOPYSCRIPT"); int lnPostCopyThreads = Integer.parseInt(Props.Get("POSTCOPYTHREADCOUNT")); boolean lbStartDownload = false; boolean lbPostCopyAction = false; boolean lbReturn = false; if (lcPostCopyAction.equals("")) { Lock(); } else { lbPostCopyAction = true; do { Lock(); if (m_nActivePostCopyThreads < lnPostCopyThreads) { m_nActivePostCopyThreads++; lbStartDownload = true; } else { Unlock(); try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } } } while (!lbStartDownload); } /* * Socket Streams */ ByteArrayOutputStream loSocketWriteLow = new ByteArrayOutputStream(); DataOutputStream loSocketWrite = new DataOutputStream(loSocketWriteLow); String laDstFiles[]; try { Logfile.Write("Copy File " + poFile.getFileName() + " to " + pcDstFile); if (poFile.m_nType == 1) { write(new byte[] {Header.PT_GETFILE_BYNAME, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0}); readbyte(); write(poFile.m_oParent.m_cRemoteName.getBytes("CP1252")); readbyte(); ping(); write(poFile.getFileName().getBytes("CP1252")); readbyte(); laDstFiles = new String[] {pcDstFile}; readstream_singlepart(createdstfile(pcDstFile)); } else { loSocketWrite.writeByte(Header.PT_GETFILE_BYRECNO); // Download Command; loSocketWrite.writeShort(poFile.getIndex()); // File Index loSocketWrite.writeLong(0); // Start Position (maybe!!) write(loSocketWriteLow.toByteArray()); // Send Message to DVR byte lbResponse = readbyte(); long lnFileSize = readlong(); byte lbFileCount = readbyte(); BufferedOutputStream[] laWrite = new BufferedOutputStream[lbFileCount]; laDstFiles = new String[lbFileCount]; for (int i = 0; i < laWrite.length; i++) { byte lbFileNo = readbyte(); laDstFiles[i] = pcDstFile + "." + readstring().toLowerCase(); laWrite[lbFileNo] = createdstfile(laDstFiles[i]); } write(Header.PT_ACK); readstream_multipart(laWrite); } Logfile.Write("Transfer Complete"); if (lbPostCopyAction) { PostCopy loPostCopy = new PostCopy(lcPostCopyAction, poFile, laDstFiles[0], this); loPostCopy.start(); } lbReturn = true; } catch (IOException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } finally { Unlock(); } return lbReturn; }