예제 #1
0
 private void backup_folder_buttonActionPerformed(
     java.awt.event.ActionEvent evt) { // GEN-FIRST:event_backup_folder_buttonActionPerformed
   try {
     JFileChooser sel = new JFileChooser();
     sel.setCurrentDirectory(new java.io.File("."));
     sel.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
     sel.setAcceptAllFileFilterUsed(false);
     if (sel.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
       File selFile = sel.getSelectedFile();
       Backup_textfield.setText(selFile.getCanonicalPath());
       path_save_chat = selFile.getCanonicalPath() + "\\";
     } else {
       // do nothing
     }
   } catch (IOException ex) {
     Logger.getLogger(Options.class.getName()).log(Level.SEVERE, null, ex);
   }
 } // GEN-LAST:event_backup_folder_buttonActionPerformed
예제 #2
0
  private void Download_buttonActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_Download_buttonActionPerformed
    try {
      JFileChooser sel = new JFileChooser();

      sel.setCurrentDirectory(new java.io.File("."));
      sel.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

      sel.setAcceptAllFileFilterUsed(false);
      if (sel.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
        File selFile = sel.getSelectedFile();
        Download_Textfield.setText(selFile.getCanonicalPath());
        path_save_download = selFile.getCanonicalPath();
      } else {
      }
    } catch (Exception ex) {

    }
  } // GEN-LAST:event_Download_buttonActionPerformed
  private ProgressMonitorInputStream getMonitorableStream(File file, String message) {
    try {
      FileInputStream stream = new FileInputStream(file);
      if (stream == null) {
        System.out.println("null on " + file.getCanonicalPath());
      }
      final ProgressMonitorInputStream pmis = new ProgressMonitorInputStream(this, message, stream);

      ProgressMonitor progress = pmis.getProgressMonitor();
      progress.setMillisToDecideToPopup(1);
      progress.setMillisToPopup(1);

      return pmis;
    } catch (IOException e) {
      showError("could not open " + file.getName());
      e.printStackTrace();
      return null;
    }
  }
예제 #4
0
파일: View.java 프로젝트: kaschenko/lab3
    public final void initUI() throws FileNotFoundException, IOException {

      String FileName = "config.txt";
      String DirSeparator = System.getProperty("file.separator");
      File currentDir = new File(".");
      String FilePath = currentDir.getCanonicalPath() + DirSeparator + FileName;

      myProperties = new Properties();
      myProperties.load(new FileInputStream(FilePath));

      setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS));

      add(Box.createRigidArea(new Dimension(0, 10)));

      JLabel label = new JLabel();
      label.setAlignmentX(0.5f);
      add(label);

      add(Box.createRigidArea(new Dimension(0, 10)));

      String result = myProperties.getProperty("1");
      if (result == null) result = "0";

      JLabel name = new JLabel("Level 1:  " + result);
      name.setFont(new Font("Serif", Font.BOLD, 13));
      name.setAlignmentX(0.5f);
      add(name);

      result = myProperties.getProperty("2");
      if (result == null) result = "0";
      name = new JLabel("Level 2:  " + result);
      name.setFont(new Font("Serif", Font.BOLD, 13));
      name.setAlignmentX(0.5f);
      add(name);

      result = myProperties.getProperty("3");
      if (result == null) result = "0";
      name = new JLabel("Level 3:  " + result);
      name.setFont(new Font("Serif", Font.BOLD, 13));
      name.setAlignmentX(0.5f);
      add(name);

      result = myProperties.getProperty("4");
      if (result == null) result = "0";
      name = new JLabel("Level 4:  " + result);
      name.setFont(new Font("Serif", Font.BOLD, 13));
      name.setAlignmentX(0.5f);
      add(name);

      result = myProperties.getProperty("5");
      if (result == null) result = "0";
      name = new JLabel("Level 5:  " + result);
      name.setFont(new Font("Serif", Font.BOLD, 13));
      name.setAlignmentX(0.5f);
      add(name);

      myProperties = null;

      add(Box.createRigidArea(new Dimension(0, 50)));

      JButton close = new JButton("Close");
      close.addActionListener(
          new ActionListener() {

            public void actionPerformed(ActionEvent event) {
              dispose();
            }
          });

      close.setAlignmentX(0.5f);
      add(close);

      setModalityType(ModalityType.APPLICATION_MODAL);

      setTitle("Table of records");
      setDefaultCloseOperation(DISPOSE_ON_CLOSE);
      setLocationRelativeTo(null);
      setSize(300, 200);
    }
예제 #5
0
    private static void init() {
      final File basePath = basePath();
      basePath.mkdirs();

      final File namesFile = new File(basePath, "names.dat");
      final File attributesFile = new File(basePath, "attrib.dat");
      final File contentsFile = new File(basePath, "content.dat");
      final File recordsFile = new File(basePath, "records.dat");

      if (!namesFile.exists()) {
        invalidateIndex();
      }

      try {
        if (getCorruptionMarkerFile().exists()) {
          invalidateIndex();
          throw new IOException("Corruption marker file found");
        }

        PagedFileStorage.StorageLockContext storageLockContext =
            new PagedFileStorage.StorageLock(false).myDefaultStorageLockContext;
        myNames = new PersistentStringEnumerator(namesFile, storageLockContext);
        myAttributes = new Storage(attributesFile.getCanonicalPath(), REASONABLY_SMALL);
        myContents =
            new RefCountingStorage(
                contentsFile.getCanonicalPath(),
                CapacityAllocationPolicy
                    .FIVE_PERCENT_FOR_GROWTH); // sources usually zipped with 4x ratio
        boolean aligned = PagedFileStorage.BUFFER_SIZE % RECORD_SIZE == 0;
        assert aligned; // for performance
        myRecords =
            new ResizeableMappedFile(
                recordsFile, 20 * 1024, storageLockContext, PagedFileStorage.BUFFER_SIZE, aligned);

        if (myRecords.length() == 0) {
          cleanRecord(0); // Clean header
          cleanRecord(1); // Create root record
          setCurrentVersion();
        }

        if (getVersion() != VERSION) {
          throw new IOException("FS repository version mismatch");
        }

        if (myRecords.getInt(HEADER_CONNECTION_STATUS_OFFSET) != SAFELY_CLOSED_MAGIC) {
          throw new IOException("FS repository wasn't safely shut down");
        }
        markDirty();
        scanFreeRecords();
      } catch (Exception e) { // IOException, IllegalArgumentException
        LOG.info(
            "Filesystem storage is corrupted or does not exist. [Re]Building. Reason: "
                + e.getMessage());
        try {
          closeFiles();

          boolean deleted = FileUtil.delete(getCorruptionMarkerFile());
          deleted &= deleteWithSubordinates(namesFile);
          deleted &= AbstractStorage.deleteFiles(attributesFile.getCanonicalPath());
          deleted &= AbstractStorage.deleteFiles(contentsFile.getCanonicalPath());
          deleted &= deleteWithSubordinates(recordsFile);

          if (!deleted) {
            throw new IOException("Cannot delete filesystem storage files");
          }
        } catch (final IOException e1) {
          final Runnable warnAndShutdown =
              new Runnable() {
                @Override
                public void run() {
                  if (ApplicationManager.getApplication().isUnitTestMode()) {
                    //noinspection CallToPrintStackTrace
                    e1.printStackTrace();
                  } else {
                    final String message =
                        "Files in "
                            + basePath.getPath()
                            + " are locked.\n"
                            + ApplicationNamesInfo.getInstance().getProductName()
                            + " will not be able to start up.";
                    if (!ApplicationManager.getApplication().isHeadlessEnvironment()) {
                      JOptionPane.showMessageDialog(
                          JOptionPane.getRootFrame(),
                          message,
                          "Fatal Error",
                          JOptionPane.ERROR_MESSAGE);
                    } else {
                      //noinspection UseOfSystemOutOrSystemErr
                      System.err.println(message);
                    }
                  }
                  Runtime.getRuntime().halt(1);
                }
              };

          if (EventQueue.isDispatchThread()) {
            warnAndShutdown.run();
          } else {
            //noinspection SSBasedInspection
            SwingUtilities.invokeLater(warnAndShutdown);
          }

          throw new RuntimeException("Can't rebuild filesystem storage ", e1);
        }

        init();
      }
    }
  private void doSave() {
    myFile = doRead();
    if (myFile == null) {
      return;
    }

    String name = myFile.getName();
    showMessage("compressing " + name);
    String newName =
        JOptionPane.showInputDialog(this, "Name of compressed file", name + HUFF_SUFFIX);
    if (newName == null) {
      return;
    }
    String path = null;
    try {
      path = myFile.getCanonicalPath();
    } catch (IOException e) {
      showError("trouble with file canonicalizing");
      return;
    }
    int pos = path.lastIndexOf(name);
    newName = path.substring(0, pos) + newName;
    final File file = new File(newName);
    try {
      final FileOutputStream out = new FileOutputStream(file);
      ProgressMonitorInputStream temp = null;
      if (myFast) {
        temp = getMonitorableStream(getFastByteReader(myFile), "compressing bits...");
      } else {
        temp = getMonitorableStream(myFile, "compressing bits ...");
      }
      final ProgressMonitorInputStream pmis = temp;
      final ProgressMonitor progress = pmis.getProgressMonitor();
      Thread fileWriterThread =
          new Thread() {
            public void run() {
              try {
                while (!myFirstReadingDone) {
                  try {
                    sleep(100);
                  } catch (InterruptedException e) {
                    // what to do?
                    HuffViewer.this.showError("Trouble in Thread " + e);
                  }
                }
                myModel.compress(pmis, out, myForce);
              } catch (IOException e) {
                HuffViewer.this.showError("compression exception\n " + e);
                cleanUp(file);
                // e.printStackTrace();
              }
              if (progress.isCanceled()) {
                HuffViewer.this.showError("compression cancelled");
                cleanUp(file);
              }
            }
          };
      fileWriterThread.start();
    } catch (FileNotFoundException e) {
      showError("could not open " + file.getName());
      e.printStackTrace();
    }
    myFile = null;
  }
  private void doDecode() {
    File file = null;
    showMessage("uncompressing");
    try {
      int retval = ourChooser.showOpenDialog(null);
      if (retval != JFileChooser.APPROVE_OPTION) {
        return;
      }
      file = ourChooser.getSelectedFile();
      String name = file.getName();
      String uname = name;
      if (name.endsWith(HUFF_SUFFIX)) {
        uname = name.substring(0, name.length() - HUFF_SUFFIX.length()) + UNHUFF_SUFFIX;
      } else {
        uname = name + UNHUFF_SUFFIX;
      }
      String newName = JOptionPane.showInputDialog(this, "Name of uncompressed file", uname);
      if (newName == null) {
        return;
      }
      String path = file.getCanonicalPath();

      int pos = path.lastIndexOf(name);
      newName = path.substring(0, pos) + newName;
      final File newFile = new File(newName);
      ProgressMonitorInputStream temp = null;
      if (myFast) {
        temp = getMonitorableStream(getFastByteReader(file), "uncompressing bits ...");
      } else {
        temp = getMonitorableStream(file, "uncompressing bits...");
      }
      final ProgressMonitorInputStream stream = temp;

      final ProgressMonitor progress = stream.getProgressMonitor();
      final OutputStream out = new FileOutputStream(newFile);
      Thread fileReaderThread =
          new Thread() {
            public void run() {
              try {
                myModel.uncompress(stream, out);
              } catch (IOException e) {

                cleanUp(newFile);
                HuffViewer.this.showError("could not uncompress\n " + e);
                // e.printStackTrace();
              }
              if (progress.isCanceled()) {
                cleanUp(newFile);
                HuffViewer.this.showError("reading cancelled");
              }
            }
          };
      fileReaderThread.start();
    } catch (FileNotFoundException e) {
      showError("could not open " + file.getName());
      e.printStackTrace();
    } catch (IOException e) {
      showError("IOException, uncompression halted from viewer");
      e.printStackTrace();
    }
  }