NIHVIVO-160 Remove the maximum file size - no need for it at this level.
This commit is contained in:
parent
fe89b1f7e9
commit
b86ec9e7b2
5 changed files with 6 additions and 136 deletions
|
@ -18,12 +18,6 @@ public interface FileStorage {
|
|||
*/
|
||||
String PROPERTY_FILE_STORAGE_BASE_DIR = "upload.directory";
|
||||
|
||||
/**
|
||||
* The default implementation will use this key to ask
|
||||
* {@link ConfigurationProperties} for the maximum permissible file size.
|
||||
*/
|
||||
String PROPERTY_FILE_MAXIMUM_SIZE = "file.maximum.size";
|
||||
|
||||
/**
|
||||
* The default implementation will use this key to ask
|
||||
* {@link ConfigurationProperties} for the default URI namespace.
|
||||
|
|
|
@ -21,7 +21,6 @@ import org.apache.log4j.Logger;
|
|||
* <li>convert an ID (with namespaces) to an absolute path</li>
|
||||
* <li>convert an ID (with namespaces) and a filename to a full path for storing
|
||||
* the file</li>
|
||||
* <li>parse the string that specifies the maximum size of an uploaded file</li>
|
||||
* </ul>
|
||||
*/
|
||||
public class FileStorageHelper {
|
||||
|
@ -259,48 +258,4 @@ public class FileStorageHelper {
|
|||
encodeName(filename));
|
||||
}
|
||||
|
||||
/**
|
||||
* Translate the configuration property for maximum file size from a
|
||||
* <code>String</code> to a <code>long</code>.
|
||||
*
|
||||
* The string must be represent a positive integer, optionally followed by
|
||||
* "K", "M", or "G" (to indicate kilobytes, megabytes, or gigabytes).
|
||||
*/
|
||||
public static long parseMaximumFileSize(String fileSizeString) {
|
||||
long factor = 1L;
|
||||
String integerString;
|
||||
int shorter = fileSizeString.length() - 1;
|
||||
if (fileSizeString.endsWith("K")) {
|
||||
factor = 1024L;
|
||||
integerString = fileSizeString.substring(0, shorter);
|
||||
} else if (fileSizeString.endsWith("M")) {
|
||||
factor = 1024L * 1024L;
|
||||
integerString = fileSizeString.substring(0, shorter);
|
||||
} else if (fileSizeString.endsWith("G")) {
|
||||
factor = 1024L * 1024L * 1024L;
|
||||
integerString = fileSizeString.substring(0, shorter);
|
||||
} else {
|
||||
integerString = fileSizeString;
|
||||
}
|
||||
|
||||
long value = 0;
|
||||
try {
|
||||
value = Long.parseLong(integerString);
|
||||
|
||||
} catch (NumberFormatException e) {
|
||||
throw new IllegalArgumentException(
|
||||
"Maximum file size is invalid: '" + fileSizeString
|
||||
+ "'. Must be a positive integer, "
|
||||
+ "optionally followed by 'K', 'M', or 'G'");
|
||||
}
|
||||
|
||||
if (value <= 0L) {
|
||||
throw new IllegalArgumentException(
|
||||
"Maximum file size must be more than 0: '" + fileSizeString
|
||||
+ "'");
|
||||
}
|
||||
|
||||
return value * factor;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -34,7 +34,6 @@ public class FileStorageImpl implements FileStorage {
|
|||
private final File baseDir;
|
||||
private final File rootDir;
|
||||
private final File namespaceFile;
|
||||
private final long maximumFileSize;
|
||||
private final Map<Character, String> namespacesMap;
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
@ -53,7 +52,7 @@ public class FileStorageImpl implements FileStorage {
|
|||
* missing, or if it isn't in the expected form.
|
||||
*/
|
||||
FileStorageImpl() throws IOException {
|
||||
this(figureBaseDir(), figureFileNamespace(), figureMaximumFileSize());
|
||||
this(figureBaseDir(), figureFileNamespace());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -65,11 +64,9 @@ public class FileStorageImpl implements FileStorage {
|
|||
* if the configuration property doesn't point to an existing,
|
||||
* writeable directory.
|
||||
*/
|
||||
FileStorageImpl(File baseDir, Collection<String> namespaces,
|
||||
long maximumFileSize) throws IOException {
|
||||
FileStorageImpl(File baseDir, Collection<String> namespaces) throws IOException {
|
||||
checkBaseDirValid(baseDir);
|
||||
checkNamespacesValid(namespaces);
|
||||
checkMaximumFileSizeValid(maximumFileSize);
|
||||
|
||||
this.baseDir = baseDir;
|
||||
this.rootDir = new File(this.baseDir, "file_storage_root");
|
||||
|
@ -77,8 +74,6 @@ public class FileStorageImpl implements FileStorage {
|
|||
this.namespaceFile = new File(baseDir,
|
||||
"file_storage_namespaces.properties");
|
||||
|
||||
this.maximumFileSize = maximumFileSize;
|
||||
|
||||
if (rootDir.exists() && namespaceFile.exists()) {
|
||||
this.namespacesMap = confirmNamespaces(namespaces);
|
||||
} else if (!rootDir.exists() && !namespaceFile.exists()) {
|
||||
|
@ -97,13 +92,6 @@ public class FileStorageImpl implements FileStorage {
|
|||
}
|
||||
}
|
||||
|
||||
private void checkMaximumFileSizeValid(long maximumFileSize) {
|
||||
if (maximumFileSize < 0) {
|
||||
throw new IllegalArgumentException(
|
||||
"Maximum file size may not be negative.");
|
||||
}
|
||||
}
|
||||
|
||||
private void checkNamespacesValid(Collection<String> namespaces) {
|
||||
if (namespaces == null) {
|
||||
throw new NullPointerException("namespaces may not be null.");
|
||||
|
@ -185,23 +173,6 @@ public class FileStorageImpl implements FileStorage {
|
|||
return Collections.singleton(fileNamespace);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the configuration property for the maximum file size and translate it
|
||||
* into a long integer. It must be a positive integer, optionally followed
|
||||
* by "K", "M", or "G" (to indicate kilobytes, megabytes, or gigabytes).
|
||||
*/
|
||||
private static long figureMaximumFileSize() {
|
||||
String fileSizeString = ConfigurationProperties
|
||||
.getProperty(PROPERTY_FILE_MAXIMUM_SIZE);
|
||||
if (fileSizeString == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Configuration properties must contain a value for '"
|
||||
+ PROPERTY_FILE_MAXIMUM_SIZE + "'");
|
||||
}
|
||||
|
||||
return FileStorageHelper.parseMaximumFileSize(fileSizeString);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assign arbitrary prefixes to these namespaces.
|
||||
*/
|
||||
|
@ -398,10 +369,6 @@ public class FileStorageImpl implements FileStorage {
|
|||
byte[] buffer = new byte[4096];
|
||||
int howMany;
|
||||
while (-1 != (howMany = in.read(buffer))) {
|
||||
if (bytes.size() > this.maximumFileSize) {
|
||||
throw new IOException("File is too large at this ID: '"
|
||||
+ id + "', file location '" + file + "'");
|
||||
}
|
||||
bytes.write(buffer, 0, howMany);
|
||||
}
|
||||
bytes.close();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue