/* * MIME type is cached so that Locator doesn't need to talk to the server, * it can just get the type and buffer and be done */ public CacheReference registerURICache(URI sourceURI, ByteBuffer data, String mimeType) { if (Logger.canLog(Logger.DEBUG)) { Logger.logMsg( Logger.DEBUG, "New cache entry: URI " + sourceURI + ", buffer " + data + ", MIME type " + mimeType); } // ensure the given ByteBuffer is a direct buffer, required for native access if (!data.isDirect()) { data.rewind(); ByteBuffer newData = ByteBuffer.allocateDirect(data.capacity()); newData.put(data); data = newData; } CacheReference ref = new CacheReference(data, mimeType); synchronized (uriCache) { uriCache.put(sourceURI, new WeakReference(ref)); } // Now register sourceURI with the disposer so we can remove it // from uriCache when our cache entry gets collected MediaDisposer.addResourceDisposer(ref, sourceURI, cacheDisposer); return ref; }
public CacheReference fetchURICache(URI sourceURI) { synchronized (uriCache) { WeakReference<CacheReference> ref = uriCache.get(sourceURI); if (null == ref) { return null; } CacheReference cacheData = ref.get(); if (null != cacheData) { if (Logger.canLog(Logger.DEBUG)) { Logger.logMsg( Logger.DEBUG, "Fetched cache entry: URI " + sourceURI + ", buffer " + cacheData.getBuffer() + ", MIME type " + cacheData.getMIMEType()); } return cacheData; } } return null; }
/** * The SQLException instance contains the following information that can help determine the cause * of the error: * * <p>A description of the error. Retrieve the String object that contains this description by * calling the method SQLException.getMessage. * * <p>A SQLState code. These codes and their respective meanings have been standardized by * ISO/ANSI and Open Group (X/Open), although some codes have been reserved for database vendors * to define for themselves. This String object consists of five alphanumeric characters. Retrieve * this code by calling the method SQLException.getSQLState. * * <p>An error code. This is an integer value identifying the error that caused the SQLException * instance to be thrown. Its value and meaning are implementation-specific and might be the * actual error code returned by the underlying data source. Retrieve the error by calling the * method SQLException.getErrorCode. * * <p>A cause. A SQLException instance might have a causal relationship, which consists of one or * more Throwable objects that caused the SQLException instance to be thrown. To navigate this * chain of causes, recursively call the method SQLException.getCause until a null value is * returned. * * <p>A reference to any chained exceptions. If more than one error occurs, the exceptions are * referenced through this chain. Retrieve these exceptions by calling the method * SQLException.getNextException on the exception that was thrown. * * <p>Retrieving Exceptions * * <p>The following method, JDBCTutorialUtilities.printSQLException outputs the SQLState, error * code, error description, and cause (if there is one) contained in the SQLException as well as * any other exception chained to it: * * @param ex The SQLException thrown by the function in question. */ public static void printSQLException(SQLException ex) { for (Throwable e : ex) { if (e instanceof SQLException && !ignoreSQLException(((SQLException) e).getSQLState())) { e.printStackTrace(System.err); Logger.logMsg(1, "SQLState: " + ((SQLException) e).getSQLState()); Logger.logMsg(1, "Error Code: " + ((SQLException) e).getErrorCode()); Logger.logMsg(1, "Message: " + e.getMessage()); Throwable t = ex.getCause(); while (t != null) { Logger.logMsg(1, "Cause: " + t); t = t.getCause(); } } } }