Package java.io

Examples of java.io.File$LazyInitialization


   * @param absolute the File to convert to relative path
   * @return a File with a path that is relative to the user's directory
   * @exception Exception if the path cannot be constructed
   */
  protected static File createRelativePath(File absolute) throws Exception {
    File userDir = new File(System.getProperty("user.dir"));
    String userPath = userDir.getAbsolutePath() + File.separator;
    String targetPath = (new File(absolute.getParent())).getPath()
      + File.separator;
    String fileName = absolute.getName();
    StringBuffer relativePath = new StringBuffer();
    //    relativePath.append("."+File.separator);
    //    System.err.println("User dir "+userPath);
    //    System.err.println("Target path "+targetPath);
   
    // file is in user dir (or subdir)
    int subdir = targetPath.indexOf(userPath);
    if (subdir == 0) {
      if (userPath.length() == targetPath.length()) {
  relativePath.append(fileName);
      } else {
  int ll = userPath.length();
  relativePath.append(targetPath.substring(ll));
  relativePath.append(fileName);
      }
    } else {
      int sepCount = 0;
      String temp = new String(userPath);
      while (temp.indexOf(File.separator) != -1) {
  int ind = temp.indexOf(File.separator);
  sepCount++;
  temp = temp.substring(ind+1, temp.length());
      }
     
      String targetTemp = new String(targetPath);
      String userTemp = new String(userPath);
      int tcount = 0;
      while (targetTemp.indexOf(File.separator) != -1) {
  int ind = targetTemp.indexOf(File.separator);
  int ind2 = userTemp.indexOf(File.separator);
  String tpart = targetTemp.substring(0,ind+1);
  String upart = userTemp.substring(0,ind2+1);
  if (tpart.compareTo(upart) != 0) {
    if (tcount == 0) {
      tcount = -1;
    }
    break;
  }
  tcount++;
  targetTemp = targetTemp.substring(ind+1, targetTemp.length());
  userTemp = userTemp.substring(ind2+1, userTemp.length());
      }
      if (tcount == -1) {
  // then target file is probably on another drive (under windows)
  throw new Exception("Can't construct a path to file relative to user "
          +"dir.");
      }
      if (targetTemp.indexOf(File.separator) == -1) {
  targetTemp = "";
      }
      for (int i = 0; i < sepCount - tcount; i++) {
  relativePath.append(".."+File.separator);
      }
      relativePath.append(targetTemp + fileName);
    }
    //    System.err.println("new path : "+relativePath.toString());
    return new File(relativePath.toString());
  }
View Full Code Here


   * weka.gui.GUICHooser.HowToFindPackageManager).
   * @return true if the user has opted not to view the named dialog
   * in the future.
   */
  public static boolean getDontShowDialog(String dialogName) {
    File wekaHome = WekaPackageManager.WEKA_HOME;
   
    if (!wekaHome.exists()) {
      return false;
    }
   
    File dialogSubDir = new File(wekaHome.toString() + File.separator + "systemDialogs");
    if (!dialogSubDir.exists()) {
      return false;
    }
   
    File dialogFile = new File(dialogSubDir.toString() + File.separator + dialogName);
   
    return dialogFile.exists();
  }
View Full Code Here

   * @throws Exception if the marker file that is used to indicate that
   * a named dialog is not to be shown can't be created. This file lives
   * in $WEKA_HOME/systemDialogs
   */
  public static void setDontShowDialog(String dialogName) throws Exception {
    File wekaHome = WekaPackageManager.WEKA_HOME;
   
    if (!wekaHome.exists()) {
      return;
    }
   
    File dialogSubDir = new File(wekaHome.toString() + File.separator + "systemDialogs");
    if (!dialogSubDir.exists()) {
      if (!dialogSubDir.mkdir()) {
        return;
      }
    }
   
    File dialogFile = new File(dialogSubDir.toString() + File.separator + dialogName);
    dialogFile.createNewFile();
  }
View Full Code Here

  public static String getDontShowDialogResponse(String dialogName) throws Exception {
    if (!getDontShowDialog(dialogName)) {
      return null; // This must be the first time - no file recorded yet.
    }
   
    File wekaHome = WekaPackageManager.WEKA_HOME;
    File dialogSubDir = new File(wekaHome.toString() + File.separator
        + "systemDialogs" + File.separator + dialogName);

   
    BufferedReader br = new BufferedReader(new FileReader(dialogSubDir));
    String response = br.readLine();
View Full Code Here

   * @throws Exception if there is a problem saving the information
   */
  public static void setDontShowDialogResponse(String dialogName, String response)
    throws Exception {
   
    File wekaHome = WekaPackageManager.WEKA_HOME;
   
    if (!wekaHome.exists()) {
      return;
    }
   
    File dialogSubDir = new File(wekaHome.toString() + File.separator + "systemDialogs");
    if (!dialogSubDir.exists()) {
      if (!dialogSubDir.mkdir()) {
        return;
      }
    }
   
    File dialogFile = new File(dialogSubDir.toString() + File.separator + dialogName);
    BufferedWriter br = new BufferedWriter(new FileWriter(dialogFile));
    br.write(response + "\n");
    br.flush();
    br.close();
  }
View Full Code Here

      if (m_FileChooser == null) {
  createFileChooser();
      }
      int returnVal = m_FileChooser.showOpenDialog(this);
      if (returnVal == JFileChooser.APPROVE_OPTION) {
  File selected = m_FileChooser.getSelectedFile();
  try {
    ObjectInputStream oi = new ObjectInputStream(new BufferedInputStream(new FileInputStream(selected)));
    Object obj = oi.readObject();
    oi.close();
    if (!m_ClassType.isAssignableFrom(obj.getClass())) {
      throw new Exception("Object not of type: " + m_ClassType.getName());
    }
    return obj;
  } catch (Exception ex) {
    JOptionPane.showMessageDialog(this,
          "Couldn't read object: "
          + selected.getName()
          + "\n" + ex.getMessage(),
          "Open object file",
          JOptionPane.ERROR_MESSAGE);
  }
      }
View Full Code Here

      if (m_FileChooser == null) {
  createFileChooser();
      }
      int returnVal = m_FileChooser.showSaveDialog(this);
      if (returnVal == JFileChooser.APPROVE_OPTION) {
  File sFile = m_FileChooser.getSelectedFile();
  try {
    ObjectOutputStream oo = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(sFile)));
    oo.writeObject(object);
    oo.close();
  } catch (Exception ex) {
    JOptionPane.showMessageDialog(this,
          "Couldn't write to file: "
          + sFile.getName()
          + "\n" + ex.getMessage(),
          "Save object",
          JOptionPane.ERROR_MESSAGE);
  }
      }
View Full Code Here

    /**
     * Creates the file chooser the user will use to save/load files with.
     */
    protected void createFileChooser() {
     
      m_FileChooser = new JFileChooser(new File(System.getProperty("user.dir")));
      m_FileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    }
View Full Code Here

   
    super.setOptions(options);
   
    tmpStr = Utils.getOption("model", options);
    if (tmpStr.length() != 0)
      setModelFile(new File(tmpStr));
    else
      setModelFile(new File(System.getProperty("user.dir")));
  }
View Full Code Here

                org.apache.synapse.config.xml.endpoints.TemplateFactory templateFactory =
                        new org.apache.synapse.config.xml.endpoints.TemplateFactory();

                Template tm = templateFactory.createEndpointTemplate(artifactConfig, properties);

                tm.setFileName(new File(fileName).getName());
                if (log.isDebugEnabled()) {
                    log.debug("Endpoint Template named '" + tm.getName()
                            + "' has been built from the file " + fileName);
                }

                getSynapseConfiguration().addEndpointTemplate(tm.getName(), tm);
                if (log.isDebugEnabled()) {
                    log.debug("Template Deployment from file : " + fileName + " : Completed");
                }
                log.info("Endpoint Template named '" + tm.getName()
                        + "' has been deployed from file : " + fileName);

                return tm.getName();
            } else {
                element = artifactConfig.getFirstChildWithName(
                        new QName(SynapseConstants.SYNAPSE_NAMESPACE, "sequence"));
                if (element != null) {
                    Mediator mediator = MediatorFactoryFinder.getInstance().
                            getMediator(artifactConfig, properties);
                    if (mediator instanceof TemplateMediator) {
                        TemplateMediator tm = (TemplateMediator) mediator;

                        tm.setFileName((new File(fileName)).getName());
                        if (log.isDebugEnabled()) {
                            log.debug("Sequence Template named '" + tm.getName()
                                    + "' has been built from the file " + fileName);
                        }
View Full Code Here

TOP

Related Classes of java.io.File$LazyInitialization

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.