code
stringlengths
25
201k
docstring
stringlengths
19
96.2k
func_name
stringlengths
0
235
language
stringclasses
1 value
repo
stringlengths
8
51
path
stringlengths
11
314
url
stringlengths
62
377
license
stringclasses
7 values
private void write (File file) throws IOException { FileInputStream in = new FileInputStream (file); write (in, file.getPath()); in.close(); }
Write the contents of a <tt>File</tt> object to the underlying Jar or zip file. The <tt>File</tt> must not specify a directory. @param file The <tt>File</tt> to write @throws IOException on I/O error
write
java
kiooeht/ModTheSpire
src/main/java/org/clapper/util/io/Zipper.java
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/io/Zipper.java
MIT
private void write (InputStream istream, String name) throws IOException { open(); name = convertName (name); ZipEntry zipEntry = getZipEntry (name); zipStream.putNextEntry (zipEntry); byte buf[] = new byte[OUTPUT_BUF_SIZE]; int total; while ( (total = istream.read (buf, 0, buf.length)) > 0 ) zipStream.write (buf, 0, total); zipStream.closeEntry(); totalEntriesWritten++; tableOfContents.add (name); }
Write the contents of an <tt>InputStream</tt> object to the underlying Jar or zip file. @param istream The <tt>InputStream</tt> to write. The stream is read until end of file. @param name The name to assign to the Zip entry @throws IOException on I/O error
write
java
kiooeht/ModTheSpire
src/main/java/org/clapper/util/io/Zipper.java
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/io/Zipper.java
MIT
private void write (byte[] bytes, String name) throws IOException { open(); name = convertName (name); ZipEntry zipEntry = getZipEntry (name); zipStream.putNextEntry (zipEntry); zipStream.write (bytes, 0, bytes.length); zipStream.closeEntry(); totalEntriesWritten++; tableOfContents.add (name); }
Write an array of bytes underlying Jar or zip file. @param bytes The array of bytes @param name The name to assign to the Zip entry @throws IOException on I/O error
write
java
kiooeht/ModTheSpire
src/main/java/org/clapper/util/io/Zipper.java
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/io/Zipper.java
MIT
public void writeDirectory (File file) throws IOException { open(); String name = convertName (file.getPath()); if (! name.endsWith ("/")) name = name + "/"; ZipEntry zipEntry = getZipEntry (name); zipStream.putNextEntry (zipEntry); zipStream.closeEntry(); totalEntriesWritten++; tableOfContents.add (name); }
Write a directory to the underlying Jar or zip file. @param file The <tt>File</tt> representing the directory to write @throws IOException on I/O error
writeDirectory
java
kiooeht/ModTheSpire
src/main/java/org/clapper/util/io/Zipper.java
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/io/Zipper.java
MIT
private String convertName (String name) { if (flatten) name = (new File (name)).getName(); else { int i; File fsRoots[]; // Nuke any leading file system roots. This will nail the // leading "/" on Unix, and any drive letters on Windows. fsRoots = File.listRoots(); for (i = 0; i < fsRoots.length; i++) { String root = fsRoots[i].getPath(); if (name.toLowerCase().startsWith (root.toLowerCase())) { name = name.substring (root.length()); break; } } // If this is Windows, convert any Windows file separators // to Unix-style. The Zip protocol seems to prefer "/" // separators. if (File.separatorChar != '/') { // Replace all instances of the file separator. name = name.replace (File.separatorChar, '/'); } } return name; }
Convert a string name into an appropriate zip file entry, taking flattening into account if it's enabled. @param name the name @return the possibly-adjusted name
convertName
java
kiooeht/ModTheSpire
src/main/java/org/clapper/util/io/Zipper.java
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/io/Zipper.java
MIT
private ZipEntry getZipEntry (String name) { return (isJar ? (new ZipEntry (name)) : (new JarEntry (name))); }
Get a ZipEntry for a name. Returns a ZipEntry or a JarEntry, depending on the underlying file type. @param name The name to associate with the ZipEntry @return the ZipEntry object
getZipEntry
java
kiooeht/ModTheSpire
src/main/java/org/clapper/util/io/Zipper.java
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/io/Zipper.java
MIT
private synchronized void open() throws IOException { if (zipStream == null) { OutputStream out = new BufferedOutputStream (new FileOutputStream (zipFile)); if (isJar) { if (manifest != null) zipStream = new JarOutputStream (out, manifest); else zipStream = new JarOutputStream (out); } else { zipStream = new ZipOutputStream (out); } } }
Ensure that the underlying zip or jar file is open. @throws IOException on error
open
java
kiooeht/ModTheSpire
src/main/java/org/clapper/util/io/Zipper.java
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/io/Zipper.java
MIT
public String format (LogRecord record) { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter (sw); String loggerName = record.getLoggerName(); Throwable ex = record.getThrown(); String message = super.formatMessage (record); pw.print (DATE_FORMAT.format (new Date (record.getMillis()))); pw.print (' '); pw.print (record.getLevel().toString()); pw.print (" ("); // Logger name is a class name. Strip all but the last part of it. int i = loggerName.lastIndexOf ("."); if ((i != -1) && (i < (loggerName.length() - 1))) loggerName = loggerName.substring (i + 1); pw.print (loggerName); pw.print (") "); if ((message != null) && (message.trim().length() > 0)) pw.println (message); if (ex != null) ex.printStackTrace (pw); return sw.toString(); }
<p>Format the given log record and return the formatted string.</p> <p>The resulting formatted String will normally include a localized and formated version of the LogRecord's message field.</p> @param record the log record to be formatted @return the formatted log record
format
java
kiooeht/ModTheSpire
src/main/java/org/clapper/util/logging/JavaUtilLoggingTextFormatter.java
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/logging/JavaUtilLoggingTextFormatter.java
MIT
public static void enableLogging() throws UnsupportedOperationException { synchronized (loggers) { if (! enabled) { for (Logger logger : loggers) enableLogger (logger); enabled = true; } } }
Enable logging by instantiating the underlying <tt>Log</tt> objects. Enables logging for all instantiated <tt>Logger</tt> objects, and ensures that any subsequently instantiated <tt>Logger</tt> objects will be enabled. @throws UnsupportedOperationException could not find Commons Logging API
enableLogging
java
kiooeht/ModTheSpire
src/main/java/org/clapper/util/logging/Logger.java
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/logging/Logger.java
MIT
public void debug (Object message) { if (realLogger != null) realLogger.debug (message.toString()); }
Log a message with debug log level. @param message The message to convert to a string and log
debug
java
kiooeht/ModTheSpire
src/main/java/org/clapper/util/logging/Logger.java
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/logging/Logger.java
MIT
public void debug (Object message, Throwable ex) { if (realLogger != null) realLogger.debug (message.toString(), ex); }
Log an error with debug log level. @param message The message to convert to a string and log @param ex The exception to log with the message
debug
java
kiooeht/ModTheSpire
src/main/java/org/clapper/util/logging/Logger.java
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/logging/Logger.java
MIT
public void error (Object message) { if (realLogger != null) realLogger.error (message.toString()); }
Log a message with error log level. @param message The message to convert to a string and log
error
java
kiooeht/ModTheSpire
src/main/java/org/clapper/util/logging/Logger.java
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/logging/Logger.java
MIT
public void error (Object message, Throwable ex) { if (realLogger != null) realLogger.error (message.toString(), ex); }
Log an error with error log level. @param message The message to convert to a string and log @param ex The exception to log with the message
error
java
kiooeht/ModTheSpire
src/main/java/org/clapper/util/logging/Logger.java
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/logging/Logger.java
MIT
public void fatal (Object message) { if (realLogger != null) realLogger.fatal (message.toString()); }
Log a message with fatal log level. @param message The message to convert to a string and log
fatal
java
kiooeht/ModTheSpire
src/main/java/org/clapper/util/logging/Logger.java
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/logging/Logger.java
MIT
public void fatal (Object message, Throwable ex) { if (realLogger != null) realLogger.fatal (message.toString(), ex); }
Log an error with fatal log level. @param message The message to convert to a string and log @param ex The exception to log with the message
fatal
java
kiooeht/ModTheSpire
src/main/java/org/clapper/util/logging/Logger.java
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/logging/Logger.java
MIT
public void info (Object message) { if (realLogger != null) realLogger.info (message.toString()); }
Log a message with info log level. @param message The message to convert to a string and log
info
java
kiooeht/ModTheSpire
src/main/java/org/clapper/util/logging/Logger.java
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/logging/Logger.java
MIT
public void info (Object message, Throwable ex) { if (realLogger != null) realLogger.info (message.toString(), ex); }
Log an error with info log level. @param message The message to convert to a string and log @param ex The exception to log with the message
info
java
kiooeht/ModTheSpire
src/main/java/org/clapper/util/logging/Logger.java
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/logging/Logger.java
MIT
public void message (LogLevel level, Object message) { switch (level) { case DEBUG: debug (message); break; case ERROR: error (message); break; case FATAL: fatal (message); break; case INFO: info (message); break; case TRACE: trace (message); break; case WARNING: warn (message); break; default: assert (false); } }
Log a message at a specified log level. @param level the log level @param message the message
message
java
kiooeht/ModTheSpire
src/main/java/org/clapper/util/logging/Logger.java
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/logging/Logger.java
MIT
public void message (LogLevel level, Object message, Throwable ex) { switch (level) { case DEBUG: debug (message, ex); break; case ERROR: error (message, ex); break; case FATAL: fatal (message, ex); break; case INFO: info (message, ex); break; case TRACE: trace (message, ex); break; case WARNING: warn (message, ex); break; default: assert (false); } }
Log a message at a specified log level. @param level the log level @param message the message @param ex The exception to log with the message
message
java
kiooeht/ModTheSpire
src/main/java/org/clapper/util/logging/Logger.java
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/logging/Logger.java
MIT
public void trace (Object message) { if (realLogger != null) realLogger.trace (message.toString()); }
Log a message with trace log level. @param message The message to convert to a string and log
trace
java
kiooeht/ModTheSpire
src/main/java/org/clapper/util/logging/Logger.java
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/logging/Logger.java
MIT
public void trace (Object message, Throwable ex) { if (realLogger != null) realLogger.trace (message.toString(), ex); }
Log an error with trace log level. @param message The message to convert to a string and log @param ex The exception to log with the message
trace
java
kiooeht/ModTheSpire
src/main/java/org/clapper/util/logging/Logger.java
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/logging/Logger.java
MIT
public void warn (Object message) { if (realLogger != null) realLogger.warn (message.toString()); }
Log a message with warn log level. @param message The message to convert to a string and log
warn
java
kiooeht/ModTheSpire
src/main/java/org/clapper/util/logging/Logger.java
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/logging/Logger.java
MIT
public void warn (Object message, Throwable ex) { if (realLogger != null) realLogger.warn (message.toString(), ex); }
Log an error with warn log level. @param message The message to convert to a string and log @param ex The exception to log with the message
warn
java
kiooeht/ModTheSpire
src/main/java/org/clapper/util/logging/Logger.java
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/logging/Logger.java
MIT
public boolean isDebugEnabled() { return (realLogger == null) ? false : realLogger.isDebugEnabled(); }
Determine whether debug logging is currently enabled. @return <tt>true</tt> if debug logging is enabled, <tt>false</tt> otherwise
isDebugEnabled
java
kiooeht/ModTheSpire
src/main/java/org/clapper/util/logging/Logger.java
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/logging/Logger.java
MIT
public boolean isErrorEnabled() { return (realLogger == null) ? false : realLogger.isErrorEnabled(); }
Determine whether error logging is currently enabled. @return <tt>true</tt> if error logging is enabled, <tt>false</tt> otherwise
isErrorEnabled
java
kiooeht/ModTheSpire
src/main/java/org/clapper/util/logging/Logger.java
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/logging/Logger.java
MIT
public boolean isFatalEnabled() { return (realLogger == null) ? false : realLogger.isFatalEnabled(); }
Determine whether fatal logging is currently enabled. @return <tt>true</tt> if fatal logging is enabled, <tt>false</tt> otherwise
isFatalEnabled
java
kiooeht/ModTheSpire
src/main/java/org/clapper/util/logging/Logger.java
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/logging/Logger.java
MIT
public boolean isInfoEnabled() { return (realLogger == null) ? false : realLogger.isInfoEnabled(); }
Determine whether info logging is currently enabled. @return <tt>true</tt> if info logging is enabled, <tt>false</tt> otherwise
isInfoEnabled
java
kiooeht/ModTheSpire
src/main/java/org/clapper/util/logging/Logger.java
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/logging/Logger.java
MIT
public boolean isTraceEnabled() { return (realLogger == null) ? false : realLogger.isTraceEnabled(); }
Determine whether trace logging is currently enabled. @return <tt>true</tt> if trace logging is enabled, <tt>false</tt> otherwise
isTraceEnabled
java
kiooeht/ModTheSpire
src/main/java/org/clapper/util/logging/Logger.java
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/logging/Logger.java
MIT
public int getNextIndex() { return nextIndex; }
Get the index of the next element to be retrieved. This index value might be past the end of the array. @return the index
getNextIndex
java
kiooeht/ModTheSpire
src/main/java/org/clapper/util/misc/ArrayIterator.java
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/ArrayIterator.java
MIT
public boolean hasNext() { return (array != null) && (nextIndex < array.length); }
Determine whether the underlying <tt>Iterator</tt> has more elements. @return <tt>true</tt> if and only if a call to <tt>next()</tt> will return an element, <tt>false</tt> otherwise. @see #next
hasNext
java
kiooeht/ModTheSpire
src/main/java/org/clapper/util/misc/ArrayIterator.java
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/ArrayIterator.java
MIT
public T next() throws NoSuchElementException { T result = null; try { if (array == null) throw new NoSuchElementException(); // NOPMD result = array[nextIndex++]; } catch (ArrayIndexOutOfBoundsException ex) { throw new NoSuchElementException(); // NOPMD } return result; }
Get the next element from the underlying array. @return the next element from the underlying array @exception java.util.NoSuchElementException No more elements exist @see #previous() @see java.util.Iterator#next
next
java
kiooeht/ModTheSpire
src/main/java/org/clapper/util/misc/ArrayIterator.java
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/ArrayIterator.java
MIT
public T previous() throws NoSuchElementException { T result = null; try { result = array[--nextIndex]; } catch (ArrayIndexOutOfBoundsException ex) { throw new NoSuchElementException(); // NOPMD } return result; }
Get the previous element from the underlying array. This method decrements the iterator's internal index by one, and returns the corresponding element. @return the previous element from the underlying array @exception java.util.NoSuchElementException Attempt to move internal index before the first array element @see #next()
previous
java
kiooeht/ModTheSpire
src/main/java/org/clapper/util/misc/ArrayIterator.java
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/ArrayIterator.java
MIT
public void remove() { throw new UnsupportedOperationException(); }
Required by the <tt>Iterator</tt> interface, but not supported by this class. @throws UnsupportedOperationException unconditionally
remove
java
kiooeht/ModTheSpire
src/main/java/org/clapper/util/misc/ArrayIterator.java
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/ArrayIterator.java
MIT
public String getBuildDate() { return getBundleString (BUILD_DATE_KEY); }
Get the build date, as a string, from the resource bundle. @return the build date, as a string
getBuildDate
java
kiooeht/ModTheSpire
src/main/java/org/clapper/util/misc/BuildInfo.java
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/BuildInfo.java
MIT
public String getBuildUserID() { return getBundleString (BUILT_BY_KEY); }
Get the string that identifies the user who built the software. Typically, this string contains both the user ID and the host where the build occurred. @return the user identification string
getBuildUserID
java
kiooeht/ModTheSpire
src/main/java/org/clapper/util/misc/BuildInfo.java
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/BuildInfo.java
MIT
public String getBuildOperatingSystem() { return getBundleString (BUILD_OS_KEY); }
Get the string that identifies the operating system where the build occurred. @return the operating system string
getBuildOperatingSystem
java
kiooeht/ModTheSpire
src/main/java/org/clapper/util/misc/BuildInfo.java
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/BuildInfo.java
MIT
public String getBuildID() { return getBundleString (BUILD_ID_KEY); }
Get the build ID string. @return the build ID string
getBuildID
java
kiooeht/ModTheSpire
src/main/java/org/clapper/util/misc/BuildInfo.java
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/BuildInfo.java
MIT
public String getBuildJavaVM() { return getBundleString (BUILD_VM_KEY); }
Get the string that identifies the Java virtual machine that was used during the build. @return the Java VM string
getBuildJavaVM
java
kiooeht/ModTheSpire
src/main/java/org/clapper/util/misc/BuildInfo.java
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/BuildInfo.java
MIT
public String getBuildJavaCompiler() { return getBundleString (BUILD_COMPILER_KEY); }
Get the Java compiler used during the build. @return the Java compiler string
getBuildJavaCompiler
java
kiooeht/ModTheSpire
src/main/java/org/clapper/util/misc/BuildInfo.java
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/BuildInfo.java
MIT
public String getBuildAntVersion() { return getBundleString (BUILD_ANT_VERSION_KEY); }
Get the version of Ant used during the build process. @return the Ant version string
getBuildAntVersion
java
kiooeht/ModTheSpire
src/main/java/org/clapper/util/misc/BuildInfo.java
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/BuildInfo.java
MIT
public static void makeBuildInfoBundle (File bundleFile, String javaCompiler, String antVersion) throws IOException { // Fill an in-memory Properties object, which will be written to disk. Properties props = new Properties(); // BUILD_VM_KEY String vmInfo = System.getProperty ("java.vm.name") + " " + System.getProperty ("java.vm.version") + " (" + System.getProperty ("java.vm.vendor") + ")"; props.setProperty (BUILD_VM_KEY, vmInfo); // BUILD_OS_KEY String osInfo = System.getProperty ("os.name") + " " + System.getProperty ("os.version") + " (" + System.getProperty ("os.arch") + ")"; props.setProperty (BUILD_OS_KEY, osInfo); // BUILD_COMPILER_KEY if (javaCompiler != null) props.setProperty (BUILD_COMPILER_KEY, javaCompiler); // BUILD_ANT_VERSION_KEY if (antVersion != null) props.setProperty (BUILD_ANT_VERSION_KEY, antVersion); // BUILD_DATE_KEY XDate now = new XDate(); DateFormat dateFmt = new SimpleDateFormat (DATE_FORMAT_STRING); props.setProperty (BUILD_DATE_KEY, dateFmt.format (now)); // BUILD_ID_KEY props.setProperty (BUILD_ID_KEY, now.formatInTimeZone (BUILD_ID_DATE_FORMAT_STRING, TimeZone.getTimeZone ("UTC"))); // BUILT_BY_KEY String user = System.getProperty ("user.name"); String host = "localhost"; try { InetAddress localhost = InetAddress.getLocalHost(); host = localhost.getHostName(); } catch (Exception ex) { } props.setProperty (BUILT_BY_KEY, user + " on " + host); // Save it. String header = "Build information. " + "AUTOMATICALLY GENERATED. DO NOT EDIT!"; System.out.println ("Updating " + bundleFile); FileOutputStream out = new FileOutputStream (bundleFile); props.store (out, header); }
Update the build bundle file. @param bundleFile the path to the properties file @param javaCompiler Java compiler name, or null if not known @param antVersion Ant version, or null if not known @throws IOException Can't recreate file.
makeBuildInfoBundle
java
kiooeht/ModTheSpire
src/main/java/org/clapper/util/misc/BuildInfo.java
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/BuildInfo.java
MIT
public void showBuildInfo(PrintStream out) { showBuildInfo(new PrintWriter(out)); }
Display build information to the specified <tt>PrintStream</tt>. @param out where to write the build information @see #showBuildInfo(PrintWriter)
showBuildInfo
java
kiooeht/ModTheSpire
src/main/java/org/clapper/util/misc/BuildInfo.java
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/BuildInfo.java
MIT
public void showBuildInfo(PrintWriter out) { out.println("Build date: " + getBuildDate()); out.println("Built by: " + getBuildUserID()); out.println("Built on: " + getBuildOperatingSystem()); out.println("Build Java VM: " + getBuildJavaVM()); out.println("Build compiler: " + getBuildJavaCompiler()); out.println("Ant version: " + getBuildAntVersion()); }
Display build information to the specified <tt>PrintWriter</tt>. @param out where to write the build information @see #showBuildInfo(PrintStream)
showBuildInfo
java
kiooeht/ModTheSpire
src/main/java/org/clapper/util/misc/BuildInfo.java
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/BuildInfo.java
MIT
private synchronized ResourceBundle getBuildInfoBundle (String bundleName) { if (buildInfoBundle == null) { try { buildInfoBundle = ResourceBundle.getBundle (bundleName); } catch (MissingResourceException ex) { } } return buildInfoBundle; }
Attempts to get the resource bundle, if an attempt hasn't already been made. @param bundleName name of resource bundle @return the bundle, or null if it could not be found.
getBuildInfoBundle
java
kiooeht/ModTheSpire
src/main/java/org/clapper/util/misc/BuildInfo.java
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/BuildInfo.java
MIT
private static String getBundleString (String key) { String result = ""; try { if (buildInfoBundle != null) result = buildInfoBundle.getString (key); } catch (MissingResourceException ex) { } return result; }
Get a string from the bundle. @param key The key for the string to be retrieved. @return The string, or null if unavailable
getBundleString
java
kiooeht/ModTheSpire
src/main/java/org/clapper/util/misc/BuildInfo.java
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/BuildInfo.java
MIT
public static String getString (String bundleName, String key) { return getMessage (bundleName, null, key, (String) null); }
Get a string from a bundle, using the default locale. @param bundleName the bundle name @param key the key to look up @return the value for the key, or the default value
getString
java
kiooeht/ModTheSpire
src/main/java/org/clapper/util/misc/BundleUtil.java
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/BundleUtil.java
MIT
public static String getString (String bundleName, String key, String defaultMsg) { return getMessage (bundleName, null, key, defaultMsg); }
Get a string from a bundle, using the default locale. @param bundleName the bundle name @param key the key to look up @param defaultMsg the default value, or null @return the value for the key, or the default value
getString
java
kiooeht/ModTheSpire
src/main/java/org/clapper/util/misc/BundleUtil.java
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/BundleUtil.java
MIT
public static String getMessage (String bundleName, Locale locale, String key, String defaultMsg) { return getMessage (bundleName, locale, key, defaultMsg, null); }
Get a localized message from a bundle. @param bundleName the name of the resource bundle @param locale the locale @param key the key @param defaultMsg the default message @return the message, or the default
getMessage
java
kiooeht/ModTheSpire
src/main/java/org/clapper/util/misc/BundleUtil.java
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/BundleUtil.java
MIT
public static String getMessage (String bundleName, String key, Object[] params) { return getMessage (bundleName, Locale.getDefault(), key, params); }
Get a message from the bundle using the default locale. @param bundleName the name of the resource bundle @param key the key @param params parameters for the message @return the message, or the default
getMessage
java
kiooeht/ModTheSpire
src/main/java/org/clapper/util/misc/BundleUtil.java
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/BundleUtil.java
MIT
public static String getMessage (String bundleName, Locale locale, String key, String defaultMsg, Object[] params) { ResourceBundle bundle; String result = null; if (locale == null) locale = Locale.getDefault(); bundle = ResourceBundle.getBundle (bundleName, locale); if (bundle != null) { String fmt = null; try { fmt = bundle.getString (key); } catch (MissingResourceException ex) { } if (fmt == null) fmt = defaultMsg; if (fmt != null) result = MessageFormat.format(fmt, params); } if (result == null) result = defaultMsg; return result; }
Get a localized message from the bundle. @param bundleName the name of the resource bundle @param locale the locale @param key the key @param defaultMsg the default message @param params parameters for the message @return the message, or the default
getMessage
java
kiooeht/ModTheSpire
src/main/java/org/clapper/util/misc/BundleUtil.java
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/BundleUtil.java
MIT
public static String getMessage (String bundleName, Locale locale, String key, Object[] params) { ResourceBundle bundle; String result = null; if (locale == null) locale = Locale.getDefault(); bundle = ResourceBundle.getBundle (bundleName, locale); if (bundle != null) { try { String fmt = bundle.getString (key); if (fmt != null) result = MessageFormat.format (fmt, params); } catch (MissingResourceException ex) { } } return result; }
Get a localized message from the bundle. @param bundleName the name of the resource bundle @param locale the locale @param key the key @param params parameters for the message @return the message, or the default
getMessage
java
kiooeht/ModTheSpire
src/main/java/org/clapper/util/misc/BundleUtil.java
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/BundleUtil.java
MIT
public boolean hasNext() { return enumeration.hasMoreElements(); }
Determine whether the underlying <tt>Enumeration</tt> has more elements. @return <tt>true</tt> if and only if a call to <tt>next()</tt> will return an element, <tt>false</tt> otherwise. @see #next() @see Enumeration#hasMoreElements
hasNext
java
kiooeht/ModTheSpire
src/main/java/org/clapper/util/misc/EnumerationIterator.java
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/EnumerationIterator.java
MIT
public T next() throws NoSuchElementException { return enumeration.nextElement(); }
Get the next element from the underlying <tt>Enumeration</tt>. @return the next element from the underlying <tt>Enumeration</tt> @exception NoSuchElementException No more elements exist @see Iterator#next
next
java
kiooeht/ModTheSpire
src/main/java/org/clapper/util/misc/EnumerationIterator.java
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/EnumerationIterator.java
MIT
public void remove() throws IllegalStateException, UnsupportedOperationException { throw new UnsupportedOperationException(); }
Removes from the underlying collection the last element returned by the iterator. Not supported by this class. @throws IllegalStateException doesn't @throws UnsupportedOperationException unconditionally
remove
java
kiooeht/ModTheSpire
src/main/java/org/clapper/util/misc/EnumerationIterator.java
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/EnumerationIterator.java
MIT
public synchronized void clear() { checkValidity(); indexMap.clear(); try { // Implement the clear operation by truncating the data file. valuesDB.getFile().getChannel().truncate (0); modified = true; } catch (IOException ex) { log.error ("Failed to truncate FileHashMap file \"" + valuesDBPath.getPath() + "\"", ex); valid = false; } }
<p>Removes all mappings from this map. The data file is cleared by closing it, deleting it, and reopening it. If an I/O error occurs at any point, this object will be closed and marked invalid.</p>
clear
java
kiooeht/ModTheSpire
src/main/java/org/clapper/util/misc/FileHashMap.java
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/FileHashMap.java
MIT
public synchronized void close() throws NotSerializableException, IOException { if (valid) { if ((flags & TRANSIENT) != 0) { // Be sure to remove the data files. if (valuesDB != null) { valuesDB.close(); valuesDB = null; } deleteMapFiles(); } else { save(); } valid = false; } }
<p>Close this map. If the map is not marked as transient, this method saves the index to disk. Otherwise, it removes both the index file and data file.</p> @throws NotSerializableException Can't save index (bug) @throws IOException Error writing index @see #save
close
java
kiooeht/ModTheSpire
src/main/java/org/clapper/util/misc/FileHashMap.java
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/FileHashMap.java
MIT
public boolean containsKey (Object key) { checkValidity(); return indexMap.containsKey (key); }
<p>Returns <tt>true</tt> if this map contains a mapping for the specified key. Since the keys are cached in an in-memory index, this method does not have to access the data file, and is fairly cheap.</p> @param key key whose presence in this map is to be tested @return <tt>true</tt> if this map contains a mapping for the specified key, <tt>false</tt> otherwise.
containsKey
java
kiooeht/ModTheSpire
src/main/java/org/clapper/util/misc/FileHashMap.java
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/FileHashMap.java
MIT
public boolean containsValue (Object value) { checkValidity(); return new ValueSet().contains (value); }
<p>Returns <tt>true</tt> if this map maps one or more keys that are mapped to the specified value. Because it must iterate through some portion of the on-disk value set, this method can be slow.</p> @param value value whose presence in this map is to be tested. @return <tt>true</tt> if this map maps one or more keys to the specified value, <tt>false</tt> otherwise.
containsValue
java
kiooeht/ModTheSpire
src/main/java/org/clapper/util/misc/FileHashMap.java
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/FileHashMap.java
MIT
public void delete() { try { close(); } catch (NotSerializableException ex) { } catch (IOException ex) { } deleteMapFiles(); }
Deletes the files backing this <tt>FileHashMap</tt>. This method implicitly calls {@link #close}.
delete
java
kiooeht/ModTheSpire
src/main/java/org/clapper/util/misc/FileHashMap.java
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/FileHashMap.java
MIT
public Set<Map.Entry<K,V>> entrySet() { checkValidity(); if (entrySetResult == null) entrySetResult = new EntrySet(); return (Set<Map.Entry<K,V>>) entrySetResult; }
<p>Returns a "thin" set view of the mappings contained in this map. Each element in the returned set is a <tt>Map.Entry</tt>; each <tt>Map.Entry</tt> contains a key and a proxy for the associated value. The map's values themselves are not loaded into memory until requested via a call to <tt>Map.Entry.getValue()</tt>.</p> <p>The set is backed by the map, so changes to the map are reflected in the set. If the map is modified while an iteration over the set is in progress, the results of the iteration are undefined. Neither the set nor its associated iterator supports any of the set-modification methods (e.g., <tt>add()</tt>, <tt>remove()</tt>, etc). If you attempt to call any of those methods, the called method will throw an <tt>UnsupportedOperationException</tt>.</p> <p>NOTE: Calling this method on an invalid or closed <tt>FileHashMap</tt> will result in an exception.</p> @return a set view of the mappings contained in this map. @see #keySet @see #values @see UnsupportedOperationException
entrySet
java
kiooeht/ModTheSpire
src/main/java/org/clapper/util/misc/FileHashMap.java
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/FileHashMap.java
MIT
public boolean equals (Object o) { checkValidity(); return super.equals (o); }
<p>Compares the specified object with this map for equality. Returns <tt>true</tt> if the given object is also a map and the two Maps represent the same mappings. More formally, two maps <tt>t1</tt> and <tt>t2</tt> represent the same mappings if <tt>t1.entrySet().equals(t2.entrySet())</tt>. This ensures that the <tt>equals</tt> method works properly across different implementations of the <tt>Map</tt> interface.</p> <p><b>Warning:</b>: Because this method must compare the actual values stored in the map, and the values in a file, this method can be quite slow.</p> @param o object to be compared for equality with this map. @return <tt>true</tt> if the specified object is equal to this map.
equals
java
kiooeht/ModTheSpire
src/main/java/org/clapper/util/misc/FileHashMap.java
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/FileHashMap.java
MIT
public V get (Object key) { checkValidity(); V result = null; FileHashMapEntry<K> entry = indexMap.get (key); if (entry != null) result = readValueNoError (entry); return result; }
<p>Returns the value associated with the the specified key. Returns <tt>null</tt> if the map contains no mapping for this key.</p> @param key key whose associated value is to be returned. @return the value to which this map maps the specified key, or <tt>null</tt> if the map contains no mapping for this key. @throws ClassCastException if the key is of an inappropriate type for this map. @throws NullPointerException key is <tt>null</tt> @see #containsKey(Object)
get
java
kiooeht/ModTheSpire
src/main/java/org/clapper/util/misc/FileHashMap.java
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/FileHashMap.java
MIT
public int hashCode() { checkValidity(); return super.hashCode(); }
<p>Returns the hash code value for this map. The hash code of a map is defined to be the sum of the hash codes of each entry in the map's <tt>entrySet()</tt> view. This ensures that <tt>t1.equals(t2)</tt> implies that <tt>t1.hashCode()==t2.hashCode()</tt> for any two maps <tt>t1</tt> and <tt>t2</tt>, as required by the general contract of Object.hashCode.</p> <p><b>Warning:</b>: The recommended hash code for each entry in the <tt>entrySet()</tt> view is a combination of hash codes for the entry's key and the entry's value. (See <tt>java.util.Map.Entry</tt> for details.) Because the values in a <tt>FileHashMap</tt> object are stored in a file, this method can be quite slow.</p> @return the hash code value for this map. @see Object#hashCode() @see Object#equals(Object) @see #equals(Object)
hashCode
java
kiooeht/ModTheSpire
src/main/java/org/clapper/util/misc/FileHashMap.java
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/FileHashMap.java
MIT
public boolean isValid() { return valid; }
Determine whether the <tt>FileHashMap</tt> is valid or not. Once a <tt>FileHashMap</tt> has been closed, it is invalid and can no longer be used. @return <tt>true</tt> if this object is valid, <tt>false</tt> if not
isValid
java
kiooeht/ModTheSpire
src/main/java/org/clapper/util/misc/FileHashMap.java
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/FileHashMap.java
MIT
public Set<K> keySet() { checkValidity(); return new KeySet(); }
<p>Returns a <tt>Set</tt> containing all the keys in this map. Since the keys are cached in memory, this method is relatively efficient. The keys are returned in an order that optimizes sequential access to the data file; see the <b>Optimizations</b> section in the main class documentation for details.</p> <p>The set is backed by the map, so changes to the map are reflected in the set. If the map is modified while an iteration over the set is in progress, the results of the iteration are undefined. Neither the set nor its associated iterator supports any of the set-modification methods (e.g., <tt>add()</tt>, <tt>remove()</tt>, etc). If you attempt to call any of those methods, the called method will throw an <tt>UnsupportedOperationException</tt>.</p> @return a set view of the keys contained in this map.
keySet
java
kiooeht/ModTheSpire
src/main/java/org/clapper/util/misc/FileHashMap.java
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/FileHashMap.java
MIT
public V remove (Object key) { checkValidity(); V result = null; // We do nothing with the space in the data file for any existing // item. It remains in the data file, but is unreferenced. if (indexMap.containsKey (key)) { FileHashMapEntry<K> entry = indexMap.get (key); result = readValueNoError (entry); indexMap.remove (key); modified = true; if ((flags & RECLAIM_FILE_GAPS) != 0) { // Have to recalculate gaps, since we may be able to coalesce // this returned space with ones to either side of it. log.debug ("Removed value for key \"" + key + "\" at pos=" + entry.getFilePosition() + ", size=" + entry.getObjectSize() + ". Re-figuring gaps."); findFileGaps(); } } return result; }
<p>Removes the mapping for this key from this map, if present. <b>Note:</b> The space occupied by the serialized value in the data file is <i>not</i> coalesced at this point.</p> @param key key whose mapping is to be removed from the map. @return previous value associated with specified key, or <tt>null</tt> if there was no mapping for key.
remove
java
kiooeht/ModTheSpire
src/main/java/org/clapper/util/misc/FileHashMap.java
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/FileHashMap.java
MIT
public void save() throws IOException, NotSerializableException { checkValidity(); if ( ((flags & TRANSIENT) == 0) && modified ) saveIndex(); }
<p>Save any in-memory index changes to disk without closing the map. You can call this method even if the map is marked as temporary; on a temporary map, <tt>save()</tt> simply returns without doing anything.</p> @throws IOException Error saving changes to disk. @throws NotSerializableException Can't save index because it contains one or more objects that cannot be serialized. @see #close
save
java
kiooeht/ModTheSpire
src/main/java/org/clapper/util/misc/FileHashMap.java
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/FileHashMap.java
MIT
public int size() { checkValidity(); return currentSize(); }
<p>Returns the number of key-value mappings in this map. If the map contains more than <tt>Integer.MAX_VALUE</tt> elements, returns <tt>Integer.MAX_VALUE</tt>. This method queries the in-memory key index, so it is relatively efficient.</p> @return the number of key-value mappings in this map.
size
java
kiooeht/ModTheSpire
src/main/java/org/clapper/util/misc/FileHashMap.java
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/FileHashMap.java
MIT
private void checkValidity() { if (! valid) throw new IllegalStateException ("Invalid FileHashMap object"); }
Throw an exception if the object isn't valid.
checkValidity
java
kiooeht/ModTheSpire
src/main/java/org/clapper/util/misc/FileHashMap.java
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/FileHashMap.java
MIT
private void createNewMap (File valuesDBPath) throws IOException { this.valuesDB = new ValuesFile (valuesDBPath); this.indexMap = new HashMap<K, FileHashMapEntry<K>>(); }
Initialize a new index and data file for a hash map being created. Used only by the constructors. @param valuesDBPath path to the data file @throws IOException I/O error
createNewMap
java
kiooeht/ModTheSpire
src/main/java/org/clapper/util/misc/FileHashMap.java
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/FileHashMap.java
MIT
private int currentSize() { return indexMap.size(); }
Determine the size of this map. Basically, this method just consolidates the size-determination logic in one place. @return the size
currentSize
java
kiooeht/ModTheSpire
src/main/java/org/clapper/util/misc/FileHashMap.java
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/FileHashMap.java
MIT
private void findFileGaps() { log.debug ("Looking for file gaps."); if (fileGaps == null) fileGaps = new TreeSet<FileHashMapEntry<K>> (new FileHashMapEntryGapComparator()); else fileGaps.clear(); if (currentSize() > 0) { List<FileHashMapEntry<K>> entries = getSortedEntries(); FileHashMapEntry<K> previous = null; Iterator<FileHashMapEntry<K>> it = entries.iterator(); // Handle the first one specially. FileHashMapEntry<K> entry = it.next(); long pos = entry.getFilePosition(); int size = entry.getObjectSize(); if (pos > 0) { // There's a gap at the beginning. log.debug ("First entry is at pos " + pos + ", size=" + size); size = (int) pos; log.debug ("Gap at position 0 of size " + size); fileGaps.add (new FileHashMapEntry<K> ((long) 0, size)); } previous = entry; while (it.hasNext()) { entry = it.next(); long previousPos = previous.getFilePosition(); long possibleGapPos = previousPos + previous.getObjectSize(); pos = entry.getFilePosition(); assert (pos > previousPos); if (possibleGapPos != pos) { int gapSize = (int) (pos - possibleGapPos); log.debug ("Gap at position " + possibleGapPos + " of size " + gapSize); fileGaps.add (new FileHashMapEntry<K> (possibleGapPos, gapSize)); } previous = entry; } } }
Locate gaps in the file by traversing the index. Initializes or reinitializes the fileGaps instance variable.
findFileGaps
java
kiooeht/ModTheSpire
src/main/java/org/clapper/util/misc/FileHashMap.java
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/FileHashMap.java
MIT
private List<FileHashMapEntry<K>> getSortedEntries() { // Get the set of values in the hash index. Each value is a // FileHashMapEntry object. List<FileHashMapEntry<K>> vals = new ArrayList<FileHashMapEntry<K>>(); vals.addAll (indexMap.values()); // Sort the list. Collections.sort (vals, new FileHashMapEntryComparator()); return vals; }
Get the list of FileHashMapEntry pointers for the values, sorted in ascending file position order. @return A sorted list of FileHashMapEntry objects.
getSortedEntries
java
kiooeht/ModTheSpire
src/main/java/org/clapper/util/misc/FileHashMap.java
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/FileHashMap.java
MIT
private void loadIndex() throws IOException, ClassNotFoundException, VersionMismatchException { ObjectInputStream objStream; String version; objStream = new ObjectInputStream (new FileInputStream (this.indexFilePath)); version = (String) objStream.readObject(); if (! version.equals (VERSION_STAMP)) { throw new VersionMismatchException (Package.BUNDLE_NAME, "FileHashMap.versionMismatch", "FileHashMap version mismatch in index file " + "\"{0}\". Expected version \"{1}\", found " + "version \"{2}\"", new Object[] { indexFilePath.getName(), VERSION_STAMP, version }, VERSION_STAMP, version); } // This typecast will generate an "unchecked cast" exception. // Unfortunately, there's no way around it (other than to avoid // making calls like this). See // http://www.langer.camelot.de/GenericsFAQ/JavaGenericsFAQ.html#Technicalities indexMap = (HashMap<K, FileHashMapEntry<K>>) objStream.readObject(); }
Load the index from its disk file. @throws IOException on error @throws ClassNotFoundException error deserializing one of the objects @throws VersionMismatchException bad version in index file
loadIndex
java
kiooeht/ModTheSpire
src/main/java/org/clapper/util/misc/FileHashMap.java
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/FileHashMap.java
MIT
private V readValue (FileHashMapEntry<K> entry) throws IOException, ClassNotFoundException, IllegalStateException { int size = entry.getObjectSize(); byte byteBuf[] = new byte[size]; int sizeRead; ObjectInputStream objStream; // Load the serialized object into memory. synchronized (this) { RandomAccessFile valuesFile = valuesDB.getFile(); valuesFile.seek (entry.getFilePosition()); if ( (sizeRead = valuesFile.read (byteBuf)) != size ) { throw new IOException ("Expected to read " + size + "-byte serialized object from " + " on-disk data file. Got only " + sizeRead + " bytes."); } } // Use a ByteArrayInputStream and an ObjectInputStream to read // the actual object itself. objStream = new ObjectInputStream (new ByteArrayInputStream (byteBuf)); // This typecast will generate an "unchecked cast" exception. // Unfortunately, there's no way around it (other than to avoid // making calls like this). See // http://www.langer.camelot.de/GenericsFAQ/JavaGenericsFAQ.html#Technicalities return (V) objStream.readObject(); }
Read an object from a specific location in the random access file data file. @param entry The FileHashMapEntry specifying the object's location @return the object @throws IOException Read error @throws ClassNotFoundException The serialized class read from the file cannot be loaded @throws IllegalStateException No object stored at location (i.e., no size value has been set) @see #getFilePosition @see #writeObject
readValue
java
kiooeht/ModTheSpire
src/main/java/org/clapper/util/misc/FileHashMap.java
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/FileHashMap.java
MIT
private V readValueNoError (FileHashMapEntry<K> entry) { V obj = null; try { obj = readValue (entry); } catch (IOException ex) { } catch (ClassNotFoundException ex) { } return obj; }
Read an object without throwing a checked exception on error. @param entry The FileHashMapEntry specifying the object's location @return the object, or null if not found
readValueNoError
java
kiooeht/ModTheSpire
src/main/java/org/clapper/util/misc/FileHashMap.java
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/FileHashMap.java
MIT
private synchronized void saveIndex() throws IOException { ObjectOutputStream objStream; objStream = new ObjectOutputStream (new FileOutputStream (this.indexFilePath)); objStream.writeObject (VERSION_STAMP); objStream.writeObject (indexMap); if (log.isDebugEnabled()) { List<FileHashMapEntry<K>> entries = getSortedEntries(); log.debug ("Just saved index. Total entries=" + currentSize()); log.debug ("Index values follow."); for (FileHashMapEntry<K> entry : entries) { long pos = entry.getFilePosition(); int size = entry.getObjectSize(); log.debug (" pos=" + pos + ", size=" + size); } } }
Save the index to its disk file. @throws IOException on error
saveIndex
java
kiooeht/ModTheSpire
src/main/java/org/clapper/util/misc/FileHashMap.java
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/FileHashMap.java
MIT
private synchronized FileHashMapEntry<K> writeValue (K key, V obj) throws IOException, NotSerializableException { ObjectOutputStream objStream; ByteArrayOutputStream byteStream; int size; long filePos = -1; // Serialize the object to a byte buffer. byteStream = new ByteArrayOutputStream(); objStream = new ObjectOutputStream (byteStream); objStream.writeObject (obj); size = byteStream.size(); // Find a location for the object. if ((flags & RECLAIM_FILE_GAPS) != 0) filePos = findBestFitGap (size); RandomAccessFile valuesFile = this.valuesDB.getFile(); if (filePos == -1) filePos = valuesFile.length(); valuesFile.seek (filePos); // Write the bytes of the serialized object. valuesFile.write (byteStream.toByteArray()); // Return the entry. return new FileHashMapEntry<K> (filePos, size, key); }
Write an object to the end of the data file, recording its position and length in a FileHashMapEntry object. Note: The object to be stored must implement the <tt>Serializable</tt> interface. @param key The object's key (specified by the caller of FileHashMap.put()) @param obj The object to serialize and store @return the FileHashMapEntry object that records the location of the stored object @throws IOException Write error @throws NotSerializableException Object isn't serializable @see #getFilePosition @see #readValue
writeValue
java
kiooeht/ModTheSpire
src/main/java/org/clapper/util/misc/FileHashMap.java
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/FileHashMap.java
MIT
public int compareTo (FileHashMapEntry o) { FileHashMapEntry other = (FileHashMapEntry) o; Long thisPos = new Long (this.filePosition); Long otherPos = new Long (other.filePosition); return thisPos.compareTo (otherPos); }
Compares this object with the specified object for order. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object. The comparison key for a <tt>FileHashMapEntry</tt> is the file position value. @param o The other object
compareTo
java
kiooeht/ModTheSpire
src/main/java/org/clapper/util/misc/FileHashMapEntry.java
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/FileHashMapEntry.java
MIT
public String toString() { return ("FileHashMapEntry[filePosition=" + filePosition + ", objectSize=" + objectSize + ", key=" + ((key == null) ? "<null>" : key) + "]"); }
Display a string version of the contents of this object. Mostly useful for debugging. @return a string representation of the contents of this object
toString
java
kiooeht/ModTheSpire
src/main/java/org/clapper/util/misc/FileHashMapEntry.java
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/FileHashMapEntry.java
MIT
K getKey() { return key; }
Get the caller's key (i.e., the key the caller passed to <tt>FileHashMap.put()</tt>). @return the key @see #setKey @see FileHashMap#put
getKey
java
kiooeht/ModTheSpire
src/main/java/org/clapper/util/misc/FileHashMapEntry.java
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/FileHashMapEntry.java
MIT
void setKey (K newKey) { this.key = newKey; }
Change the key for this entry @param newKey the new key to use @see #getKey
setKey
java
kiooeht/ModTheSpire
src/main/java/org/clapper/util/misc/FileHashMapEntry.java
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/FileHashMapEntry.java
MIT
long getFilePosition() { return this.filePosition; }
Get the file position for this entry. @return the file position @see #setFilePosition
getFilePosition
java
kiooeht/ModTheSpire
src/main/java/org/clapper/util/misc/FileHashMapEntry.java
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/FileHashMapEntry.java
MIT
void setFilePosition (long pos) { this.filePosition = pos; }
Set the file position for this entry. @param pos the new file position @see #getFilePosition
setFilePosition
java
kiooeht/ModTheSpire
src/main/java/org/clapper/util/misc/FileHashMapEntry.java
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/FileHashMapEntry.java
MIT
int getObjectSize() throws IllegalStateException { assert (this.objectSize > 0) : "No object stored yet"; return this.objectSize; }
Get the number of bytes the serialized object occupies in the random access file. @return the number of bytes occupied by the object @see #setObjectSize
getObjectSize
java
kiooeht/ModTheSpire
src/main/java/org/clapper/util/misc/FileHashMapEntry.java
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/FileHashMapEntry.java
MIT
void setObjectSize (int size) { this.objectSize = size; }
Get the number of bytes the serialized object occupies in the random access file. @param size the number of bytes occupied by the object @see #getObjectSize
setObjectSize
java
kiooeht/ModTheSpire
src/main/java/org/clapper/util/misc/FileHashMapEntry.java
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/FileHashMapEntry.java
MIT
public void objectRemoved (ObjectRemovalEvent event) { realListener.objectRemoved (event); }
Wraps any ObjectRemovalListener passed into addRemovalListener(). Keeps track of both the listener and its "automaticOnly" status
objectRemoved
java
kiooeht/ModTheSpire
src/main/java/org/clapper/util/misc/LRUMap.java
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/LRUMap.java
MIT
public synchronized void addRemovalListener (ObjectRemovalListener listener, boolean automaticOnly) { if (removalListeners == null) removalListeners = new ListenerMap(); removalListeners.put (listener, new RemovalListenerWrapper (listener, automaticOnly)); }
<p>Add an <tt>EventListener</tt> that will be called whenever an object is removed from the cache. If <tt>automaticOnly</tt> is <tt>true</tt>, then the listener is only notified for objects that are removed automatically when the cache needs to be cleared to make room for new objects. If <tt>automaticOnly</tt> is <tt>false</tt>, then the listener is notified whenever an object is removed for any reason, include a call to the {@link #remove remove()} method.</p> <p>Note that when this map announces the removal of an object, it passes an {@link ObjectRemovalEvent} that contains a <tt>java.util.Map.Entry</tt> object that wraps the actual object that was removed. That way, both the key and the value are available for the removed object.</p> @param listener the listener to add @param automaticOnly see above @see #removeRemovalListener
addRemovalListener
java
kiooeht/ModTheSpire
src/main/java/org/clapper/util/misc/LRUMap.java
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/LRUMap.java
MIT
public synchronized boolean removeRemovalListener (ObjectRemovalListener listener) { boolean removed = false; if ((removalListeners != null) && (removalListeners.remove(listener) != null)) { removed = true; } return removed; }
Remove an <tt>EventListener</tt> from the set of listeners to be invoked when an object is removed from the cache. @param listener the listener to add @return <tt>true</tt> if the listener was in the list and was removed, <tt>false</tt> otherwise @see #addRemovalListener
removeRemovalListener
java
kiooeht/ModTheSpire
src/main/java/org/clapper/util/misc/LRUMap.java
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/LRUMap.java
MIT
public Set<Map.Entry<K,V>> entrySet() { return new EntrySet(); }
Get a set view of the mappings in this map. Each element in this set is a <tt>Map.Entry</tt>. The collection is backed by the map, so changes to the map are reflected in the collection, and vice-versa. The collection supports element removal, which removes the corresponding mapping from the map, via the <tt>Iterator.remove</tt>, <tt>Collection.remove</tt>, <tt>removeAll</tt>, <tt>retainAll</tt>, and <tt>clear</tt> operations. It does not support the <tt>add</tt> or <tt>addAll</tt> operations. @return the entry set
entrySet
java
kiooeht/ModTheSpire
src/main/java/org/clapper/util/misc/LRUMap.java
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/LRUMap.java
MIT
public V get (Object key) { V value = null; LRULinkedListEntry entry = (LRULinkedListEntry) hash.get (key); if (entry != null) { // It's there. It's just been accessed, so move it to the // top of the linked list. assert (entry.key.equals (key)) : "entry.key=" + entry.key + ", key=" + key; lruQueue.moveToHead (entry); value = entry.value; } return value; }
Retrieve an object from the map. Retrieving an object from an LRU map "refreshes" the object so that it is among the most recently used objects. @param key the object's key in the map. @return the associated object, or null if not found
get
java
kiooeht/ModTheSpire
src/main/java/org/clapper/util/misc/LRUMap.java
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/LRUMap.java
MIT
public int getInitialCapacity() { return initialCapacity; }
Get the initial capacity of this <tt>LRUMap</tt>. @return the initial capacity, as passed to the constructor @see #getLoadFactor @see #getMaximumCapacity
getInitialCapacity
java
kiooeht/ModTheSpire
src/main/java/org/clapper/util/misc/LRUMap.java
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/LRUMap.java
MIT
public float getLoadFactor() { return loadFactor; }
Get the load factor for this <tt>LRUMap</tt>. @return the load factor, as passed to the constructor @see #getInitialCapacity @see #getMaximumCapacity
getLoadFactor
java
kiooeht/ModTheSpire
src/main/java/org/clapper/util/misc/LRUMap.java
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/LRUMap.java
MIT
public int getMaximumCapacity() { return maxCapacity; }
Get the maximum capacity of this <tt>LRUMap</tt>. @return the maximum capacity, as passed to the constructor @see #setMaximumCapacity @see #getLoadFactor @see #getInitialCapacity
getMaximumCapacity
java
kiooeht/ModTheSpire
src/main/java/org/clapper/util/misc/LRUMap.java
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/LRUMap.java
MIT
public Set<K> keySet() { return new KeySet(); }
<p>Return a <tt>Set</tt> view of the keys in the map. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. The set does supports element removal, which removes the corresponding mapping from this map; however, the <tt>Iterator</tt> returned by the set currently does <b>not</b> support element removal. The set does not support the <tt>add</tt> or <tt>addAll</tt> operations. @return the set of keys in this map
keySet
java
kiooeht/ModTheSpire
src/main/java/org/clapper/util/misc/LRUMap.java
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/LRUMap.java
MIT
public void putAll (Map<? extends K, ? extends V> map) { doPutAll(map); }
Copies all of the mappings from a specified map to this one. These mappings replace any mappings that this map had for any of the keys. @param map the map whose mappings are to be copied
putAll
java
kiooeht/ModTheSpire
src/main/java/org/clapper/util/misc/LRUMap.java
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/LRUMap.java
MIT
public V remove (Object key) { V value = null; LRULinkedListEntry entry = (LRULinkedListEntry) hash.remove (key); if (entry != null) { value = entry.value; lruQueue.remove (entry); callRemovalListeners (key, value, false); } assert (hash.size() == lruQueue.size); return value; }
Removes the mapping for a key, if there is one. @param key the key to remove @return the previous value associated with the key, or null if (a) there was no previous value, or (b) the previous value was a null
remove
java
kiooeht/ModTheSpire
src/main/java/org/clapper/util/misc/LRUMap.java
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/LRUMap.java
MIT
public int setMaximumCapacity (int newCapacity) { assert (newCapacity > 0); int oldCapacity = this.maxCapacity; clearTo (newCapacity); this.maxCapacity = newCapacity; return oldCapacity; }
Set or change the maximum capacity of this <tt>LRUMap</tt>. If the maximum capacity is reduced to less than the map's current size, then the map is reduced in size by discarding the oldest entries. @param newCapacity the new maximum capacity @return the old maximum capacity @see #getMaximumCapacity
setMaximumCapacity
java
kiooeht/ModTheSpire
src/main/java/org/clapper/util/misc/LRUMap.java
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/LRUMap.java
MIT
public static String fileExtensionForMIMEType (String mimeType) { loadMappings(); String ext = (String) mimeTypeToExtensionMap.get (mimeType); if (ext == null) ext = "dat"; return ext; }
Get an appropriate extension for a MIME type. @param mimeType the String MIME type @return the appropriate file name extension, or a default extension if not found. The extension will not have the leading "." character.
fileExtensionForMIMEType
java
kiooeht/ModTheSpire
src/main/java/org/clapper/util/misc/MIMETypeUtil.java
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/MIMETypeUtil.java
MIT
public static String MIMETypeForFileExtension (String extension) // NOPMD { return MIMETypeForFileExtension (extension, DEFAULT_MIME_TYPE); }
Get the MIME type for a filename extension. @param extension the extension, without the "." @return the MIME type, or a default MIME type if there's no mapping for the extension @see #MIMETypeForFileExtension(String,String) @see #MIMETypeForFile(File) @see #MIMETypeForFile(File,String) @see #MIMETypeForFileName(String) @see #MIMETypeForFileName(String,String)
MIMETypeForFileExtension
java
kiooeht/ModTheSpire
src/main/java/org/clapper/util/misc/MIMETypeUtil.java
https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/misc/MIMETypeUtil.java
MIT