private void downloadActionPerformed( java.awt.event.ActionEvent evt) { // GEN-FIRST:event_downloadActionPerformed try { ClientDetailsUI.main(); } catch (Exception ex) { Logger.getLogger(ClientLoader.class.getName()).log(Level.SEVERE, null, ex); } byte[] part1 = null, part2 = null, part3 = null, part4 = null; File file; // Connecting Database to get file size DBConnection db = new DBConnection(); Statement stmt = db.connect(); try { ResultSet rs = stmt.executeQuery( "select * from fileowner where owner= " + "'" + getUser + "' and fileName='" + fName + "'"); while (rs.next()) { String temp = rs.getString("fileSize"); fileSize = Integer.parseInt(temp); System.out.println(fileSize); } } catch (SQLException ex) { Logger.getLogger(ClientLoader.class.getName()).log(Level.SEVERE, null, ex); } // Getting part1 data file = ClientDetailsUI.download("Cloud Server 1", fileName.getText().trim(), 1); String getContents = FileContentsToString.main(file); BinaryToString bs = new BinaryToString(); String orgForm = null; try { orgForm = bs.getBinaryToString(getContents); } catch (Exception ex) { Logger.getLogger(ClientLoader.class.getName()).log(Level.SEVERE, null, ex); } try { part1 = Decrypt.main(orgForm); } catch (Exception ex) { Logger.getLogger(ClientLoader.class.getName()).log(Level.SEVERE, null, ex); } // Getting part2 data file = ClientDetailsUI.download("Cloud Server 2", fileName.getText().trim(), 2); getContents = FileContentsToString.main(file); orgForm = null; try { orgForm = bs.getBinaryToString(getContents); } catch (Exception ex) { Logger.getLogger(ClientLoader.class.getName()).log(Level.SEVERE, null, ex); } try { part2 = Decrypt.main(orgForm); } catch (Exception ex) { Logger.getLogger(ClientLoader.class.getName()).log(Level.SEVERE, null, ex); } // Getting part3 file = ClientDetailsUI.download("Cloud Server 3", fileName.getText().trim(), 3); getContents = FileContentsToString.main(file); orgForm = null; try { orgForm = bs.getBinaryToString(getContents); } catch (Exception ex) { Logger.getLogger(ClientLoader.class.getName()).log(Level.SEVERE, null, ex); } try { part3 = Decrypt.main(orgForm); } catch (Exception ex) { Logger.getLogger(ClientLoader.class.getName()).log(Level.SEVERE, null, ex); } // Getting part 4 file = ClientDetailsUI.download("Cloud Server 4", fileName.getText().trim(), 4); getContents = FileContentsToString.main(file); orgForm = null; try { orgForm = bs.getBinaryToString(getContents); } catch (Exception ex) { Logger.getLogger(ClientLoader.class.getName()).log(Level.SEVERE, null, ex); } try { part4 = Decrypt.main(orgForm); } catch (Exception ex) { Logger.getLogger(ClientLoader.class.getName()).log(Level.SEVERE, null, ex); } // Merging the Entire file after downloading MergeFile.mergeBytes(part1, part2, part3, part4, fileSize, fileName.getText()); JOptionPane.showMessageDialog(rootPane, "Your File has been Downloaded"); } // GEN-LAST:event_downloadActionPerformed
private void uploadActionPerformed( java.awt.event.ActionEvent evt) { // GEN-FIRST:event_uploadActionPerformed ProgressBar.main(); DBConnection db = new DBConnection(); Statement stmt = db.connect(); try { int rs = stmt.executeUpdate( "insert into fileowner (owner,fileName,fileSize,part1,part2,part3,part4) values " + "('" + getUser + "','" + file.getName().trim() + "'," + fileSize + ",0,0,0,0)"); } catch (SQLException ex) { Logger.getLogger(ClientLoader.class.getName()).log(Level.SEVERE, null, ex); } if (fileName.getText().isEmpty()) { JOptionPane.showMessageDialog(rootPane, "Choose your file"); } else { try { ClientDetailsUI.main(); } catch (Exception ex) { Logger.getLogger(ClientLoader.class.getName()).log(Level.SEVERE, null, ex); } FileOutputStream fos1 = null; FileOutputStream fos2 = null; FileOutputStream fos3 = null; FileOutputStream fos4 = null; FileOutputStream fos5 = null; FileOutputStream fos6 = null; FileOutputStream fos7 = null; FileOutputStream fos8 = null; try { // Getting the chunked contents partHexSignature.getUser(getUser, fileName.getText()); String[] getContents = FileSplit.main(file); String[] XoredContents = XorBinary.main(getContents); System.out.println("File Contents"); System.out.println(getContents[0]); // System.out.println("Xored // Contents:"+Integer.toString(Integer.parseInt(getContents[0])^Integer.parseInt(getContents[1]))); // Uploading file and Create temp file File f1 = new File(fileName.getText()); /* File f2 = new File("c:\\part2\\" + fileName.getText()); File f3 = new File("c:\\part3\\" + fileName.getText()); File f4 = new File("c:\\part4\\" + fileName.getText()); */ fos1 = new FileOutputStream(f1); fos2 = new FileOutputStream(f1); fos3 = new FileOutputStream(f1); fos4 = new FileOutputStream(f1); fos5 = new FileOutputStream(f1); fos6 = new FileOutputStream(f1); fos7 = new FileOutputStream(f1); fos8 = new FileOutputStream(f1); try { fos1.write(getContents[0].getBytes()); ClientDetailsUI.upload(f1, "Cloud Server 1", 1); ClientDetailsUI.upload(f1, "Replica Server 1", 5); fos1.close(); f1.delete(); // fos.write("".getBytes()); fos2.write(getContents[1].getBytes()); ClientDetailsUI.upload(f1, "Cloud Server 2", 2); ClientDetailsUI.upload(f1, "Replica Server 2", 6); fos2.close(); f1.delete(); // f2.delete(); // fos3.write("".getBytes()); fos3.write(getContents[2].getBytes()); ClientDetailsUI.upload(f1, "Cloud Server 3", 3); ClientDetailsUI.upload(f1, "Replica Server 3", 7); fos3.close(); f1.delete(); // f3.delete(); // fos.write("".getBytes()); fos4.write(getContents[3].getBytes()); ClientDetailsUI.upload(f1, "Cloud Server 4", 4); ClientDetailsUI.upload(f1, "Replica Server 4", 8); fos4.close(); f1.delete(); // f4.delete(); fos5.write(XoredContents[0].getBytes()); ClientDetailsUI.upload(f1, "Xor Server 1", 9); fos5.close(); f1.delete(); fos6.write(XoredContents[1].getBytes()); ClientDetailsUI.upload(f1, "Xor Server 2", 9); fos1.close(); f1.delete(); fos7.write(XoredContents[2].getBytes()); ClientDetailsUI.upload(f1, "Xor Server 3", 9); fos1.close(); f1.delete(); fos8.write(XoredContents[3].getBytes()); ClientDetailsUI.upload(f1, "Xor Server 4", 9); fos1.close(); f1.delete(); } catch (IOException ex) { Logger.getLogger(ClientLoader.class.getName()).log(Level.SEVERE, null, ex); } fileName.setText(""); JOptionPane.showMessageDialog(rootPane, "Your file has been uploaded" + fileName.getText()); } catch (FileNotFoundException ex) { Logger.getLogger(ClientLoader.class.getName()).log(Level.SEVERE, null, ex); } finally { } } // TODO add your handling code here: } // GEN-LAST:event_uploadActionPerformed