MCPcopy Create free account
hub / github.com/M66B/FairEmail / _encode

Method _encode

app/src/main/java/javax/mail/URLName.java:575–618  ·  view source on GitHub ↗
(String s)

Source from the content-addressed store, hash-verified

573 }
574
575 private static String _encode(String s) {
576 int maxBytesPerChar = 10;
577 StringBuilder out = new StringBuilder(s.length());
578 ByteArrayOutputStream buf = new ByteArrayOutputStream(maxBytesPerChar);
579 OutputStreamWriter writer = new OutputStreamWriter(buf);
580
581 for (int i = 0; i < s.length(); i++) {
582 int c = (int)s.charAt(i);
583 if (dontNeedEncoding.get(c)) {
584 if (c == ' ') {
585 c = '+';
586 }
587 out.append((char)c);
588 } else {
589 // convert to external encoding before hex conversion
590 try {
591 writer.write(c);
592 writer.flush();
593 } catch(IOException e) {
594 buf.reset();
595 continue;
596 }
597 byte[] ba = buf.toByteArray();
598 for (int j = 0; j < ba.length; j++) {
599 out.append('%');
600 char ch = Character.forDigit((ba[j] >> 4) & 0xF, 16);
601 // converting to use uppercase letter as part of
602 // the hex value if ch is a letter.
603 if (Character.isLetter(ch)) {
604 ch -= caseDiff;
605 }
606 out.append(ch);
607 ch = Character.forDigit(ba[j] & 0xF, 16);
608 if (Character.isLetter(ch)) {
609 ch -= caseDiff;
610 }
611 out.append(ch);
612 }
613 buf.reset();
614 }
615 }
616
617 return out.toString();
618 }
619
620
621 /**

Callers 1

encodeMethod · 0.95

Calls 8

charAtMethod · 0.80
resetMethod · 0.65
lengthMethod · 0.45
getMethod · 0.45
appendMethod · 0.45
writeMethod · 0.45
flushMethod · 0.45
toStringMethod · 0.45

Tested by

no test coverage detected