@Override public void actionPerformed(ActionEvent ev) { if (ev.getSource() == btn) { File file; String string = ""; try { if (radioRead.isSelected()) { file = new File(txt.getText()); DataInputStream input = new DataInputStream(new FileInputStream(file)); int inByte; while ((inByte = input.read()) != -1) { string += (char) inByte; } input.close(); } else if (radioEncrypt.isSelected()) { string = fileContent.getOut(); String strEncrypt = new String(); for (int i = 0; i < string.length(); i++) { char ch = string.charAt(i); if (ch >= 'A' && ch <= 'Z') { ch += 13; if (ch > 'Z') { ch -= 26; } } else if (ch >= 'a' && ch <= 'z') { ch += 13; if (ch > 'z') { ch -= 26; } } strEncrypt += ch; } string = strEncrypt; } if (fileContent == null) { fileContent = new FileContent(string); } else { fileContent.setVisible(true); fileContent.setOut(string); } } catch (FileNotFoundException e) { JOptionPane.showMessageDialog(this, "Can't find the file."); } catch (IOException e) { JOptionPane.showMessageDialog(this, "IO Exception " + e.getMessage()); } } }
private InputStream inputStreamFrom(final FileContent content) throws FileSystemException { return content.getInputStream(); }
private ZipEntry entryFor(final String name, final FileContent content) throws FileSystemException { final ZipEntry entry = new ZipEntry(name); entry.setTime(content.getLastModifiedTime()); return entry; }