Examples of File


Examples of java.io.File

   * to be a dynamic document.
   */
  public HttpDoc retrieveFromCache(URL u) {
  String ext = getExtension(u);
  if (ext == null) return null;
  File cacheFile = getCacheFile(u);
  if (cacheFile == null) return null;
   
    // create a buffer;
    long size = cacheFile.length();
    if (size > Integer.MAX_VALUE) {
      log.info("File too large");
      return null;
    }

View Full Code Here

Examples of java.io.File

      if (filename.charAt(i) == File.separatorChar) {
  pos = i;
  i = -1;
      }
    }
    File dir = new File(filename.substring(0, pos));
    dir.mkdirs();
  }
View Full Code Here

Examples of java.io.File

    // Allow a properties file in the WekaPackageManager.PROPERTIES_DIR to override
    Properties userProps = new Properties(defaultProps);
    if (!WekaPackageManager.PROPERTIES_DIR.exists()) {
      WekaPackageManager.PROPERTIES_DIR.mkdir();
    }
    File propFile = new File(WekaPackageManager.PROPERTIES_DIR.toString()
                             + File.separator
                             + resourceName);

    if (propFile.exists()) {
      try {
        userProps.load(new FileInputStream(propFile));
      } catch (Exception ex) {
        throw new Exception("Problem reading user properties: " + propFile);
      }
    }

    // Allow a properties file in the current directory to override
    Properties localProps = new Properties(userProps);
    propFile = new File(resourceName);
    if (propFile.exists()) {
      try {
        localProps.load(new FileInputStream(propFile));
      } catch (Exception ex) {
        throw new Exception("Problem reading local properties: " + propFile);
      }
View Full Code Here

Examples of java.io.File

   * @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
   */
  public static File convertToRelativePath(File absolute) throws Exception {
    File        result;
    String      fileStr;
   
    result = null;
   
    // if we're running windows, it could be Cygwin
    if (File.separator.equals("\\")) {
      // Cygwin doesn't like upper case drives -> try lower case drive
      try {
        fileStr = absolute.getPath();
        fileStr =   fileStr.substring(0, 1).toLowerCase()
                  + fileStr.substring(1);
        result = createRelativePath(new File(fileStr));
      }
      catch (Exception e) {
        // no luck with Cygwin workaround, convert it like it is
        result = createRelativePath(absolute);
      }
View Full Code Here

Examples of java.io.File

   * @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

Examples of java.io.File

   * 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

Examples of java.io.File

   * @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

Examples of java.io.File

  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

Examples of java.io.File

   * @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

Examples of java.io.File

      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
TOP
Copyright © 2018 www.massapi.com. 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.