List of usage examples for java.lang.ref WeakReference WeakReference
public WeakReference(T referent)
From source file:edu.cornell.mannlib.vitro.webapp.freemarker.config.FreemarkerConfigurationImpl.java
void setRequestInfo(HttpServletRequest req) { reqRef.set(new WeakReference<>(req)); req.setAttribute(ATTRIBUTE_NAME, new RequestBasedInformation(req, this)); }
From source file:com.flowpowered.engine.entity.FlowEntitySnapshot.java
public FlowEntitySnapshot(UUID id, Transform t, UUID worldId, byte[] dataMap, List<Class<? extends Component>> types) { this.entity = new WeakReference<>(null); this.entityId = -1; this.uniqueId = id; this.location = t; this.worldName = null; this.worldId = worldId; this.savable = true; this.dataMap = new ManagedHashMap(); if (dataMap != null) { try {//from ww w .j a v a 2s . c om this.dataMap.deserialize(dataMap); } catch (IOException e) { throw new RuntimeException("Unable to deserialize data", e); } } this.components = new ArrayList<>(types); }
From source file:disko.PDFDocument.java
protected synchronized String load() { final StringWriter stringOutput = new StringWriter(); PDDocument document = null;//from w w w . j av a 2 s . c o m try { document = PDDocument.load(ContentDownloader.getInstance().getInputStream(getUrlString())); title = document.getDocumentInformation().getTitle(); PDFTextStripper stripper = new PDFTextStripper() { int startPage = 0; private int getIndex() { return stringOutput.getBuffer().length(); } @Override protected void startPage(PDPage page) throws IOException { startPage = getIndex(); log.debug("START PAGE " + getCurrentPageNo() + " AT " + startPage); } @Override protected void endPage(PDPage page) throws IOException { int endPage = getIndex(); DocumentAnn ann = new DocumentAnn(startPage, endPage, PAGE_ANN); annotations.add(ann); log.debug("END PAGE " + getCurrentPageNo() + " AT " + endPage); } }; // stripper.setSortByPosition(false); // String maxPageSetting = System.getProperty("disco.pdf.max.pages", // Integer.toString(Integer.MAX_VALUE)); // stripper.setEndPage(Integer.parseInt(maxPageSetting)); stripper.writeText(document, stringOutput); } catch (Throwable t) { throw new RuntimeException("Unable to read resource at URL '" + url + "'", t); } finally { if (stringOutput != null) { try { stringOutput.close(); } catch (IOException e) { } } if (document != null) { try { document.close(); } catch (IOException e) { } } } String s = DU.replaceUnicodePunctuation(stringOutput.toString()); ParagraphDetector.detectParagraphs(s, this.annotations); return (fullText = new WeakReference<String>(s)).get(); }
From source file:com.lastorder.pushnotifications.data.ImageDownloader.java
/** * Download the specified image from the Internet and binds it to the provided ImageView. The * binding is immediate if the image is found in the cache and will be done asynchronously * otherwise. A null bitmap will be associated to the ImageView if an error occurs. * * @param url The URL of the image to download. * @param imageView The ImageView to bind the downloaded image to. */// w w w . j a v a 2s .co m public void download(String url, ImageView imageView, Context context, ProgressBar bar) { resetPurgeTimer(); Bitmap bitmap = getBitmapFromCache(url); myWeakContext = new WeakReference<Context>(context); if (bitmap == null) { bar.setVisibility(0); imageView.setVisibility(8); forceDownload(url, imageView, bar); } else { bar.setVisibility(8); cancelPotentialDownload(url, imageView); imageView.setImageBitmap(bitmap); imageView.setVisibility(0); imageView.bringToFront(); } }
From source file:net.lightbody.bmp.proxy.jetty.util.RolloverFileOutputStream.java
public RolloverFileOutputStream(String filename, boolean append, int retainDays) throws IOException { super(null);// ww w .j a v a 2s . c o m if (filename != null) { filename = filename.trim(); if (filename.length() == 0) filename = null; } if (filename == null) throw new IllegalArgumentException("Invalid filename"); _filename = filename; _append = append; _retainDays = retainDays; _ref = new WeakReference(this); setFile(); synchronized (__rollovers) { if (__rollover == null) { __rollover = new Rollover(); __rollover.start(); } __rollovers.add(_ref); } }
From source file:com.crossbow.volley.toolbox.CrossbowImageCache.java
public void storeForReUse(Bitmap bitmap) { synchronized (imageCache) { if (bitmapCanBeReused(bitmap)) { unusedBitmaps.add(new WeakReference<Bitmap>(bitmap)); }//w w w . java 2 s . c o m } }
From source file:com.chiorichan.http.HttpRequestWrapper.java
private static void putRequest(HttpRequestWrapper request) { references.put(Thread.currentThread(), new WeakReference<HttpRequestWrapper>(request)); }
From source file:com.dubsar_dictionary.Dubsar.model.Sense.java
/** * Constructor for some senses in sense and synset parsing * @param id a sense ID/*from w ww . ja va 2 s. com*/ * @param name the associated word's name * @param synset the associated synset */ public Sense(int id, String name, Synset synset) { super(synset.getPartOfSpeech()); mId = id; mName = new String(name); mIsWeakSynsetReference = true; mSynsetReference = new WeakReference<Synset>(synset); setupUrl(); }
From source file:com.adkdevelopment.earthquakesurvival.ui.adapters.PagerAdapter.java
@Override public Object instantiateItem(ViewGroup container, int position) { Fragment fragment = (Fragment) super.instantiateItem(container, position); registeredFragments.put(position, new WeakReference<>(fragment)); return fragment; }