FileUtil.java 15.8 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508
package com.bitstrips.imoji.util;

import android.content.Context;
import android.content.res.Resources;
import android.os.Environment;
import android.support.annotation.WorkerThread;
import com.crashlytics.android.Crashlytics;
import java.io.Closeable;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import javax.inject.Inject;
import javax.inject.Singleton;

@Singleton
public class FileUtil
{
  private static final Object a = new Object();
  private Context b;
  private File c;
  private File d;
  
  @Inject
  public FileUtil(Context paramContext)
  {
    this.b = paramContext;
    a();
  }
  
  private File a(boolean paramBoolean)
  {
    String str2 = new SimpleDateFormat("yyyyMMddhhmmss", Locale.US).format(new Date());
    if (paramBoolean) {}
    for (String str1 = this.d.getAbsolutePath();; str1 = this.c.getAbsolutePath()) {
      return new File(str1 + File.separator + "bitmoji-" + str2 + ".png");
    }
  }
  
  private void a()
  {
    this.c = new File(Environment.getExternalStorageDirectory(), this.b.getResources().getString(2131231253));
    if (!this.c.exists()) {
      this.c.mkdirs();
    }
    this.d = new File(this.b.getExternalFilesDir(Environment.DIRECTORY_PICTURES) + File.separator + "temp");
    if (!this.d.exists()) {
      this.d.mkdirs();
    }
    File[] arrayOfFile = this.d.listFiles();
    if (arrayOfFile == null) {}
    for (;;)
    {
      return;
      int j = arrayOfFile.length;
      int i = 0;
      while (i < j)
      {
        arrayOfFile[i].delete();
        i += 1;
      }
    }
  }
  
  private static void a(Closeable paramCloseable)
  {
    if (paramCloseable != null) {}
    try
    {
      paramCloseable.close();
      return;
    }
    catch (IOException paramCloseable) {}
  }
  
  /* Error */
  private static void a(File paramFile1, File paramFile2, boolean paramBoolean)
    throws IOException
  {
    // Byte code:
    //   0: aconst_null
    //   1: astore 13
    //   3: aload_1
    //   4: invokevirtual 105	java/io/File:exists	()Z
    //   7: ifeq +39 -> 46
    //   10: aload_1
    //   11: invokevirtual 139	java/io/File:isDirectory	()Z
    //   14: ifeq +32 -> 46
    //   17: new 130	java/io/IOException
    //   20: dup
    //   21: new 58	java/lang/StringBuilder
    //   24: dup
    //   25: ldc -115
    //   27: invokespecial 142	java/lang/StringBuilder:<init>	(Ljava/lang/String;)V
    //   30: aload_1
    //   31: invokevirtual 118	java/lang/StringBuilder:append	(Ljava/lang/Object;)Ljava/lang/StringBuilder;
    //   34: ldc -112
    //   36: invokevirtual 63	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   39: invokevirtual 74	java/lang/StringBuilder:toString	()Ljava/lang/String;
    //   42: invokespecial 145	java/io/IOException:<init>	(Ljava/lang/String;)V
    //   45: athrow
    //   46: new 147	java/io/FileInputStream
    //   49: dup
    //   50: aload_0
    //   51: invokespecial 150	java/io/FileInputStream:<init>	(Ljava/io/File;)V
    //   54: astore 9
    //   56: new 152	java/io/FileOutputStream
    //   59: dup
    //   60: aload_1
    //   61: invokespecial 153	java/io/FileOutputStream:<init>	(Ljava/io/File;)V
    //   64: astore 10
    //   66: aload 9
    //   68: invokevirtual 157	java/io/FileInputStream:getChannel	()Ljava/nio/channels/FileChannel;
    //   71: astore 11
    //   73: aload 10
    //   75: invokevirtual 158	java/io/FileOutputStream:getChannel	()Ljava/nio/channels/FileChannel;
    //   78: astore 13
    //   80: aload 11
    //   82: invokevirtual 164	java/nio/channels/FileChannel:size	()J
    //   85: lstore 7
    //   87: lconst_0
    //   88: lstore_3
    //   89: goto +230 -> 319
    //   92: aload 13
    //   94: aload 11
    //   96: lload_3
    //   97: lload 5
    //   99: invokevirtual 168	java/nio/channels/FileChannel:transferFrom	(Ljava/nio/channels/ReadableByteChannel;JJ)J
    //   102: lstore 5
    //   104: lload_3
    //   105: lload 5
    //   107: ladd
    //   108: lstore_3
    //   109: goto +210 -> 319
    //   112: lload 7
    //   114: lload_3
    //   115: lsub
    //   116: lstore 5
    //   118: goto -26 -> 92
    //   121: aload 13
    //   123: invokestatic 170	com/bitstrips/imoji/util/FileUtil:a	(Ljava/io/Closeable;)V
    //   126: aload 10
    //   128: invokestatic 170	com/bitstrips/imoji/util/FileUtil:a	(Ljava/io/Closeable;)V
    //   131: aload 11
    //   133: invokestatic 170	com/bitstrips/imoji/util/FileUtil:a	(Ljava/io/Closeable;)V
    //   136: aload 9
    //   138: invokestatic 170	com/bitstrips/imoji/util/FileUtil:a	(Ljava/io/Closeable;)V
    //   141: aload_0
    //   142: invokevirtual 173	java/io/File:length	()J
    //   145: aload_1
    //   146: invokevirtual 173	java/io/File:length	()J
    //   149: lcmp
    //   150: ifeq +75 -> 225
    //   153: new 130	java/io/IOException
    //   156: dup
    //   157: new 58	java/lang/StringBuilder
    //   160: dup
    //   161: ldc -81
    //   163: invokespecial 142	java/lang/StringBuilder:<init>	(Ljava/lang/String;)V
    //   166: aload_0
    //   167: invokevirtual 118	java/lang/StringBuilder:append	(Ljava/lang/Object;)Ljava/lang/StringBuilder;
    //   170: ldc -79
    //   172: invokevirtual 63	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   175: aload_1
    //   176: invokevirtual 118	java/lang/StringBuilder:append	(Ljava/lang/Object;)Ljava/lang/StringBuilder;
    //   179: ldc -77
    //   181: invokevirtual 63	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   184: invokevirtual 74	java/lang/StringBuilder:toString	()Ljava/lang/String;
    //   187: invokespecial 145	java/io/IOException:<init>	(Ljava/lang/String;)V
    //   190: athrow
    //   191: astore_0
    //   192: aconst_null
    //   193: astore_1
    //   194: aconst_null
    //   195: astore 9
    //   197: aconst_null
    //   198: astore 10
    //   200: aload 13
    //   202: astore 11
    //   204: aload_1
    //   205: invokestatic 170	com/bitstrips/imoji/util/FileUtil:a	(Ljava/io/Closeable;)V
    //   208: aload 9
    //   210: invokestatic 170	com/bitstrips/imoji/util/FileUtil:a	(Ljava/io/Closeable;)V
    //   213: aload 11
    //   215: invokestatic 170	com/bitstrips/imoji/util/FileUtil:a	(Ljava/io/Closeable;)V
    //   218: aload 10
    //   220: invokestatic 170	com/bitstrips/imoji/util/FileUtil:a	(Ljava/io/Closeable;)V
    //   223: aload_0
    //   224: athrow
    //   225: iload_2
    //   226: ifeq +12 -> 238
    //   229: aload_1
    //   230: aload_0
    //   231: invokevirtual 182	java/io/File:lastModified	()J
    //   234: invokevirtual 186	java/io/File:setLastModified	(J)Z
    //   237: pop
    //   238: return
    //   239: astore_0
    //   240: aconst_null
    //   241: astore_1
    //   242: aconst_null
    //   243: astore 12
    //   245: aload 9
    //   247: astore 10
    //   249: aload 13
    //   251: astore 11
    //   253: aload 12
    //   255: astore 9
    //   257: goto -53 -> 204
    //   260: astore_0
    //   261: aconst_null
    //   262: astore_1
    //   263: aload 9
    //   265: astore 12
    //   267: aload 13
    //   269: astore 11
    //   271: aload 10
    //   273: astore 9
    //   275: aload 12
    //   277: astore 10
    //   279: goto -75 -> 204
    //   282: astore_0
    //   283: aload 9
    //   285: astore 12
    //   287: aconst_null
    //   288: astore_1
    //   289: aload 10
    //   291: astore 9
    //   293: aload 12
    //   295: astore 10
    //   297: goto -93 -> 204
    //   300: astore_0
    //   301: aload 9
    //   303: astore 12
    //   305: aload 13
    //   307: astore_1
    //   308: aload 10
    //   310: astore 9
    //   312: aload 12
    //   314: astore 10
    //   316: goto -112 -> 204
    //   319: lload_3
    //   320: lload 7
    //   322: lcmp
    //   323: ifge -202 -> 121
    //   326: lload 7
    //   328: lload_3
    //   329: lsub
    //   330: ldc2_w 187
    //   333: lcmp
    //   334: ifle -222 -> 112
    //   337: ldc2_w 187
    //   340: lstore 5
    //   342: goto -250 -> 92
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	345	0	paramFile1	File
    //   0	345	1	paramFile2	File
    //   0	345	2	paramBoolean	boolean
    //   88	241	3	l1	long
    //   97	1	5	localObject1	Object
    //   102	239	5	l2	long
    //   85	242	7	l3	long
    //   54	257	9	localObject2	Object
    //   64	251	10	localObject3	Object
    //   71	199	11	localFileChannel1	java.nio.channels.FileChannel
    //   243	70	12	localObject4	Object
    //   1	305	13	localFileChannel2	java.nio.channels.FileChannel
    // Exception table:
    //   from	to	target	type
    //   46	56	191	finally
    //   56	66	239	finally
    //   66	73	260	finally
    //   73	80	282	finally
    //   80	87	300	finally
    //   92	104	300	finally
  }
  
  public static void copyFile(File paramFile1, File paramFile2)
    throws IOException
  {
    copyFile(paramFile1, paramFile2, true);
  }
  
  public static void copyFile(File paramFile1, File paramFile2, boolean paramBoolean)
    throws IOException
  {
    if (paramFile1 == null) {
      throw new NullPointerException("Source must not be null");
    }
    if (paramFile2 == null) {
      throw new NullPointerException("Destination must not be null");
    }
    if (!paramFile1.exists()) {
      throw new FileNotFoundException("Source '" + paramFile1 + "' does not exist");
    }
    if (paramFile1.isDirectory()) {
      throw new IOException("Source '" + paramFile1 + "' exists but is a directory");
    }
    if (paramFile1.getCanonicalPath().equals(paramFile2.getCanonicalPath())) {
      throw new IOException("Source '" + paramFile1 + "' and destination '" + paramFile2 + "' are the same");
    }
    File localFile = paramFile2.getParentFile();
    if ((localFile != null) && (!localFile.mkdirs()) && (!localFile.isDirectory())) {
      throw new IOException("Destination '" + localFile + "' directory cannot be created");
    }
    if ((paramFile2.exists()) && (!paramFile2.canWrite())) {
      throw new IOException("Destination '" + paramFile2 + "' exists but is read-only");
    }
    a(paramFile1, paramFile2, paramBoolean);
  }
  
  @WorkerThread
  public static boolean ensureThatFoldersExists(File paramFile)
  {
    return (paramFile.exists()) || (paramFile.mkdirs());
  }
  
  public File copy(File paramFile)
  {
    if (this.d == null) {
      return paramFile;
    }
    File localFile = a(true);
    try
    {
      copyFile(paramFile, localFile);
      return localFile;
    }
    catch (IOException paramFile)
    {
      for (;;)
      {
        paramFile.printStackTrace();
        Crashlytics.logException(paramFile);
      }
    }
  }
  
  /* Error */
  public <T> T readGsonFromFile(String paramString, Class<T> paramClass)
  {
    // Byte code:
    //   0: aconst_null
    //   1: astore_3
    //   2: new 52	java/io/File
    //   5: dup
    //   6: aload_0
    //   7: getfield 24	com/bitstrips/imoji/util/FileUtil:b	Landroid/content/Context;
    //   10: invokevirtual 258	android/content/Context:getCacheDir	()Ljava/io/File;
    //   13: aload_1
    //   14: invokespecial 101	java/io/File:<init>	(Ljava/io/File;Ljava/lang/String;)V
    //   17: astore 4
    //   19: aload_3
    //   20: astore_1
    //   21: aload 4
    //   23: invokevirtual 105	java/io/File:exists	()Z
    //   26: ifeq +32 -> 58
    //   29: new 260	java/io/FileReader
    //   32: dup
    //   33: aload 4
    //   35: invokespecial 261	java/io/FileReader:<init>	(Ljava/io/File;)V
    //   38: astore_1
    //   39: new 263	com/google/gson/Gson
    //   42: dup
    //   43: invokespecial 264	com/google/gson/Gson:<init>	()V
    //   46: aload_1
    //   47: aload_2
    //   48: invokevirtual 268	com/google/gson/Gson:fromJson	(Ljava/io/Reader;Ljava/lang/Class;)Ljava/lang/Object;
    //   51: astore_2
    //   52: aload_1
    //   53: invokestatic 170	com/bitstrips/imoji/util/FileUtil:a	(Ljava/io/Closeable;)V
    //   56: aload_2
    //   57: astore_1
    //   58: aload_1
    //   59: areturn
    //   60: astore_1
    //   61: aconst_null
    //   62: astore_1
    //   63: aload_1
    //   64: invokestatic 170	com/bitstrips/imoji/util/FileUtil:a	(Ljava/io/Closeable;)V
    //   67: aconst_null
    //   68: areturn
    //   69: astore_1
    //   70: aconst_null
    //   71: astore_3
    //   72: aload_1
    //   73: astore_2
    //   74: aload_3
    //   75: invokestatic 170	com/bitstrips/imoji/util/FileUtil:a	(Ljava/io/Closeable;)V
    //   78: aload_2
    //   79: athrow
    //   80: astore_2
    //   81: aload_1
    //   82: astore_3
    //   83: goto -9 -> 74
    //   86: astore_2
    //   87: goto -24 -> 63
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	90	0	this	FileUtil
    //   0	90	1	paramString	String
    //   0	90	2	paramClass	Class<T>
    //   1	82	3	localObject	Object
    //   17	17	4	localFile	File
    // Exception table:
    //   from	to	target	type
    //   29	39	60	java/lang/Exception
    //   29	39	69	finally
    //   39	52	80	finally
    //   39	52	86	java/lang/Exception
  }
  
  /* Error */
  public void saveGsonToFile(String paramString, Object paramObject)
  {
    // Byte code:
    //   0: aconst_null
    //   1: astore_3
    //   2: new 52	java/io/File
    //   5: dup
    //   6: aload_0
    //   7: getfield 24	com/bitstrips/imoji/util/FileUtil:b	Landroid/content/Context;
    //   10: invokevirtual 258	android/content/Context:getCacheDir	()Ljava/io/File;
    //   13: aload_1
    //   14: invokespecial 101	java/io/File:<init>	(Ljava/io/File;Ljava/lang/String;)V
    //   17: astore_1
    //   18: aload_2
    //   19: ifnonnull +13 -> 32
    //   22: aload_1
    //   23: invokevirtual 127	java/io/File:delete	()Z
    //   26: pop
    //   27: aconst_null
    //   28: invokestatic 170	com/bitstrips/imoji/util/FileUtil:a	(Ljava/io/Closeable;)V
    //   31: return
    //   32: new 274	java/io/FileWriter
    //   35: dup
    //   36: aload_1
    //   37: iconst_0
    //   38: invokespecial 277	java/io/FileWriter:<init>	(Ljava/io/File;Z)V
    //   41: astore_1
    //   42: new 263	com/google/gson/Gson
    //   45: dup
    //   46: invokespecial 264	com/google/gson/Gson:<init>	()V
    //   49: aload_2
    //   50: aload_1
    //   51: invokevirtual 281	com/google/gson/Gson:toJson	(Ljava/lang/Object;Ljava/lang/Appendable;)V
    //   54: aload_1
    //   55: invokestatic 170	com/bitstrips/imoji/util/FileUtil:a	(Ljava/io/Closeable;)V
    //   58: return
    //   59: astore_1
    //   60: aload_3
    //   61: astore_1
    //   62: aload_1
    //   63: invokestatic 170	com/bitstrips/imoji/util/FileUtil:a	(Ljava/io/Closeable;)V
    //   66: return
    //   67: astore_1
    //   68: aconst_null
    //   69: astore_3
    //   70: aload_1
    //   71: astore_2
    //   72: aload_3
    //   73: invokestatic 170	com/bitstrips/imoji/util/FileUtil:a	(Ljava/io/Closeable;)V
    //   76: aload_2
    //   77: athrow
    //   78: astore_2
    //   79: aload_1
    //   80: astore_3
    //   81: goto -9 -> 72
    //   84: astore_2
    //   85: goto -23 -> 62
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	88	0	this	FileUtil
    //   0	88	1	paramString	String
    //   0	88	2	paramObject	Object
    //   1	80	3	localObject	Object
    // Exception table:
    //   from	to	target	type
    //   22	27	59	java/lang/Exception
    //   32	42	59	java/lang/Exception
    //   22	27	67	finally
    //   32	42	67	finally
    //   42	54	78	finally
    //   42	54	84	java/lang/Exception
  }
  
  public String saveImoji(String paramString)
  {
    try
    {
      File localFile = a(false);
      copyFile(new File(paramString), localFile);
      paramString = localFile.getAbsolutePath();
      return paramString;
    }
    catch (IOException paramString) {}
    return null;
  }
}


/* Location:              /home/merong/decompile/hackery-dex2jar.jar!/com/bitstrips/imoji/util/FileUtil.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       0.7.1
 */