@@ -130,7 +130,9 @@ public static CacheUtils getInstance(@NonNull final File cacheDir) {
130130 * @param maxCount 最大缓存个数
131131 * @return {@link CacheUtils}
132132 */
133- public static CacheUtils getInstance (@ NonNull final File cacheDir , final long maxSize , final int maxCount ) {
133+ public static CacheUtils getInstance (@ NonNull final File cacheDir ,
134+ final long maxSize ,
135+ final int maxCount ) {
134136 final String cacheKey = cacheDir .getAbsoluteFile () + "_" + Process .myPid ();
135137 CacheUtils cache = CACHE_MAP .get (cacheKey );
136138 if (cache == null ) {
@@ -175,7 +177,6 @@ public void put(@NonNull final String key, @NonNull byte[] value, final int save
175177 CacheHelper .writeFileFromBytes (file , value );
176178 mCacheManager .updateModify (file );
177179 mCacheManager .put (file );
178-
179180 }
180181
181182 /**
@@ -276,7 +277,9 @@ public void put(@NonNull final String key, @NonNull final JSONObject value) {
276277 * @param value 值
277278 * @param saveTime 保存时长,单位:秒
278279 */
279- public void put (@ NonNull final String key , @ NonNull final JSONObject value , final int saveTime ) {
280+ public void put (@ NonNull final String key ,
281+ @ NonNull final JSONObject value ,
282+ final int saveTime ) {
280283 put (key , CacheHelper .jsonObject2Bytes (value ), saveTime );
281284 }
282285
@@ -470,7 +473,9 @@ public void put(@NonNull final String key, @NonNull final Parcelable value) {
470473 * @param value 值
471474 * @param saveTime 保存时长,单位:秒
472475 */
473- public void put (@ NonNull final String key , @ NonNull final Parcelable value , final int saveTime ) {
476+ public void put (@ NonNull final String key ,
477+ @ NonNull final Parcelable value ,
478+ final int saveTime ) {
474479 put (key , CacheHelper .parcelable2Bytes (value ), saveTime );
475480 }
476481
@@ -481,7 +486,8 @@ public void put(@NonNull final String key, @NonNull final Parcelable value, fina
481486 * @param creator 建造器
482487 * @return 存在且没过期返回对应值,否则返回{@code null}
483488 */
484- public <T > T getParcelable (@ NonNull final String key , @ NonNull final Parcelable .Creator <T > creator ) {
489+ public <T > T getParcelable (@ NonNull final String key ,
490+ @ NonNull final Parcelable .Creator <T > creator ) {
485491 return getParcelable (key , creator , null );
486492 }
487493
@@ -493,7 +499,9 @@ public <T> T getParcelable(@NonNull final String key, @NonNull final Parcelable.
493499 * @param defaultValue 默认值
494500 * @return 存在且没过期返回对应值,否则返回默认值{@code defaultValue}
495501 */
496- public <T > T getParcelable (@ NonNull final String key , @ NonNull final Parcelable .Creator <T > creator , final T defaultValue ) {
502+ public <T > T getParcelable (@ NonNull final String key ,
503+ @ NonNull final Parcelable .Creator <T > creator ,
504+ final T defaultValue ) {
497505 byte [] bytes = getBytes (key );
498506 if (bytes == null ) return defaultValue ;
499507 return CacheHelper .bytes2Parcelable (bytes , creator );
@@ -520,7 +528,9 @@ public void put(@NonNull final String key, @NonNull final Serializable value) {
520528 * @param value 值
521529 * @param saveTime 保存时长,单位:秒
522530 */
523- public void put (@ NonNull final String key , @ NonNull final Serializable value , final int saveTime ) {
531+ public void put (@ NonNull final String key ,
532+ @ NonNull final Serializable value ,
533+ final int saveTime ) {
524534 put (key , CacheHelper .serializable2Bytes (value ), saveTime );
525535 }
526536
@@ -592,7 +602,8 @@ private class CacheManager {
592602 private final AtomicInteger cacheCount ;
593603 private final long sizeLimit ;
594604 private final int countLimit ;
595- private final Map <File , Long > lastUsageDates = Collections .synchronizedMap (new HashMap <File , Long >());
605+ private final Map <File , Long > lastUsageDates
606+ = Collections .synchronizedMap (new HashMap <File , Long >());
596607 private final File cacheDir ;
597608 private final Thread mThread ;
598609
@@ -749,7 +760,10 @@ private static byte[] newByteArrayWithTime(final int second, final byte[] data)
749760 * @return _$millis$_
750761 */
751762 private static String createDueTime (final int second ) {
752- return String .format (Locale .getDefault (), "_$%010d$_" , System .currentTimeMillis () / 1000 + second );
763+ return String .format (
764+ Locale .getDefault (), "_$%010d$_" ,
765+ System .currentTimeMillis () / 1000 + second
766+ );
753767 }
754768
755769 private static boolean isDue (final byte [] data ) {
@@ -872,7 +886,8 @@ private static byte[] parcelable2Bytes(final Parcelable parcelable) {
872886 return bytes ;
873887 }
874888
875- private static <T > T bytes2Parcelable (final byte [] bytes , final Parcelable .Creator <T > creator ) {
889+ private static <T > T bytes2Parcelable (final byte [] bytes ,
890+ final Parcelable .Creator <T > creator ) {
876891 if (bytes == null ) return null ;
877892 Parcel parcel = Parcel .obtain ();
878893 parcel .unmarshall (bytes , 0 , bytes .length );
@@ -920,7 +935,9 @@ private static byte[] bitmap2Bytes(final Bitmap bitmap) {
920935 }
921936
922937 private static Bitmap bytes2Bitmap (final byte [] bytes ) {
923- return (bytes == null || bytes .length == 0 ) ? null : BitmapFactory .decodeByteArray (bytes , 0 , bytes .length );
938+ return (bytes == null || bytes .length == 0 )
939+ ? null
940+ : BitmapFactory .decodeByteArray (bytes , 0 , bytes .length );
924941 }
925942
926943 private static byte [] drawable2Bytes (final Drawable drawable ) {
@@ -940,11 +957,21 @@ private static Bitmap drawable2Bitmap(final Drawable drawable) {
940957 }
941958 Bitmap bitmap ;
942959 if (drawable .getIntrinsicWidth () <= 0 || drawable .getIntrinsicHeight () <= 0 ) {
943- bitmap = Bitmap .createBitmap (1 , 1 ,
944- drawable .getOpacity () != PixelFormat .OPAQUE ? Bitmap .Config .ARGB_8888 : Bitmap .Config .RGB_565 );
960+ bitmap = Bitmap .createBitmap (
961+ 1 ,
962+ 1 ,
963+ drawable .getOpacity () != PixelFormat .OPAQUE
964+ ? Bitmap .Config .ARGB_8888
965+ : Bitmap .Config .RGB_565
966+ );
945967 } else {
946- bitmap = Bitmap .createBitmap (drawable .getIntrinsicWidth (), drawable .getIntrinsicHeight (),
947- drawable .getOpacity () != PixelFormat .OPAQUE ? Bitmap .Config .ARGB_8888 : Bitmap .Config .RGB_565 );
968+ bitmap = Bitmap .createBitmap (
969+ drawable .getIntrinsicWidth (),
970+ drawable .getIntrinsicHeight (),
971+ drawable .getOpacity () != PixelFormat .OPAQUE
972+ ? Bitmap .Config .ARGB_8888
973+ : Bitmap .Config .RGB_565
974+ );
948975 }
949976 Canvas canvas = new Canvas (bitmap );
950977 drawable .setBounds (0 , 0 , canvas .getWidth (), canvas .getHeight ());
@@ -953,7 +980,9 @@ private static Bitmap drawable2Bitmap(final Drawable drawable) {
953980 }
954981
955982 private static Drawable bitmap2Drawable (final Bitmap bitmap ) {
956- return bitmap == null ? null : new BitmapDrawable (Utils .getApp ().getResources (), bitmap );
983+ return bitmap == null
984+ ? null
985+ : new BitmapDrawable (Utils .getApp ().getResources (), bitmap );
957986 }
958987 }
959988
0 commit comments