| 536 | } |
| 537 | |
| 538 | /* package */ static class Encoder extends Coder { |
| 539 | /** |
| 540 | * Emit a new line every this many output tuples. Corresponds to |
| 541 | * a 76-character line length (the maximum allowable according to |
| 542 | * <a href="http://www.ietf.org/rfc/rfc2045.txt">RFC 2045</a>). |
| 543 | */ |
| 544 | public static final int LINE_GROUPS = 19; |
| 545 | |
| 546 | /** |
| 547 | * Lookup table for turning Base64 alphabet positions (6 bits) |
| 548 | * into output bytes. |
| 549 | */ |
| 550 | private static final byte ENCODE[] = { |
| 551 | 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', |
| 552 | 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', |
| 553 | 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', |
| 554 | 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/', |
| 555 | }; |
| 556 | |
| 557 | /** |
| 558 | * Lookup table for turning Base64 alphabet positions (6 bits) |
| 559 | * into output bytes. |
| 560 | */ |
| 561 | private static final byte ENCODE_WEBSAFE[] = { |
| 562 | 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', |
| 563 | 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', |
| 564 | 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', |
| 565 | 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '-', '_', |
| 566 | }; |
| 567 | |
| 568 | final private byte[] tail; |
| 569 | /* package */ int tailLen; |
| 570 | private int count; |
| 571 | |
| 572 | final public boolean do_padding; |
| 573 | final public boolean do_newline; |
| 574 | final public boolean do_cr; |
| 575 | final private byte[] alphabet; |
| 576 | |
| 577 | public Encoder(int flags, byte[] output) { |
| 578 | this.output = output; |
| 579 | |
| 580 | do_padding = (flags & NO_PADDING) == 0; |
| 581 | do_newline = (flags & NO_WRAP) == 0; |
| 582 | do_cr = (flags & CRLF) != 0; |
| 583 | alphabet = ((flags & URL_SAFE) == 0) ? ENCODE : ENCODE_WEBSAFE; |
| 584 | |
| 585 | tail = new byte[2]; |
| 586 | tailLen = 0; |
| 587 | |
| 588 | count = do_newline ? LINE_GROUPS : -1; |
| 589 | } |
| 590 | |
| 591 | /** |
| 592 | * @return an overestimate for the number of bytes {@code |
| 593 | * len} bytes could encode to. |
| 594 | */ |
| 595 | public int maxOutputSize(int len) { |
nothing calls this directly
no outgoing calls
no test coverage detected