Java 类java.lang.ref.SoftReference 实例源码

项目:fitnotifications    文件:ZoneMeta.java   
/**
 * Returns an immutable set of system time zone IDs.
 * Etc/Unknown is excluded.
 * @return An immutable set of system time zone IDs.
 */
private static synchronized Set<String> getSystemZIDs() {
    Set<String> systemZones = null;
    if (REF_SYSTEM_ZONES != null) {
        systemZones = REF_SYSTEM_ZONES.get();
    }
    if (systemZones == null) {
        Set<String> systemIDs = new TreeSet<String>();
        String[] allIDs = getZoneIDs();
        for (String id : allIDs) {
            // exclude Etc/Unknown
            if (id.equals(TimeZone.UNKNOWN_ZONE_ID)) {
                continue;
            }
            systemIDs.add(id);
        }
        systemZones = Collections.unmodifiableSet(systemIDs);
        REF_SYSTEM_ZONES = new SoftReference<Set<String>>(systemZones);
    }
    return systemZones;
}
项目:ImmerseMode    文件:TlSbTlNbwFCImmerseMode.java   
public TlSbTlNbwFCImmerseMode(@NonNull Activity activity) {
    mActivityRef = new SoftReference<>(activity);

    Window window = activity.getWindow();
    WindowUtils.addWindowFlags(window, FLAG_TRANSLUCENT_STATUS);
    WindowUtils.addWindowFlags(window, FLAG_TRANSLUCENT_NAVIGATION);

    mActivityConfig = new ActivityConfig(activity);
    mCompatStatusBarView = setupStatusBarView(activity);
    mCompatNavigationBarView = setupNavigationBarView(activity);

    mCompatStatusBarView.setBackgroundColor(Color.TRANSPARENT);
    if (mCompatNavigationBarView != null) {
        mCompatNavigationBarView.setBackgroundColor(Color.TRANSPARENT);
    }
}
项目:OpenJSharp    文件:ReferenceTypeImpl.java   
private SDE sourceDebugExtensionInfo() {
    if (!vm.canGetSourceDebugExtension()) {
        return NO_SDE_INFO_MARK;
    }
    SDE sde = (sdeRef == null) ?  null : sdeRef.get();
    if (sde == null) {
        String extension = null;
        try {
            extension = JDWP.ReferenceType.SourceDebugExtension.
                process(vm, this).extension;
        } catch (JDWPException exc) {
            if (exc.errorCode() != JDWP.Error.ABSENT_INFORMATION) {
                sdeRef = new SoftReference<SDE>(NO_SDE_INFO_MARK);
                throw exc.toJDIException();
            }
        }
        if (extension == null) {
            sde = NO_SDE_INFO_MARK;
        } else {
            sde = new SDE(extension);
        }
        sdeRef = new SoftReference<SDE>(sde);
    }
    return sde;
}
项目:OpenJSharp    文件:PropertyMap.java   
/**
 * Check the history for a map that already has the given property added.
 *
 * @param property {@link Property} to add.
 *
 * @return Existing map or {@code null} if not found.
 */
private PropertyMap checkHistory(final Property property) {

    if (history != null) {
        final SoftReference<PropertyMap> ref = history.get(property);
        final PropertyMap historicMap = ref == null ? null : ref.get();

        if (historicMap != null) {
            if (Context.DEBUG) {
                historyHit++;
            }

            return historicMap;
        }
    }

    return null;
}
项目:jdk8u-jdk    文件:ZoneInfoOld.java   
static Map<String, String> getCachedAliasTable() {
    Map<String, String> aliases = null;

    SoftReference<Map<String, String>> cache = aliasTable;
    if (cache != null) {
        aliases = cache.get();
    }
    return aliases;
}
项目:openjdk-jdk10    文件:Snapshot.java   
public synchronized Enumeration<?> getFinalizerObjects() {
    Vector<?> obj;
    if (finalizablesCache != null &&
        (obj = finalizablesCache.get()) != null) {
        return obj.elements();
    }

    JavaClass clazz = findClass("java.lang.ref.Finalizer");
    JavaObject queue = (JavaObject) clazz.getStaticField("queue");
    JavaThing tmp = queue.getField("head");
    Vector<JavaHeapObject> finalizables = new Vector<JavaHeapObject>();
    if (tmp != getNullThing()) {
        JavaObject head = (JavaObject) tmp;
        while (true) {
            JavaHeapObject referent = (JavaHeapObject) head.getField("referent");
            JavaThing next = head.getField("next");
            if (next == getNullThing() || next.equals(head)) {
                break;
            }
            head = (JavaObject) next;
            finalizables.add(referent);
        }
    }
    finalizablesCache = new SoftReference<Vector<?>>(finalizables);
    return finalizables.elements();
}
项目:incubator-netbeans    文件:J2SEPlatformImpl.java   
/**
 * This implementation simply reads and parses `java.class.path' property and creates a ClassPath
 * out of it.
 * @return  ClassPath that represents contents of system property java.class.path.
 */
@Override
public ClassPath getStandardLibraries() {
    synchronized (this) {
        ClassPath cp = (standardLibs == null ? null : standardLibs.get());
        if (cp != null)
            return cp;
        final String pathSpec = getSystemProperties().get(SYSPROP_JAVA_CLASS_PATH);
        if (pathSpec == null) {
            cp = ClassPathSupport.createClassPath(new URL[0]);
        }
        else {
            cp = Util.createClassPath (pathSpec);
        }
        standardLibs = new SoftReference<>(cp);
        return cp;
    }
}
项目:incubator-netbeans    文件:AntBridge.java   
private synchronized static AntInstance getAntInstance() {
    AntInstance ai;
    if (antInstance != null) {
        ai = antInstance.get();
    } else {
        ai = null;
    }
    if (ai == null) {
        ai = createAntInstance();
        // XXX would be more accurate to stuff this struct into by BridgeImpl
        // so that it all lives or dies iff that class loader is still alive
        // (current impl is just workaround for JDK #6389107)
        antInstance = new SoftReference<AntInstance>(ai);
    }
    return ai;
}
项目:OpenJSharp    文件:PropertyMap.java   
/**
 * Check prototype history for an existing property map with specified prototype.
 *
 * @param proto New prototype object.
 *
 * @return Existing {@link PropertyMap} or {@code null} if not found.
 */
private PropertyMap checkProtoHistory(final ScriptObject proto) {
    final PropertyMap cachedMap;
    if (protoHistory != null) {
        final SoftReference<PropertyMap> weakMap = protoHistory.get(proto);
        cachedMap = (weakMap != null ? weakMap.get() : null);
    } else {
        cachedMap = null;
    }

    if (Context.DEBUG && cachedMap != null) {
        protoHistoryHit++;
    }

    return cachedMap;
}
项目:incubator-netbeans    文件:BeanSupport.java   
private static synchronized Image getIconForDefault(Class klass) {
    Map<String,Object> icons;
    if ((imageCache == null) || ((icons = imageCache.get()) == null)) {
        icons = createImageCache();
        imageCache = new SoftReference<Map<String,Object>>(icons);
    }

    String name = klass.getName();
    Object img = icons.get(name);

    if (img == null) {
        return null;
    }

    if (img instanceof Image) {
        return (Image) img;
    } else {
        Image image = java.awt.Toolkit.getDefaultToolkit().createImage(
                             BeanSupport.class.getResource((String)img));
        icons.put(name, image);
        return image;
    }
}
项目:incubator-netbeans    文件:ElementsParserCache.java   
private CacheBlock(CharSequence code, TokenSequence<HTMLTokenId> tokenSequence, int firstElementIndex, int firstTokenIndex) {
    this.code = code;
    this.tokenSequence = tokenSequence;

    this.startIndex = firstElementIndex;
    this.firstTokenIndex = firstTokenIndex;

    CacheBlockContent block = new CacheBlockContent(code, tokenSequence, firstTokenIndex);
    int blockSize = block.getElements().size();
    this.endIndex = firstElementIndex + blockSize;

    this.startOffset = blockSize == 0 ? -1 : block.getFirstElement().from();

    this.endOffset = blockSize == 0 ? -1 : block.getLastElement().to();
    this.lastTokenIndex = block.getLastTokenIndex();

    blockReads++;

    blockReference = new SoftReference<>(block);
}
项目:uavstack    文件:SerializeWriter.java   
public SerializeWriter(Writer writer, SerializerFeature... features){
    this.writer = writer;

    SoftReference<char[]> ref = bufLocal.get();

    if (ref != null) {
        buf = ref.get();
        bufLocal.set(null);
    }

    if (buf == null) {
        buf = new char[1024];
    }

    int featuresValue = 0;
    for (SerializerFeature feature : features) {
        featuresValue |= feature.getMask();
    }
    this.features = featuresValue;
}
项目:openjdk-jdk10    文件:TCPTransport.java   
/**
 * Verify that the given AccessControlContext has permission to
 * accept this connection.
 */
void checkAcceptPermission(SecurityManager sm,
                           AccessControlContext acc)
{
    /*
     * Note: no need to synchronize on cache-related fields, since this
     * method only gets called from the ConnectionHandler's thread.
     */
    if (sm != cacheSecurityManager) {
        okContext = null;
        authCache = new WeakHashMap<AccessControlContext,
                                    Reference<AccessControlContext>>();
        cacheSecurityManager = sm;
    }
    if (acc.equals(okContext) || authCache.containsKey(acc)) {
        return;
    }
    InetAddress addr = socket.getInetAddress();
    String host = (addr != null) ? addr.getHostAddress() : "*";

    sm.checkAccept(host, socket.getPort());

    authCache.put(acc, new SoftReference<AccessControlContext>(acc));
    okContext = acc;
}
项目:scanning    文件:LevelRunner.java   
/**
 * Get the scannables, ordered by level, lowest first
 * @param position
 * @return
 * @throws ScanningException
 */
protected Map<Integer, List<L>> getLevelOrderedDevices() throws ScanningException {
    if (sortedObjects!=null && sortedObjects.get()!=null) return sortedObjects.get();

    final Collection<L> devices = getDevices();

    if (devices == null) return Collections.emptyMap();

    final Map<Integer, List<L>> devicesByLevel = new TreeMap<>();
    for (L object : devices) {
        final int level = object.getLevel();

        if (!devicesByLevel.containsKey(level)) devicesByLevel.put(level, new ArrayList<L>(7));
        devicesByLevel.get(level).add(object);
    }
    if (isLevelCachingAllowed()) sortedObjects = new SoftReference<Map>(devicesByLevel);

    return devicesByLevel;
}
项目:jsf-sdk    文件:BufferRecycler.java   
/**
 * Accessor to get thread-local recycler instance
 */
public static BufferRecycler instance()
{
    SoftReference<BufferRecycler> ref = recyclerRef.get();

    BufferRecycler bufferRecycler;
    if (ref == null) {
        bufferRecycler = null;
    }
    else {
        bufferRecycler = ref.get();
    }

    if (bufferRecycler == null) {
        bufferRecycler = new BufferRecycler();
        recyclerRef.set(new SoftReference<BufferRecycler>(bufferRecycler));
    }
    return bufferRecycler;
}
项目:incubator-netbeans    文件:MylynSupport.java   
NbTask toNbTask (ITask task) {
    NbTask nbTask = null;
    if (task != null) {
        synchronized (tasks) {
            Reference<NbTask> nbTaskRef = tasks.get(task);
            if (nbTaskRef != null) {
                nbTask = nbTaskRef.get();
            }
            if (nbTask == null) {
                nbTask = new NbTask(task);
                tasks.put(task, new SoftReference<NbTask>(nbTask));
            }
        }
    }
    return nbTask;
}
项目:incubator-netbeans    文件:StructHandler.java   
/**
 * When the parser finishes its job, it calls this method to set new values.
 *
 * @param newPropStructure new properties structure
 * @param fire if should fire change when structure created anew
 */
private void updatePropertiesStructure(PropertiesStructure newPropStructure,
                                       boolean fire) {
    if (newPropStructure == null) {
        propStructureSRef = new SoftReference<PropertiesStructure>(null);
        return;
    }

    PropertiesStructure propStructure = propStructureSRef.get();

    if (propStructure == null) {
        // Set the parent.
        newPropStructure.setParent(this);
        propStructure = newPropStructure;
        propStructureSRef = new SoftReference<PropertiesStructure>(propStructure);

        if (fire) {
            propStructure.structureChanged();
        }
    } else {
        // Update calls notification methods according to changes.
        propStructure.update(newPropStructure);
    }
}
项目:openjdk-jdk10    文件:ZoneInfoOld.java   
/**
* Returns a Map from alias time zone IDs to their standard
* time zone IDs.
*
* @return the Map that holds the mappings from alias time zone IDs
*    to their standard time zone IDs, or null if
*    <code>ZoneInfoOldMappings</code> file is not available.
*/
public synchronized static Map<String, String> getAliasTable() {
    Map<String, String> aliases = getCachedAliasTable();
    if (aliases == null) {
        aliases = ZoneInfoFile.getZoneAliases();
        if (aliases != null) {
            if (!USE_OLDMAPPING) {
                // Remove the conflicting IDs from the alias table.
                for (String key : conflictingIDs) {
                    aliases.remove(key);
                }
            }
            aliasTable = new SoftReference<Map<String, String>>(aliases);
        }
    }
    return aliases;
}
项目:ImmerseMode    文件:TpSbNNbwFCImmerseMode.java   
public TpSbNNbwFCImmerseMode(@NonNull Activity activity) {
    mActivityRef = new SoftReference<>(activity);

    Window window = activity.getWindow();
    WindowUtils.clearWindowFlags(window, FLAG_TRANSLUCENT_STATUS);
    WindowUtils.clearWindowFlags(window, FLAG_TRANSLUCENT_NAVIGATION);
    WindowUtils.addWindowFlags(window, FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);

    window.getDecorView().setSystemUiVisibility(SYSTEM_UI_FLAG_LAYOUT_STABLE | SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);

    mCompatStatusBarView = setupContentViewAndStatusBarView(activity);

    window.setStatusBarColor(Color.TRANSPARENT);
    mCompatStatusBarView.setBackgroundColor(Color.TRANSPARENT);
}
项目:lams    文件:MetadataCredentialResolver.java   
/**
 * Constructor.
 * 
 * @param metadataProvider provider of the metadata
 * 
 * @throws IllegalArgumentException thrown if the supplied provider is null
 */
public MetadataCredentialResolver(MetadataProvider metadataProvider) {
    super();
    if (metadataProvider == null) {
        throw new IllegalArgumentException("Metadata provider may not be null");
    }
    metadata = metadataProvider;

    cache = new HashMap<MetadataCacheKey, SoftReference<Collection<Credential>>>();

    keyInfoCredentialResolver = Configuration.getGlobalSecurityConfiguration()
            .getDefaultKeyInfoCredentialResolver();

    rwlock = new ReentrantReadWriteLock();

    if (metadata instanceof ObservableMetadataProvider) {
        ObservableMetadataProvider observable = (ObservableMetadataProvider) metadataProvider;
        observable.getObservers().add(new MetadataProviderObserver());
    }

}
项目:incubator-netbeans    文件:LanguagePath.java   
/**
 * Get language path corresponding to the suffix language path embedded
 * in this path.
 * 
 * @param suffix non-null suffix to be added to this path.
 * @return non-null language path consisting of this path with the
 *  suffix added to the end.
 */
public LanguagePath embedded(LanguagePath suffix) {
    if (suffix == null) {
        throw new IllegalArgumentException("suffix cannot be null");
    }
    // Attempt to retrieve from the cache first
    synchronized (languages) {
        initLanguage2path();
        Reference<LanguagePath> lpRef = language2path.get(suffix);
        LanguagePath lp;
        if (lpRef == null || (lp = lpRef.get()) == null) {
            // Construct the LanguagePath
            lp = this;
            for (int i = 0; i < suffix.size(); i++) {
                lp = lp.embedded(suffix.language(i));
            }
            language2path.put(suffix, new SoftReference<LanguagePath>(lp));
        }

        return lp;
    }
}
项目:rapidminer    文件:ObjectVisualizerService.java   
/**
 * Returns the object visualizer registered for this targetObject. If the targetObject is of
 * type ExampleSet and there's no special visualizer registered, it will return an new
 * ExampleVisualizer.
 */
public static ObjectVisualizer getVisualizerForObject(Object targetObject) {
    ObjectVisualizer capableVisualizer = null;
    SoftReference<ObjectVisualizer> visualizerReference = visualizerMap.get(targetObject);
    if (visualizerReference != null) {
        capableVisualizer = visualizerReference.get();
    }
    if (capableVisualizer == null) {
        if (targetObject instanceof ExampleSet) {
            ObjectVisualizer visualizer = new ExampleVisualizer((ExampleSet) targetObject);
            addObjectVisualizer(targetObject, visualizer);
            return visualizer;
        }
        return DUMMY_VISUALIZER;
    }
    return capableVisualizer;
}
项目:rapidminer    文件:Cache.java   
private Cache.Entry getEntry(Object key, GraphicsConfiguration config, int w, int h, Object[] args) {
    synchronized (this) {
        Cache.Entry entry;

        for (int counter = this.entries.size() - 1; counter >= 0; counter--) {

            entry = (Cache.Entry) ((SoftReference) this.entries.get(counter)).get();

            if (entry == null) {
                this.entries.remove(counter);
            } else if (entry.equals(config, w, h, args)) {
                return entry;
            }
        }
        entry = new Entry(config, w, h, args);
        if (this.entries.size() == this.maxCount) {
            this.entries.remove(0);
        }
        this.entries.add(new SoftReference<Cache.Entry>(entry));
        return entry;
    }
}
项目:jdk8u-jdk    文件:ImageCache.java   
private Entry getEntry(Object key, GraphicsConfiguration config,
                       int w, int h, Object[] args) {
    Entry entry;
    Iterator<SoftReference<Entry>> iter = entries.listIterator();
    while (iter.hasNext()) {
        SoftReference<Entry> ref = iter.next();
        entry = ref.get();
        if (entry == null) {
            // SoftReference was invalidated, remove the entry
            iter.remove();
        }
        else if (entry.equals(config, w, h, args)) {
            // Put most recently used entries at the head
            iter.remove();
            entries.addFirst(ref);
            return entry;
        }
    }
    // Entry doesn't exist
    entry = new Entry(config, w, h, args);
    if (entries.size() >= maxCount) {
        entries.removeLast();
    }
    entries.addFirst(new SoftReference<Entry>(entry));
    return entry;
}
项目:OpenJSharp    文件:StrikeCache.java   
public static Reference getStrikeRef(FontStrike strike, boolean weak) {
    /* Some strikes may have no disposer as there's nothing
     * for them to free, as they allocated no native resource
     * eg, if they did not allocate resources because of a problem,
     * or they never hold native resources. So they create no disposer.
     * But any strike that reaches here that has a null disposer is
     * a potential memory leak.
     */
    if (strike.disposer == null) {
        if (weak) {
            return new WeakReference(strike);
        } else {
            return new SoftReference(strike);
        }
    }

    if (weak) {
        return new WeakDisposerRef(strike);
    } else {
        return new SoftDisposerRef(strike);
    }
}
项目:Cable-Android    文件:ConversationAdapter.java   
@Override
protected MessageRecord getRecordFromCursor(@NonNull Cursor cursor) {
  long   messageId = cursor.getLong(cursor.getColumnIndexOrThrow(MmsSmsColumns.ID));
  String type      = cursor.getString(cursor.getColumnIndexOrThrow(MmsSmsDatabase.TRANSPORT));

  final SoftReference<MessageRecord> reference = messageRecordCache.get(type + messageId);
  if (reference != null) {
    final MessageRecord record = reference.get();
    if (record != null) return record;
  }

  final MessageRecord messageRecord = db.readerFor(cursor, masterSecret).getCurrent();
  messageRecordCache.put(type + messageId, new SoftReference<>(messageRecord));

  return messageRecord;
}
项目:FlexibleRichTextView    文件:JLaTeXMathCache.java   
/**
 * Set max size. Take care the cache will be reinitialized
 * 
 * @param max
 *            the max size
 */
public static void setMaxCachedObjects(int max) {
    JLaTeXMathCache.max = Math.max(max, 1);
    cache.clear();
    cache = new ConcurrentHashMap<CachedTeXFormula, SoftReference<CachedImage>>(
            JLaTeXMathCache.max);
}
项目:OpenJSharp    文件:AquaUtils.java   
T get() {
    T referent;
    if (objectRef != null && (referent = objectRef.get()) != null) return referent;
    referent = create();
    objectRef = new SoftReference<T>(referent);
    return referent;
}
项目:NioImapClient    文件:SoftReferencedAppendableCharSequence.java   
public AppendableCharSequence get() {
  AppendableCharSequence sequence = reference.get();
  if (sequence == null) {
    sequence = newCharSeq();
  }

  reference = new SoftReference<>(sequence);

  return sequence;
}
项目:jkami    文件:CacheMap.java   
@Override
public V put(K key, V value) {
    SoftReference<V> reference = new SoftReference<>(value);
    Object oldValue = map.put(key, reference);
    if (oldValue instanceof SoftReference) {
        return ((SoftReference<V>) oldValue).get();
    } else {
        return (V) oldValue;
    }
}
项目:NotifyTools    文件:MappedPropertyDescriptor.java   
/**
 * Introspect our bean class to identify the corresponding getter
 * and setter methods.
 */
private void findMappedPropertyType() throws IntrospectionException {
    try {
        final Method mappedReadMethod  = getMappedReadMethod();
        final Method mappedWriteMethod = getMappedWriteMethod();
        Class<?> mappedPropertyType = null;
        if (mappedReadMethod != null) {
            if (mappedReadMethod.getParameterTypes().length != 1) {
                throw new IntrospectionException
                        ("bad mapped read method arg count");
            }
            mappedPropertyType = mappedReadMethod.getReturnType();
            if (mappedPropertyType == Void.TYPE) {
                throw new IntrospectionException
                        ("mapped read method " +
                        mappedReadMethod.getName() + " returns void");
            }
        }

        if (mappedWriteMethod != null) {
            final Class<?>[] params = mappedWriteMethod.getParameterTypes();
            if (params.length != 2) {
                throw new IntrospectionException
                        ("bad mapped write method arg count");
            }
            if (mappedPropertyType != null &&
                    mappedPropertyType != params[1]) {
                throw new IntrospectionException
                        ("type mismatch between mapped read and write methods");
            }
            mappedPropertyType = params[1];
        }
        mappedPropertyTypeRef = new SoftReference<Class<?>>(mappedPropertyType);
    } catch (final IntrospectionException ex) {
        throw ex;
    }
}
项目:OpenJSharp    文件:PropertyMap.java   
/**
 * Add a map to the prototype history.
 *
 * @param newProto Prototype to add (key.)
 * @param newMap   {@link PropertyMap} associated with prototype.
 */
private void addToProtoHistory(final ScriptObject newProto, final PropertyMap newMap) {
    if (protoHistory == null) {
        protoHistory = new WeakHashMap<>();
    }

    protoHistory.put(newProto, new SoftReference<>(newMap));
}
项目:fitnotifications    文件:Currency.java   
private static synchronized Set<String> getAllCurrenciesAsSet() {
    Set<String> all = (ALL_CODES_AS_SET == null) ? null : ALL_CODES_AS_SET.get();
    if (all == null) {
        CurrencyMetaInfo info = CurrencyMetaInfo.getInstance();
        all = Collections.unmodifiableSet(
                new HashSet<String>(info.currencies(CurrencyFilter.all())));
        ALL_CODES_AS_SET = new SoftReference<Set<String>>(all);
    }
    return all;
}
项目:Jupiter    文件:Level.java   
private void addBlockChange(long index, int x, int y, int z) {
    SoftReference<Map<Short, Object>> current = changedBlocks.computeIfAbsent(index, k -> new SoftReference(new HashMap<>()));
    Map<Short, Object> currentMap = current.get();
    if (currentMap != changeBlocksFullMap && currentMap != null) {
        if (currentMap.size() > MAX_BLOCK_CACHE) {
            this.changedBlocks.put(index, new SoftReference(changeBlocksFullMap));
        } else {
            currentMap.put(Level.localBlockHash(x, y, z), changeBlocksPresent);
        }
    }
}
项目:OpenJSharp    文件:MethodRef.java   
void set(Method method) {
    if (method == null) {
        this.signature = null;
        this.methodRef = null;
        this.typeRef = null;
    }
    else {
        this.signature = method.toGenericString();
        this.methodRef = new SoftReference<>(method);
        this.typeRef = new WeakReference<Class<?>>(method.getDeclaringClass());
    }
}
项目:javaide    文件:ZipFileIndex.java   
private int inflate(byte[] src, byte[] dest) {
    Inflater inflater = (inflaterRef == null ? null : inflaterRef.get());

    // construct the inflater object or reuse an existing one
    if (inflater == null)
        inflaterRef = new SoftReference<Inflater>(inflater = new Inflater(true));

    inflater.reset();
    inflater.setInput(src);
    try {
        return inflater.inflate(dest);
    } catch (DataFormatException ex) {
        return -1;
    }
}
项目:CacheManage    文件:CacheUtil.java   
/**
 * 获取LruCache,防止弱引用销毁
 */
private static LruCache<String, String> getLruCache() {
    LruCache<String, String> lruCache = getInstance().mLuCache.get();
    if (lruCache == null) {
        getInstance().mLuCache = new SoftReference<>(new LruCache<String, String>(50));
        lruCache = getInstance().mLuCache.get();
    }
    return lruCache;
}
项目:PeSanKita-android    文件:EncryptingSmsDatabase.java   
public String get(String ciphertext) {
  SoftReference<String> plaintextReference = decryptedBodyCache.get(ciphertext);

  if (plaintextReference != null) {
    String plaintext = plaintextReference.get();

    if (plaintext != null) {
      return plaintext;
    }
  }

  return null;
}
项目:boohee_v5.6    文件:ThreadLocalCache.java   
public static char[] getChars(int length) {
    SoftReference<char[]> ref = (SoftReference) charsBufLocal.get();
    if (ref == null) {
        return allocate(length);
    }
    char[] chars = (char[]) ref.get();
    if (chars == null) {
        return allocate(length);
    }
    if (chars.length < length) {
        return allocate(length);
    }
    return chars;
}
项目:OpenJSharp    文件:ReferenceTypeImpl.java   
private void getConstantPoolInfo() {
    JDWP.ReferenceType.ConstantPool jdwpCPool;
    if (!vm.canGetConstantPool()) {
        throw new UnsupportedOperationException();
    }
    if (constantPoolInfoGotten) {
        return;
    } else {
        try {
            jdwpCPool = JDWP.ReferenceType.ConstantPool.process(vm, this);
        } catch (JDWPException exc) {
            if (exc.errorCode() == JDWP.Error.ABSENT_INFORMATION) {
                constanPoolCount = 0;
                constantPoolBytesRef = null;
                constantPoolInfoGotten = true;
                return;
            } else {
                throw exc.toJDIException();
            }
        }
        byte[] cpbytes;
        constanPoolCount = jdwpCPool.count;
        cpbytes = jdwpCPool.bytes;
        constantPoolBytesRef = new SoftReference<byte[]>(cpbytes);
        constantPoolInfoGotten = true;
    }
}