List of usage examples for java.lang.ref SoftReference SoftReference
public SoftReference(T referent)
From source file:org.jboss.windup.metadata.type.XmlMetadata.java
protected Document hydrateDocument() { if (parsedDocumentRef == null) { FileInputStream fis = null; try {//from www. ja v a 2s. c om fis = FileUtils.openInputStream(filePointer); Document parsedDocument = LocationAwareXmlReader.readXML(fis); LOG.debug("Hydrating XML Document: " + filePointer.getAbsolutePath()); parsedDocumentRef = new SoftReference<Document>(parsedDocument); } catch (Exception e) { LOG.error("Bad XML? " + filePointer.getAbsolutePath()); LOG.info("Skipping file. Continuing Windup Processing..."); Summary sr = new Summary(); sr.setDescription("Bad XML? Unable to parse."); sr.setLevel(NotificationLevel.CRITICAL); sr.setEffort(new UnknownEffort()); this.getDecorations().add(sr); this.parsedDocumentRef = null; return null; } finally { IOUtils.closeQuietly(fis); } } return parsedDocumentRef.get(); }
From source file:de.handtwerk.android.IoHelper.java
public static JSONObject readAssetAsJsonObject(String pPath, Context pContext) throws IOException, JSONException { synchronized (JSON_OBJECT_CACHE) { SoftReference<JSONObject> ref = JSON_OBJECT_CACHE.get(pPath); if (ref != null && ref.get() != null) { return ref.get(); }/*from w ww . java 2 s .c o m*/ String jsonStr = readAssetAsString(pPath, pContext); JSONObject json = new JSONObject(jsonStr); JSON_OBJECT_CACHE.put(pPath, new SoftReference<JSONObject>(json)); return json; } }
From source file:com.eviware.soapui.security.log.FunctionalTestLogModel.java
public synchronized void addSecurityTestFunctionalStepResult(TestStepResult result) { stepCount++;/*from www . j a v a2 s .c om*/ int size = items.size(); SoftReference<TestStepResult> stepResultRef = new SoftReference<TestStepResult>(result); items.add("Step " + stepCount + " [" + result.getTestStep().getName() + "] " + result.getStatus() + ": took " + result.getTimeTaken() + " ms"); results.add(stepResultRef); for (String msg : result.getMessages()) { items.add(" -> " + msg); results.add(stepResultRef); } fireIntervalAdded(this, size, items.size() - 1); enforceMaxSize(); }
From source file:jef.tools.chinese.CFJUtil.java
private void checkAndInit() { if (jan2fanMapping == null || jan2fanMapping.get() == null) { jan2fanMapping = new SoftReference<Mapping[]>(loadMapping("jf_map_utf8.properties", 2700)); }// w ww. j a v a 2 s . c o m if (fan2janMapping == null || fan2janMapping.get() == null) { fan2janMapping = new SoftReference<Mapping[]>(loadMapping("fj_map_utf8.properties", 3180)); } }
From source file:com.skynetcomputing.database.Database.java
/** * Creates a new database connection pool so that statements and queries can be executed. */// w ww .j a va 2 s .co m @SuppressWarnings("unchecked") private Database() { GenericObjectPoolConfig config = new GenericObjectPoolConfig(); config.setMaxIdle(5); config.setMaxTotal(10); // Configurable connectionstring. String connString = MiscUtils.getPropertyOrDefault("dbConnection", URL); String connUser = MiscUtils.getPropertyOrDefault("dbUser", USERNAME); String connPassword = MiscUtils.getPropertyOrDefault("dbPassword", PASSWORD); pool = new GenericObjectPool<>(new BasePooledObjectFactory() { @Override public Object create() throws Exception { return DriverManager.getConnection(connString, connUser, connPassword); } @Override public PooledObject wrap(Object o) { return new PooledSoftReference<>(new SoftReference<>(o)); } }, config); }
From source file:org.lenskit.LenskitInfo.java
/** * Get the set of revisions LensKit is built from. This is in the order returned by {@code git log}, * so the head revision is first./*from w ww . j av a2 s.c om*/ * @return The set of revisions included in this build of LensKit. */ @Nonnull public static synchronized Set<String> getRevisions() { Set<String> revisions = revisionSet == null ? null : revisionSet.get(); if (revisions == null) { revisions = loadRevisionSet(); revisionSet = new SoftReference<>(revisions); } return revisions; }
From source file:com.binroot.fatpita.BitmapManager2.java
public Bitmap fetchBitmap(String urlString, int sample) { SoftReference<Bitmap> ref = mCache.get(urlString); if (ref != null && ref.get() != null) { return ref.get(); }//from w w w. j a v a 2 s.c o m Log.d(TAG, "image url:" + urlString); try { Bitmap bitmap = readBitmapFromNetwork(urlString, sample); mCache.put(urlString, new SoftReference<Bitmap>(bitmap)); // if (Constants.LOGGING) Log.d(this.getClass().getSimpleName(), "got a thumbnail drawable: " + drawable.getBounds() + ", " // + drawable.getIntrinsicHeight() + "," + drawable.getIntrinsicWidth() + ", " // + drawable.getMinimumHeight() + "," + drawable.getMinimumWidth()); return bitmap; } catch (Exception e) { Log.e(TAG, "fetchBitmap failed", e); return null; } }
From source file:com.application.maskhos.maskhosblogapi.Model.interfaces.BitmapCache.BitmapMemoryLruCache.java
@Override protected void entryRemoved(boolean evicted, String key, CacheableBitmapDrawable oldValue, CacheableBitmapDrawable newValue) { // Notify the wrapper that it's no longer being cached oldValue.setCached(false);// www . jav a2 s . c om if (mRemovedEntries != null && oldValue.isBitmapValid() && oldValue.isBitmapMutable()) { synchronized (mRemovedEntries) { mRemovedEntries.add(new SoftReference<CacheableBitmapDrawable>(oldValue)); } } }
From source file:com.uzmap.pkg.uzmodules.UIMediaScanner.UzImgsAdapterForFileList.java
public UzImgsAdapterForFileList(Context context, ArrayList<FileInfo> data, OnItemClickClass onItemClickClass) { this.mContext = context; this.mAllImgFiles = data; this.mOnItemClickClass = onItemClickClass; long maxMem = Runtime.getRuntime().maxMemory() / 1024L; this.mCachedMap = new LruCache<String, SoftReference<Bitmap>>((int) (maxMem / 8L)); for (int i = 0; i < data.size(); i++) { this.mCachedMap.put(((FileInfo) data.get(i)).path, new SoftReference<Bitmap>(null)); }//from www. j a v a 2 s. co m this.mUtil = new Util(context); this.mHolderlist = new ArrayList<View>(); }
From source file:com.uzmap.pkg.uzmodules.UIMediaScanner.UzImgsAdapter.java
public UzImgsAdapter(Context context, ArrayList<FileInfo> data, OnItemClickClass onItemClickClass) { this.mContext = context; this.mAllImgFiles = data; this.onItemClickClass = onItemClickClass; long maxMem = Runtime.getRuntime().maxMemory() / 1024L; this.cacheMap = new LruCache<String, SoftReference<Bitmap>>((int) (maxMem / 8L)); for (int i = 0; i < data.size(); i++) { this.cacheMap.put(((FileInfo) data.get(i)).path, new SoftReference<Bitmap>(null)); }// ww w. j a v a 2 s . c o m this.mUtil = new Util(context); this.mHolderlist = new ArrayList<View>(); }