Changeset 2913


Ignore:
Timestamp:
Nov 15, 2006, 8:37:31 AM (16 years ago)
Author:
Nicklas Nordborg
Message:

Internal subdirectory is now generated taking year, week, day in week and seconds into account
to make sure that not too many files end up in the same directory. The pattern is: yyyy-ww/F-ss
where yyyy = four digit year, ww = two-digit week number of year, F = number of day in week, and
ss = two-digit seconds

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/core/net/sf/basedb/core/File.java

    r2904 r2913  
    454454    {
    455455      // an old file exists
    456       internalFile = new java.io.File(Application.getUserFilesDirectory(), getInternalName());
     456      internalFile = getAbsolutePath(getInternalName());
    457457    }
    458458    if (newInternalFile != null)
     
    871871      return new ByteArrayInputStream(new byte[0]);
    872872    }
    873     java.io.File file = newInternalFile != null ? newInternalFile : new java.io.File(Application.getUserFilesDirectory(), getInternalName());
    874     if(!file.exists())
     873    java.io.File file = newInternalFile != null ? newInternalFile : getAbsolutePath(getInternalName());
     874    if (!file.exists())
    875875    {
    876876      return new ByteArrayInputStream(new byte[0]);
     
    891891  }
    892892
    893   private static final SimpleDateFormat SUBDIR_FORMAT = new SimpleDateFormat("yyyy-ww");
     893  private static final String separator = java.io.File.separator;
     894  private static final SimpleDateFormat SUBDIR_FORMAT =
     895    new SimpleDateFormat("yyyy-ww"+separator+"F-ss");
    894896
    895897  /**
     
    935937  /**
    936938    Get the relative path of the specified file from the base upload
    937     directory.
     939    directory and convert directory separator to forward slash.
    938940    @since 2.2
     941    @see #getAbsolutePath(String)
    939942  */
    940943  private String getRelativePath(java.io.File file)
     
    943946    String rootPath = Application.getUserFilesDirectory().getAbsolutePath();
    944947    String relPath = absPath.replace(rootPath, "");
    945     if (relPath.startsWith(java.io.File.separator))
    946     {
    947       relPath = relPath.substring(java.io.File.separator.length());
    948     }
     948    if (relPath.startsWith(separator))
     949    {
     950      relPath = relPath.substring(separator.length());
     951    }
     952    relPath = relPath.replaceAll(separator, "/");
    949953    return relPath;
     954  }
     955 
     956  /**
     957    Convert a relative path back to an absolute file path.
     958    @since 2.2
     959    @see #getRelativePath(java.io.File)
     960  */
     961  private java.io.File getAbsolutePath(String relativePath)
     962  {
     963    // Convert forward slash to file system separator
     964    relativePath = relativePath.replaceAll("/", separator);
     965    return new java.io.File(Application.getUserFilesDirectory(), relativePath);
    950966  }
    951967 
Note: See TracChangeset for help on using the changeset viewer.