ByteSource.java 14.2 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 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580
package com.google.common.io;

import com.google.common.annotations.Beta;
import com.google.common.base.Ascii;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.hash.Funnels;
import com.google.common.hash.HashCode;
import com.google.common.hash.HashFunction;
import com.google.common.hash.Hasher;
import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.Reader;
import java.nio.charset.Charset;
import java.util.Arrays;
import java.util.Iterator;
import re;

public abstract class ByteSource
{
  private static final byte[] a = new byte['က'];
  
  private static long a(InputStream paramInputStream)
    throws IOException
  {
    long l2;
    for (long l1 = 0L;; l1 += l2)
    {
      l2 = paramInputStream.read(a);
      if (l2 == -1L) {
        break;
      }
    }
    return l1;
  }
  
  public static ByteSource concat(Iterable<? extends ByteSource> paramIterable)
  {
    return new c(paramIterable);
  }
  
  public static ByteSource concat(Iterator<? extends ByteSource> paramIterator)
  {
    return concat(ImmutableList.copyOf(paramIterator));
  }
  
  public static ByteSource concat(ByteSource... paramVarArgs)
  {
    return concat(ImmutableList.copyOf(paramVarArgs));
  }
  
  public static ByteSource empty()
  {
    return d.a();
  }
  
  public static ByteSource wrap(byte[] paramArrayOfByte)
  {
    return new b(paramArrayOfByte);
  }
  
  public CharSource asCharSource(Charset paramCharset)
  {
    return new a(paramCharset, (byte)0);
  }
  
  public boolean contentEquals(ByteSource paramByteSource)
    throws IOException
  {
    Preconditions.checkNotNull(paramByteSource);
    byte[] arrayOfByte1 = new byte['က'];
    byte[] arrayOfByte2 = new byte['က'];
    Closer localCloser = Closer.create();
    try
    {
      InputStream localInputStream = (InputStream)localCloser.register(openStream());
      paramByteSource = (InputStream)localCloser.register(paramByteSource.openStream());
      int i;
      do
      {
        i = ByteStreams.read(localInputStream, arrayOfByte1, 0, 4096);
        if (i == ByteStreams.read(paramByteSource, arrayOfByte2, 0, 4096))
        {
          boolean bool = Arrays.equals(arrayOfByte1, arrayOfByte2);
          if (bool) {}
        }
        else
        {
          return false;
        }
      } while (i == 4096);
      return true;
    }
    catch (Throwable paramByteSource)
    {
      throw localCloser.rethrow(paramByteSource);
    }
    finally
    {
      localCloser.close();
    }
  }
  
  public long copyTo(ByteSink paramByteSink)
    throws IOException
  {
    Preconditions.checkNotNull(paramByteSink);
    Closer localCloser = Closer.create();
    try
    {
      long l = ByteStreams.copy((InputStream)localCloser.register(openStream()), (OutputStream)localCloser.register(paramByteSink.openStream()));
      return l;
    }
    catch (Throwable paramByteSink)
    {
      throw localCloser.rethrow(paramByteSink);
    }
    finally
    {
      localCloser.close();
    }
  }
  
  public long copyTo(OutputStream paramOutputStream)
    throws IOException
  {
    Preconditions.checkNotNull(paramOutputStream);
    Closer localCloser = Closer.create();
    try
    {
      long l = ByteStreams.copy((InputStream)localCloser.register(openStream()), paramOutputStream);
      return l;
    }
    catch (Throwable paramOutputStream)
    {
      throw localCloser.rethrow(paramOutputStream);
    }
    finally
    {
      localCloser.close();
    }
  }
  
  public HashCode hash(HashFunction paramHashFunction)
    throws IOException
  {
    paramHashFunction = paramHashFunction.newHasher();
    copyTo(Funnels.asOutputStream(paramHashFunction));
    return paramHashFunction.hash();
  }
  
  /* Error */
  public boolean isEmpty()
    throws IOException
  {
    // Byte code:
    //   0: invokestatic 92	com/google/common/io/Closer:create	()Lcom/google/common/io/Closer;
    //   3: astore_3
    //   4: aload_3
    //   5: aload_0
    //   6: invokevirtual 96	com/google/common/io/ByteSource:openStream	()Ljava/io/InputStream;
    //   9: invokevirtual 100	com/google/common/io/Closer:register	(Ljava/io/Closeable;)Ljava/io/Closeable;
    //   12: checkcast 33	java/io/InputStream
    //   15: invokevirtual 158	java/io/InputStream:read	()I
    //   18: istore_1
    //   19: iload_1
    //   20: iconst_m1
    //   21: if_icmpne +11 -> 32
    //   24: iconst_1
    //   25: istore_2
    //   26: aload_3
    //   27: invokevirtual 114	com/google/common/io/Closer:close	()V
    //   30: iload_2
    //   31: ireturn
    //   32: iconst_0
    //   33: istore_2
    //   34: goto -8 -> 26
    //   37: astore 4
    //   39: aload_3
    //   40: aload 4
    //   42: invokevirtual 118	com/google/common/io/Closer:rethrow	(Ljava/lang/Throwable;)Ljava/lang/RuntimeException;
    //   45: athrow
    //   46: astore 4
    //   48: aload_3
    //   49: invokevirtual 114	com/google/common/io/Closer:close	()V
    //   52: aload 4
    //   54: athrow
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	55	0	this	ByteSource
    //   18	4	1	i	int
    //   25	9	2	bool	boolean
    //   3	46	3	localCloser	Closer
    //   37	4	4	localThrowable	Throwable
    //   46	7	4	localObject	Object
    // Exception table:
    //   from	to	target	type
    //   4	19	37	java/lang/Throwable
    //   4	19	46	finally
    //   39	46	46	finally
  }
  
  public InputStream openBufferedStream()
    throws IOException
  {
    InputStream localInputStream = openStream();
    if ((localInputStream instanceof BufferedInputStream)) {
      return (BufferedInputStream)localInputStream;
    }
    return new BufferedInputStream(localInputStream);
  }
  
  public abstract InputStream openStream()
    throws IOException;
  
  @Beta
  public <T> T read(ByteProcessor<T> paramByteProcessor)
    throws IOException
  {
    Preconditions.checkNotNull(paramByteProcessor);
    Closer localCloser = Closer.create();
    try
    {
      paramByteProcessor = ByteStreams.readBytes((InputStream)localCloser.register(openStream()), paramByteProcessor);
      return paramByteProcessor;
    }
    catch (Throwable paramByteProcessor)
    {
      throw localCloser.rethrow(paramByteProcessor);
    }
    finally
    {
      localCloser.close();
    }
  }
  
  public byte[] read()
    throws IOException
  {
    Closer localCloser = Closer.create();
    try
    {
      byte[] arrayOfByte = ByteStreams.toByteArray((InputStream)localCloser.register(openStream()));
      return arrayOfByte;
    }
    catch (Throwable localThrowable)
    {
      throw localCloser.rethrow(localThrowable);
    }
    finally
    {
      localCloser.close();
    }
  }
  
  public long size()
    throws IOException
  {
    localCloser = Closer.create();
    try
    {
      localInputStream = (InputStream)localCloser.register(openStream());
      l1 = 0L;
    }
    catch (IOException localIOException)
    {
      for (;;)
      {
        InputStream localInputStream;
        long l1;
        long l2;
        int i;
        localCloser.close();
        localCloser = Closer.create();
        try
        {
          l1 = a((InputStream)localCloser.register(openStream()));
          return l1;
        }
        catch (Throwable localThrowable)
        {
          throw localCloser.rethrow(localThrowable);
        }
        finally {}
        l1 += 1L;
        continue;
        l1 += l2;
      }
    }
    finally
    {
      localCloser.close();
    }
    l2 = localInputStream.skip(Math.min(localInputStream.available(), Integer.MAX_VALUE));
    if (l2 <= 0L)
    {
      i = localInputStream.read();
      if (i == -1)
      {
        localCloser.close();
        return l1;
      }
      if ((l1 == 0L) && (localInputStream.available() == 0)) {
        throw new IOException();
      }
    }
  }
  
  public ByteSource slice(long paramLong1, long paramLong2)
  {
    return new e(paramLong1, paramLong2, (byte)0);
  }
  
  final class a
    extends CharSource
  {
    private final Charset b;
    
    private a(Charset paramCharset)
    {
      this.b = ((Charset)Preconditions.checkNotNull(paramCharset));
    }
    
    public final Reader openStream()
      throws IOException
    {
      return new InputStreamReader(ByteSource.this.openStream(), this.b);
    }
    
    public final String toString()
    {
      String str1 = String.valueOf(String.valueOf(ByteSource.this.toString()));
      String str2 = String.valueOf(String.valueOf(this.b));
      return str1.length() + 15 + str2.length() + str1 + ".asCharSource(" + str2 + ")";
    }
  }
  
  static class b
    extends ByteSource
  {
    protected final byte[] a;
    
    protected b(byte[] paramArrayOfByte)
    {
      this.a = ((byte[])Preconditions.checkNotNull(paramArrayOfByte));
    }
    
    public long copyTo(OutputStream paramOutputStream)
      throws IOException
    {
      paramOutputStream.write(this.a);
      return this.a.length;
    }
    
    public HashCode hash(HashFunction paramHashFunction)
      throws IOException
    {
      return paramHashFunction.hashBytes(this.a);
    }
    
    public boolean isEmpty()
    {
      return this.a.length == 0;
    }
    
    public InputStream openBufferedStream()
      throws IOException
    {
      return openStream();
    }
    
    public InputStream openStream()
    {
      return new ByteArrayInputStream(this.a);
    }
    
    public <T> T read(ByteProcessor<T> paramByteProcessor)
      throws IOException
    {
      paramByteProcessor.processBytes(this.a, 0, this.a.length);
      return (T)paramByteProcessor.getResult();
    }
    
    public byte[] read()
    {
      return (byte[])this.a.clone();
    }
    
    public long size()
    {
      return this.a.length;
    }
    
    public String toString()
    {
      String str = String.valueOf(String.valueOf(Ascii.truncate(BaseEncoding.base16().encode(this.a), 30, "...")));
      return str.length() + 17 + "ByteSource.wrap(" + str + ")";
    }
  }
  
  static final class c
    extends ByteSource
  {
    private final Iterable<? extends ByteSource> a;
    
    c(Iterable<? extends ByteSource> paramIterable)
    {
      this.a = ((Iterable)Preconditions.checkNotNull(paramIterable));
    }
    
    public final boolean isEmpty()
      throws IOException
    {
      Iterator localIterator = this.a.iterator();
      while (localIterator.hasNext()) {
        if (!((ByteSource)localIterator.next()).isEmpty()) {
          return false;
        }
      }
      return true;
    }
    
    public final InputStream openStream()
      throws IOException
    {
      return new re(this.a.iterator());
    }
    
    public final long size()
      throws IOException
    {
      Iterator localIterator = this.a.iterator();
      for (long l = 0L; localIterator.hasNext(); l = ((ByteSource)localIterator.next()).size() + l) {}
      return l;
    }
    
    public final String toString()
    {
      String str = String.valueOf(String.valueOf(this.a));
      return str.length() + 19 + "ByteSource.concat(" + str + ")";
    }
  }
  
  static final class d
    extends ByteSource.b
  {
    private static final d b = new d();
    
    private d()
    {
      super();
    }
    
    public final CharSource asCharSource(Charset paramCharset)
    {
      Preconditions.checkNotNull(paramCharset);
      return CharSource.empty();
    }
    
    public final byte[] read()
    {
      return this.a;
    }
    
    public final String toString()
    {
      return "ByteSource.empty()";
    }
  }
  
  final class e
    extends ByteSource
  {
    private final long b;
    private final long c;
    
    private e(long paramLong1, long paramLong2)
    {
      if (paramLong1 >= 0L)
      {
        bool = true;
        Preconditions.checkArgument(bool, "offset (%s) may not be negative", new Object[] { Long.valueOf(paramLong1) });
        if (paramLong2 < 0L) {
          break label83;
        }
      }
      label83:
      for (boolean bool = true;; bool = false)
      {
        Preconditions.checkArgument(bool, "length (%s) may not be negative", new Object[] { Long.valueOf(paramLong2) });
        this.b = paramLong1;
        this.c = paramLong2;
        return;
        bool = false;
        break;
      }
    }
    
    private InputStream a(InputStream paramInputStream)
      throws IOException
    {
      if (this.b > 0L) {}
      try
      {
        ByteStreams.skipFully(paramInputStream, this.b);
        return ByteStreams.limit(paramInputStream, this.c);
      }
      catch (Throwable localThrowable)
      {
        Closer localCloser = Closer.create();
        localCloser.register(paramInputStream);
        try
        {
          throw localCloser.rethrow(localThrowable);
        }
        finally
        {
          localCloser.close();
        }
      }
    }
    
    public final boolean isEmpty()
      throws IOException
    {
      return (this.c == 0L) || (super.isEmpty());
    }
    
    public final InputStream openBufferedStream()
      throws IOException
    {
      return a(ByteSource.this.openBufferedStream());
    }
    
    public final InputStream openStream()
      throws IOException
    {
      return a(ByteSource.this.openStream());
    }
    
    public final ByteSource slice(long paramLong1, long paramLong2)
    {
      if (paramLong1 >= 0L)
      {
        bool = true;
        Preconditions.checkArgument(bool, "offset (%s) may not be negative", new Object[] { Long.valueOf(paramLong1) });
        if (paramLong2 < 0L) {
          break label88;
        }
      }
      label88:
      for (boolean bool = true;; bool = false)
      {
        Preconditions.checkArgument(bool, "length (%s) may not be negative", new Object[] { Long.valueOf(paramLong2) });
        long l = this.c;
        return ByteSource.this.slice(this.b + paramLong1, Math.min(paramLong2, l - paramLong1));
        bool = false;
        break;
      }
    }
    
    public final String toString()
    {
      String str = String.valueOf(String.valueOf(ByteSource.this.toString()));
      long l1 = this.b;
      long l2 = this.c;
      return str.length() + 50 + str + ".slice(" + l1 + ", " + l2 + ")";
    }
  }
}


/* Location:              /home/merong/decompile/hackery-dex2jar.jar!/com/google/common/io/ByteSource.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       0.7.1
 */