"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "httpclient5/src/main/java/org/apache/hc/client5/http/entity/mime/AbstractMultipartFormat.java" between
httpcomponents-client-5.2-src.tar.gz and httpcomponents-client-5.2.1-src.tar.gz

About: Apache HttpComponents Client provides reusable components for client-side authentication, HTTP state management, and HTTP connection management. Java sources.

AbstractMultipartFormat.java  (httpcomponents-client-5.2-src):AbstractMultipartFormat.java  (httpcomponents-client-5.2.1-src)
skipping to change at line 50 skipping to change at line 50
import org.apache.hc.core5.util.ByteArrayBuffer; import org.apache.hc.core5.util.ByteArrayBuffer;
/** /**
* HttpMultipart represents a collection of MIME multipart encoded content bodie s. * HttpMultipart represents a collection of MIME multipart encoded content bodie s.
* *
* @since 4.3 * @since 4.3
*/ */
abstract class AbstractMultipartFormat { abstract class AbstractMultipartFormat {
static ByteArrayBuffer encode( static ByteArrayBuffer encode(
final Charset charset, final String string) { final Charset charset, final CharSequence string) {
final ByteBuffer encoded = charset.encode(CharBuffer.wrap(string)); final ByteBuffer encoded = charset.encode(CharBuffer.wrap(string));
final ByteArrayBuffer bab = new ByteArrayBuffer(encoded.remaining()); final ByteArrayBuffer bab = new ByteArrayBuffer(encoded.remaining());
bab.append(encoded.array(), encoded.arrayOffset() + encoded.position(), encoded.remaining()); bab.append(encoded.array(), encoded.arrayOffset() + encoded.position(), encoded.remaining());
return bab; return bab;
} }
static void writeBytes( static void writeBytes(
final ByteArrayBuffer b, final OutputStream out) throws IOException { final ByteArrayBuffer b, final OutputStream out) throws IOException {
out.write(b.array(), 0, b.length()); out.write(b.array(), 0, b.length());
} }
static void writeBytes( static void writeBytes(
final String s, final Charset charset, final OutputStream out) throw s IOException { final CharSequence s, final Charset charset, final OutputStream out) throws IOException {
final ByteArrayBuffer b = encode(charset, s); final ByteArrayBuffer b = encode(charset, s);
writeBytes(b, out); writeBytes(b, out);
} }
static void writeBytes( static void writeBytes(
final String s, final OutputStream out) throws IOException { final CharSequence s, final OutputStream out) throws IOException {
final ByteArrayBuffer b = encode(StandardCharsets.ISO_8859_1, s); final ByteArrayBuffer b = encode(StandardCharsets.ISO_8859_1, s);
writeBytes(b, out); writeBytes(b, out);
} }
static boolean isLineBreak(final char ch) {
return ch == '\r' || ch == '\n' || ch == '\f' || ch == 11;
}
static CharSequence stripLineBreaks(final CharSequence s) {
if (s == null) {
return null;
}
boolean requiresRewrite = false;
int n = 0;
for (; n < s.length(); n++) {
final char ch = s.charAt(n);
if (isLineBreak(ch)) {
requiresRewrite = true;
break;
}
}
if (!requiresRewrite) {
return s;
}
final StringBuilder buf = new StringBuilder();
buf.append(s, 0, n);
for (; n < s.length(); n++) {
final char ch = s.charAt(n);
if (isLineBreak(ch)) {
buf.append(' ');
} else {
buf.append(ch);
}
}
return buf.toString();
}
static void writeField( static void writeField(
final MimeField field, final OutputStream out) throws IOException { final MimeField field, final OutputStream out) throws IOException {
writeBytes(field.getName(), out); writeBytes(stripLineBreaks(field.getName()), out);
writeBytes(FIELD_SEP, out); writeBytes(FIELD_SEP, out);
writeBytes(field.getBody(), out); writeBytes(stripLineBreaks(field.getBody()), out);
writeBytes(CR_LF, out); writeBytes(CR_LF, out);
} }
static void writeField( static void writeField(
final MimeField field, final Charset charset, final OutputStream out ) throws IOException { final MimeField field, final Charset charset, final OutputStream out ) throws IOException {
writeBytes(field.getName(), charset, out); writeBytes(stripLineBreaks(field.getName()), charset, out);
writeBytes(FIELD_SEP, out); writeBytes(FIELD_SEP, out);
writeBytes(field.getBody(), charset, out); writeBytes(stripLineBreaks(field.getBody()), charset, out);
writeBytes(CR_LF, out); writeBytes(CR_LF, out);
} }
static final ByteArrayBuffer FIELD_SEP = encode(StandardCharsets.ISO_8859_1, ": "); static final ByteArrayBuffer FIELD_SEP = encode(StandardCharsets.ISO_8859_1, ": ");
static final ByteArrayBuffer CR_LF = encode(StandardCharsets.ISO_8859_1, "\r \n"); static final ByteArrayBuffer CR_LF = encode(StandardCharsets.ISO_8859_1, "\r \n");
static final ByteArrayBuffer TWO_HYPHENS = encode(StandardCharsets.ISO_8859_ 1, "--"); static final ByteArrayBuffer TWO_HYPHENS = encode(StandardCharsets.ISO_8859_ 1, "--");
final Charset charset; final Charset charset;
final String boundary; final String boundary;
 End of changes. 8 change blocks. 
7 lines changed or deleted 40 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)