@Override String getInitialResponse(String host, String authzid, String user, String passwd) throws MessagingException, IOException { // return "authzid<NUL>user<NUL>passwd" ByteArrayOutputStream bos = new ByteArrayOutputStream(); OutputStream b64os = new BASE64EncoderStream(bos, Integer.MAX_VALUE); if (authzid != null) b64os.write(authzid.getBytes(StandardCharsets.UTF_8)); b64os.write(0); b64os.write(user.getBytes(StandardCharsets.UTF_8)); b64os.write(0); b64os.write(passwd.getBytes(StandardCharsets.UTF_8)); b64os.flush(); // complete the encoding return ASCIIUtility.toString(bos.toByteArray()); }
write(b[off++]); if (off + blen <= end) { int outlen = encodedSize(blen); if (!noCRLF) { outbuf[outlen++] = (byte)'\r'; outbuf[outlen++] = (byte)'\n'; out.write(encode(b, off, blen, outbuf), 0, outlen); off += blen; count = 0; out.write(encode(b, off, lineLimit, outbuf)); blen = (blen / 3) * 3; // round down int outlen = encodedSize(blen); out.write(encode(b, off, blen, outbuf), 0, outlen); off += blen; count += outlen; write(b[off]);
/** * Forces any buffered output bytes to be encoded out to the stream * and closes this output stream */ public synchronized void close() throws IOException { flush(); if (count > 0 && !noCRLF) { out.write(newline); out.flush(); } out.close(); }
/** * Encode the data stored in <code>buffer</code>. * Uses <code>outbuf</code> to store the encoded * data before writing. * * @exception IOException if an I/O error occurs. */ private void encode() throws IOException { int osize = encodedSize(bufsize); out.write(encode(buffer, 0, bufsize, outbuf), 0, osize); // increment count count += osize; // If writing out this encoded unit caused overflow, // start a new line. if (count >= bytesPerLine) { if (!noCRLF) out.write(newline); count = 0; } }
/** * Encodes the specified <code>byte</code> to this output stream. * * @param c the <code>byte</code>. * @exception IOException if an I/O error occurs. */ public synchronized void write(int c) throws IOException { buffer[bufsize++] = (byte)c; if (bufsize == 3) { // Encoding unit = 3 bytes encode(); bufsize = 0; } }
/** * Encodes <code>b.length</code> bytes to this output stream. * * @param b the data to be written. * @exception IOException if an I/O error occurs. */ public void write(byte[] b) throws IOException { write(b, 0, b.length); }
byte[] outbuf) { if (outbuf == null) outbuf = new byte[encodedSize(size)]; int inpos, outpos; int val;
/** * Encode the data stored in <code>buffer</code>. * Uses <code>outbuf</code> to store the encoded * data before writing. * * @exception IOException if an I/O error occurs. */ private void encode() throws IOException { int osize = encodedSize(bufsize); out.write(encode(buffer, 0, bufsize, outbuf), 0, osize); // increment count count += osize; // If writing out this encoded unit caused overflow, // start a new line. if (count >= bytesPerLine) { if (!noCRLF) out.write(newline); count = 0; } }
/** * Base64 encode a byte array. No line breaks are inserted. * This method is suitable for short strings, such as those * in the IMAP AUTHENTICATE protocol, but not to encode the * entire content of a MIME part. * * @param inbuf the byte array * @return the encoded byte array */ public static byte[] encode(byte[] inbuf) { if (inbuf.length == 0) return inbuf; return encode(inbuf, 0, inbuf.length, null); }
/** * Encodes <code>b.length</code> bytes to this output stream. * * @param b the data to be written. * @exception IOException if an I/O error occurs. */ @Override public void write(byte[] b) throws IOException { write(b, 0, b.length); }
byte[] outbuf) { if (outbuf == null) outbuf = new byte[encodedSize(size)]; int inpos, outpos; int val;
write(b[off++]); if (off + blen <= end) { int outlen = encodedSize(blen); if (!noCRLF) { outbuf[outlen++] = (byte)'\r'; outbuf[outlen++] = (byte)'\n'; out.write(encode(b, off, blen, outbuf), 0, outlen); off += blen; count = 0; out.write(encode(b, off, lineLimit, outbuf)); blen = (blen / 3) * 3; // round down int outlen = encodedSize(blen); out.write(encode(b, off, blen, outbuf), 0, outlen); off += blen; count += outlen; write(b[off]);
String getInitialResponse(String host, String authzid, String user, String passwd) throws MessagingException, IOException { // return "authzid<NUL>user<NUL>passwd" ByteArrayOutputStream bos = new ByteArrayOutputStream(); OutputStream b64os = new BASE64EncoderStream(bos, Integer.MAX_VALUE); if (authzid != null) b64os.write(ASCIIUtility.getBytes(authzid)); b64os.write(0); b64os.write(ASCIIUtility.getBytes(user)); b64os.write(0); b64os.write(ASCIIUtility.getBytes(passwd)); b64os.flush(); // complete the encoding return ASCIIUtility.toString(bos.toByteArray()); }
/** * Encode the data stored in <code>buffer</code>. * Uses <code>outbuf</code> to store the encoded * data before writing. * * @exception IOException if an I/O error occurs. */ private void encode() throws IOException { int osize = encodedSize(bufsize); out.write(encode(buffer, 0, bufsize, outbuf), 0, osize); // increment count count += osize; // If writing out this encoded unit caused overflow, // start a new line. if (count >= bytesPerLine) { if (!noCRLF) out.write(newline); count = 0; } }
/** * Base64 encode a byte array. No line breaks are inserted. * This method is suitable for short strings, such as those * in the IMAP AUTHENTICATE protocol, but not to encode the * entire content of a MIME part. * * @param inbuf the byte array * @return the encoded byte array */ public static byte[] encode(byte[] inbuf) { if (inbuf.length == 0) return inbuf; return encode(inbuf, 0, inbuf.length, null); }
/** * Encodes <code>b.length</code> bytes to this output stream. * * @param b the data to be written. * @exception IOException if an I/O error occurs. */ @Override public void write(byte[] b) throws IOException { write(b, 0, b.length); }
/** * Forces any buffered output bytes to be encoded out to the stream * and closes this output stream */ @Override public synchronized void close() throws IOException { flush(); if (count > 0 && !noCRLF) { out.write(newline); out.flush(); } out.close(); }
byte[] outbuf) { if (outbuf == null) outbuf = new byte[encodedSize(size)]; int inpos, outpos; int val;
write(b[off++]); if (off + blen <= end) { int outlen = encodedSize(blen); if (!noCRLF) { outbuf[outlen++] = (byte)'\r'; outbuf[outlen++] = (byte)'\n'; out.write(encode(b, off, blen, outbuf), 0, outlen); off += blen; count = 0; out.write(encode(b, off, lineLimit, outbuf)); blen = (blen / 3) * 3; // round down int outlen = encodedSize(blen); out.write(encode(b, off, blen, outbuf), 0, outlen); off += blen; count += outlen; write(b[off]);
return os; else if (encoding.equalsIgnoreCase("base64")) return new BASE64EncoderStream(os); else if (encoding.equalsIgnoreCase("quoted-printable")) return new QPEncoderStream(os);