BaseEncoding.java
20.3 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
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
package com.google.common.io;
import com.google.common.annotations.Beta;
import com.google.common.annotations.GwtCompatible;
import com.google.common.annotations.GwtIncompatible;
import com.google.common.base.Ascii;
import com.google.common.base.CharMatcher;
import com.google.common.base.Preconditions;
import com.google.common.math.IntMath;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Reader;
import java.io.Writer;
import java.math.RoundingMode;
import java.util.Arrays;
import javax.annotation.CheckReturnValue;
import javax.annotation.Nullable;
import rc.1;
import rc.2;
import rc.3;
import rc.4;
import rc.5;
import rc.6;
import rc.a;
import rc.b;
import rc.c;
import rc.d;
@Beta
@GwtCompatible(emulated=true)
public abstract class BaseEncoding
{
private static final BaseEncoding a = new c("base64()", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", Character.valueOf('='));
private static final BaseEncoding b = new c("base64Url()", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_", Character.valueOf('='));
private static final BaseEncoding c = new c("base32()", "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567", Character.valueOf('='));
private static final BaseEncoding d = new c("base32Hex()", "0123456789ABCDEFGHIJKLMNOPQRSTUV", Character.valueOf('='));
private static final BaseEncoding e = new c("base16()", "0123456789ABCDEF", null);
private byte[] a(CharSequence paramCharSequence)
throws BaseEncoding.DecodingException
{
Object localObject = a().trimTrailingFrom(paramCharSequence);
Preconditions.checkNotNull(localObject);
paramCharSequence = a(new rc.2((CharSequence)localObject));
localObject = new byte[b(((CharSequence)localObject).length())];
int i;
try
{
int j = paramCharSequence.a();
i = 0;
while (j != -1)
{
localObject[i] = ((byte)j);
j = paramCharSequence.a();
i += 1;
}
if (i != localObject.length) {
break label102;
}
}
catch (DecodingException paramCharSequence)
{
throw paramCharSequence;
}
catch (IOException paramCharSequence)
{
throw new AssertionError(paramCharSequence);
}
return (byte[])localObject;
label102:
paramCharSequence = new byte[i];
System.arraycopy(localObject, 0, paramCharSequence, 0, i);
return paramCharSequence;
}
public static BaseEncoding base16()
{
return e;
}
public static BaseEncoding base32()
{
return c;
}
public static BaseEncoding base32Hex()
{
return d;
}
public static BaseEncoding base64()
{
return a;
}
public static BaseEncoding base64Url()
{
return b;
}
abstract int a(int paramInt);
abstract CharMatcher a();
abstract rc.a a(rc.c paramc);
abstract rc.b a(rc.d paramd);
abstract int b(int paramInt);
public final byte[] decode(CharSequence paramCharSequence)
{
try
{
paramCharSequence = a(paramCharSequence);
return paramCharSequence;
}
catch (DecodingException paramCharSequence)
{
throw new IllegalArgumentException(paramCharSequence);
}
}
@GwtIncompatible("ByteSource,CharSource")
public final ByteSource decodingSource(final CharSource paramCharSource)
{
Preconditions.checkNotNull(paramCharSource);
new ByteSource()
{
public final InputStream openStream()
throws IOException
{
return BaseEncoding.this.decodingStream(paramCharSource.openStream());
}
};
}
@GwtIncompatible("Reader,InputStream")
public final InputStream decodingStream(Reader paramReader)
{
Preconditions.checkNotNull(paramReader);
paramReader = a(new rc.1(paramReader));
Preconditions.checkNotNull(paramReader);
return new rc.3(paramReader);
}
public String encode(byte[] paramArrayOfByte)
{
return encode((byte[])Preconditions.checkNotNull(paramArrayOfByte), 0, paramArrayOfByte.length);
}
public final String encode(byte[] paramArrayOfByte, int paramInt1, int paramInt2)
{
Preconditions.checkNotNull(paramArrayOfByte);
Preconditions.checkPositionIndexes(paramInt1, paramInt1 + paramInt2, paramArrayOfByte.length);
rc.6 local6 = new rc.6(new StringBuilder(a(paramInt2)));
rc.b localb = a(local6);
int i = 0;
for (;;)
{
if (i < paramInt2) {}
try
{
localb.a(paramArrayOfByte[(paramInt1 + i)]);
i += 1;
}
catch (IOException paramArrayOfByte)
{
throw new AssertionError("impossible");
}
}
localb.b();
return local6.toString();
}
@GwtIncompatible("ByteSink,CharSink")
public final ByteSink encodingSink(final CharSink paramCharSink)
{
Preconditions.checkNotNull(paramCharSink);
new ByteSink()
{
public final OutputStream openStream()
throws IOException
{
return BaseEncoding.this.encodingStream(paramCharSink.openStream());
}
};
}
@GwtIncompatible("Writer,OutputStream")
public final OutputStream encodingStream(Writer paramWriter)
{
Preconditions.checkNotNull(paramWriter);
paramWriter = a(new rc.5(paramWriter));
Preconditions.checkNotNull(paramWriter);
return new rc.4(paramWriter);
}
@CheckReturnValue
public abstract BaseEncoding lowerCase();
@CheckReturnValue
public abstract BaseEncoding omitPadding();
@CheckReturnValue
public abstract BaseEncoding upperCase();
@CheckReturnValue
public abstract BaseEncoding withPadChar(char paramChar);
@CheckReturnValue
public abstract BaseEncoding withSeparator(String paramString, int paramInt);
public static final class DecodingException
extends IOException
{
DecodingException(String paramString)
{
super();
}
}
static final class a
extends CharMatcher
{
final String c;
final char[] d;
final int e;
final int f;
final int g;
final int h;
final byte[] i;
private final boolean[] j;
a(String paramString, char[] paramArrayOfChar)
{
this.c = ((String)Preconditions.checkNotNull(paramString));
this.d = ((char[])Preconditions.checkNotNull(paramArrayOfChar));
for (;;)
{
try
{
this.f = IntMath.log2(paramArrayOfChar.length, RoundingMode.UNNECESSARY);
k = Math.min(8, Integer.lowestOneBit(this.f));
this.g = (8 / k);
this.h = (this.f / k);
this.e = (paramArrayOfChar.length - 1);
paramString = new byte[''];
Arrays.fill(paramString, (byte)-1);
k = 0;
if (k >= paramArrayOfChar.length) {
break;
}
char c1 = paramArrayOfChar[k];
Preconditions.checkArgument(CharMatcher.ASCII.matches(c1), "Non-ASCII character: %s", new Object[] { Character.valueOf(c1) });
boolean bool;
if (paramString[c1] == -1)
{
bool = true;
Preconditions.checkArgument(bool, "Duplicate character: %s", new Object[] { Character.valueOf(c1) });
paramString[c1] = ((byte)k);
k += 1;
}
else
{
bool = false;
}
}
catch (ArithmeticException paramString)
{
k = paramArrayOfChar.length;
throw new IllegalArgumentException(35 + "Illegal alphabet length " + k, paramString);
}
}
this.i = paramString;
paramString = new boolean[this.g];
int k = m;
while (k < this.h)
{
paramString[IntMath.divide(k * 8, this.f, RoundingMode.CEILING)] = 1;
k += 1;
}
this.j = paramString;
}
final boolean a()
{
boolean bool2 = false;
char[] arrayOfChar = this.d;
int m = arrayOfChar.length;
int k = 0;
for (;;)
{
boolean bool1 = bool2;
if (k < m)
{
if (Ascii.isLowerCase(arrayOfChar[k])) {
bool1 = true;
}
}
else {
return bool1;
}
k += 1;
}
}
final boolean a(int paramInt)
{
return this.j[(paramInt % this.g)];
}
final boolean b()
{
boolean bool2 = false;
char[] arrayOfChar = this.d;
int m = arrayOfChar.length;
int k = 0;
for (;;)
{
boolean bool1 = bool2;
if (k < m)
{
if (Ascii.isUpperCase(arrayOfChar[k])) {
bool1 = true;
}
}
else {
return bool1;
}
k += 1;
}
}
public final boolean matches(char paramChar)
{
return (CharMatcher.ASCII.matches(paramChar)) && (this.i[paramChar] != -1);
}
public final String toString()
{
return this.c;
}
}
static final class b
extends BaseEncoding
{
private final BaseEncoding a;
private final String b;
private final int c;
private final CharMatcher d;
b(BaseEncoding paramBaseEncoding, String paramString, int paramInt)
{
this.a = ((BaseEncoding)Preconditions.checkNotNull(paramBaseEncoding));
this.b = ((String)Preconditions.checkNotNull(paramString));
this.c = paramInt;
if (paramInt > 0) {}
for (boolean bool = true;; bool = false)
{
Preconditions.checkArgument(bool, "Cannot add a separator after every %s chars", new Object[] { Integer.valueOf(paramInt) });
this.d = CharMatcher.anyOf(paramString).precomputed();
return;
}
}
final int a(int paramInt)
{
paramInt = this.a.a(paramInt);
return paramInt + this.b.length() * IntMath.divide(Math.max(0, paramInt - 1), this.c, RoundingMode.FLOOR);
}
final CharMatcher a()
{
return this.a.a();
}
final rc.a a(rc.c paramc)
{
BaseEncoding localBaseEncoding = this.a;
CharMatcher localCharMatcher = this.d;
Preconditions.checkNotNull(paramc);
Preconditions.checkNotNull(localCharMatcher);
return localBaseEncoding.a(new BaseEncoding.3(paramc, localCharMatcher));
}
final rc.b a(rc.d paramd)
{
BaseEncoding localBaseEncoding = this.a;
String str = this.b;
int i = this.c;
Preconditions.checkNotNull(paramd);
Preconditions.checkNotNull(str);
if (i > 0) {}
for (boolean bool = true;; bool = false)
{
Preconditions.checkArgument(bool);
return localBaseEncoding.a(new BaseEncoding.4(i, str, paramd));
}
}
final int b(int paramInt)
{
return this.a.b(paramInt);
}
public final BaseEncoding lowerCase()
{
return this.a.lowerCase().withSeparator(this.b, this.c);
}
public final BaseEncoding omitPadding()
{
return this.a.omitPadding().withSeparator(this.b, this.c);
}
public final String toString()
{
String str1 = String.valueOf(String.valueOf(this.a.toString()));
String str2 = String.valueOf(String.valueOf(this.b));
int i = this.c;
return str1.length() + 31 + str2.length() + str1 + ".withSeparator(\"" + str2 + "\", " + i + ")";
}
public final BaseEncoding upperCase()
{
return this.a.upperCase().withSeparator(this.b, this.c);
}
public final BaseEncoding withPadChar(char paramChar)
{
return this.a.withPadChar(paramChar).withSeparator(this.b, this.c);
}
public final BaseEncoding withSeparator(String paramString, int paramInt)
{
throw new UnsupportedOperationException("Already have a separator");
}
}
static final class c
extends BaseEncoding
{
private final BaseEncoding.a a;
@Nullable
private final Character b;
private transient BaseEncoding c;
private transient BaseEncoding d;
private c(BaseEncoding.a parama, @Nullable Character paramCharacter)
{
this.a = ((BaseEncoding.a)Preconditions.checkNotNull(parama));
if ((paramCharacter == null) || (!parama.matches(paramCharacter.charValue()))) {}
for (boolean bool = true;; bool = false)
{
Preconditions.checkArgument(bool, "Padding character %s was already in alphabet", new Object[] { paramCharacter });
this.b = paramCharacter;
return;
}
}
c(String paramString1, String paramString2, @Nullable Character paramCharacter)
{
this(new BaseEncoding.a(paramString1, paramString2.toCharArray()), paramCharacter);
}
final int a(int paramInt)
{
return this.a.g * IntMath.divide(paramInt, this.a.h, RoundingMode.CEILING);
}
final CharMatcher a()
{
if (this.b == null) {
return CharMatcher.NONE;
}
return CharMatcher.is(this.b.charValue());
}
final rc.a a(final rc.c paramc)
{
Preconditions.checkNotNull(paramc);
new rc.a()
{
int a = 0;
int b = 0;
int c = 0;
boolean d = false;
final CharMatcher e = BaseEncoding.c.this.a();
public final int a()
throws IOException
{
int j = -1;
do
{
char c1;
for (;;)
{
i = paramc.a();
if (i == -1)
{
i = j;
if (this.d) {
return i;
}
i = j;
if (BaseEncoding.c.a(BaseEncoding.c.this).a(this.c)) {
return i;
}
i = this.c;
throw new BaseEncoding.DecodingException(32 + "Invalid input length " + i);
}
this.c += 1;
c1 = (char)i;
if (!this.e.matches(c1)) {
break;
}
if ((!this.d) && ((this.c == 1) || (!BaseEncoding.c.a(BaseEncoding.c.this).a(this.c - 1))))
{
i = this.c;
throw new BaseEncoding.DecodingException(41 + "Padding cannot start at index " + i);
}
this.d = true;
}
if (this.d)
{
i = this.c;
throw new BaseEncoding.DecodingException(61 + "Expected padding character but found '" + c1 + "' at index " + i);
}
this.a <<= BaseEncoding.c.a(BaseEncoding.c.this).f;
i = this.a;
BaseEncoding.a locala = BaseEncoding.c.a(BaseEncoding.c.this);
if ((c1 > '') || (locala.i[c1] == -1)) {
throw new BaseEncoding.DecodingException(25 + "Unrecognized character: " + c1);
}
this.a = (locala.i[c1] | i);
this.b += BaseEncoding.c.a(BaseEncoding.c.this).f;
} while (this.b < 8);
this.b -= 8;
int i = this.a >> this.b & 0xFF;
return i;
}
public final void b()
throws IOException
{
paramc.b();
}
};
}
final rc.b a(final rc.d paramd)
{
Preconditions.checkNotNull(paramd);
new rc.b()
{
int a = 0;
int b = 0;
int c = 0;
public final void a()
throws IOException
{
paramd.a();
}
public final void a(byte paramAnonymousByte)
throws IOException
{
this.a <<= 8;
this.a |= paramAnonymousByte & 0xFF;
for (this.b += 8; this.b >= BaseEncoding.c.a(BaseEncoding.c.this).f; this.b -= BaseEncoding.c.a(BaseEncoding.c.this).f)
{
paramAnonymousByte = this.a;
int i = this.b;
int j = BaseEncoding.c.a(BaseEncoding.c.this).f;
int k = BaseEncoding.c.a(BaseEncoding.c.this).e;
paramd.a(BaseEncoding.c.a(BaseEncoding.c.this).d[(paramAnonymousByte >> i - j & k)]);
this.c += 1;
}
}
public final void b()
throws IOException
{
if (this.b > 0)
{
int i = this.a;
int j = BaseEncoding.c.a(BaseEncoding.c.this).f;
int k = this.b;
int m = BaseEncoding.c.a(BaseEncoding.c.this).e;
paramd.a(BaseEncoding.c.a(BaseEncoding.c.this).d[(i << j - k & m)]);
this.c += 1;
if (BaseEncoding.c.b(BaseEncoding.c.this) != null) {
while (this.c % BaseEncoding.c.a(BaseEncoding.c.this).g != 0)
{
paramd.a(BaseEncoding.c.b(BaseEncoding.c.this).charValue());
this.c += 1;
}
}
}
paramd.b();
}
};
}
final int b(int paramInt)
{
return (int)((this.a.f * paramInt + 7L) / 8L);
}
public final BaseEncoding lowerCase()
{
int i = 0;
Object localObject2 = this.d;
Object localObject1 = localObject2;
if (localObject2 == null)
{
localObject1 = this.a;
if (((BaseEncoding.a)localObject1).b()) {
break label45;
}
if (localObject1 != this.a) {
break label128;
}
}
label45:
label128:
for (localObject1 = this;; localObject1 = new c((BaseEncoding.a)localObject1, this.b))
{
this.d = ((BaseEncoding)localObject1);
return (BaseEncoding)localObject1;
if (!((BaseEncoding.a)localObject1).a()) {}
for (boolean bool = true;; bool = false)
{
Preconditions.checkState(bool, "Cannot call lowerCase() on a mixed-case alphabet");
localObject2 = new char[((BaseEncoding.a)localObject1).d.length];
while (i < ((BaseEncoding.a)localObject1).d.length)
{
localObject2[i] = Ascii.toLowerCase(localObject1.d[i]);
i += 1;
}
}
localObject1 = new BaseEncoding.a(String.valueOf(((BaseEncoding.a)localObject1).c).concat(".lowerCase()"), (char[])localObject2);
break;
}
}
public final BaseEncoding omitPadding()
{
if (this.b == null) {
return this;
}
return new c(this.a, null);
}
public final String toString()
{
StringBuilder localStringBuilder = new StringBuilder("BaseEncoding.");
localStringBuilder.append(this.a.toString());
if (8 % this.a.f != 0)
{
if (this.b != null) {
break label54;
}
localStringBuilder.append(".omitPadding()");
}
for (;;)
{
return localStringBuilder.toString();
label54:
localStringBuilder.append(".withPadChar(").append(this.b).append(')');
}
}
public final BaseEncoding upperCase()
{
int i = 0;
Object localObject2 = this.c;
Object localObject1 = localObject2;
if (localObject2 == null)
{
localObject1 = this.a;
if (((BaseEncoding.a)localObject1).a()) {
break label45;
}
if (localObject1 != this.a) {
break label128;
}
}
label45:
label128:
for (localObject1 = this;; localObject1 = new c((BaseEncoding.a)localObject1, this.b))
{
this.c = ((BaseEncoding)localObject1);
return (BaseEncoding)localObject1;
if (!((BaseEncoding.a)localObject1).b()) {}
for (boolean bool = true;; bool = false)
{
Preconditions.checkState(bool, "Cannot call upperCase() on a mixed-case alphabet");
localObject2 = new char[((BaseEncoding.a)localObject1).d.length];
while (i < ((BaseEncoding.a)localObject1).d.length)
{
localObject2[i] = Ascii.toUpperCase(localObject1.d[i]);
i += 1;
}
}
localObject1 = new BaseEncoding.a(String.valueOf(((BaseEncoding.a)localObject1).c).concat(".upperCase()"), (char[])localObject2);
break;
}
}
public final BaseEncoding withPadChar(char paramChar)
{
if ((8 % this.a.f == 0) || ((this.b != null) && (this.b.charValue() == paramChar))) {
return this;
}
return new c(this.a, Character.valueOf(paramChar));
}
public final BaseEncoding withSeparator(String paramString, int paramInt)
{
Preconditions.checkNotNull(paramString);
Preconditions.checkArgument(a().or(this.a).matchesNoneOf(paramString), "Separator cannot contain alphabet or padding characters");
return new BaseEncoding.b(this, paramString, paramInt);
}
}
}
/* Location: /home/merong/decompile/hackery-dex2jar.jar!/com/google/common/io/BaseEncoding.class
* Java compiler version: 6 (50.0)
* JD-Core Version: 0.7.1
*/