12
12
*/
13
13
package org .asynchttpclient .request .body .multipart ;
14
14
15
- import static java .nio .charset .StandardCharsets .*;
16
-
17
- import java .io .ByteArrayOutputStream ;
18
- import java .io .IOException ;
19
15
import java .nio .charset .Charset ;
20
16
21
17
/**
22
18
* This class is an adaptation of the Apache HttpClient implementation
23
19
*/
24
- public abstract class AbstractFilePart extends PartBase {
20
+ public abstract class FileLikePart extends PartBase {
25
21
26
22
/**
27
23
* Default content encoding of file attachments.
@@ -33,11 +29,6 @@ public abstract class AbstractFilePart extends PartBase {
33
29
*/
34
30
public static final String DEFAULT_TRANSFER_ENCODING = "binary" ;
35
31
36
- /**
37
- * Attachment's file name as a byte array
38
- */
39
- private static final byte [] FILE_NAME_BYTES = "; filename=" .getBytes (US_ASCII );
40
-
41
32
private long stalledTime = -1L ;
42
33
43
34
private String fileName ;
@@ -51,44 +42,14 @@ public abstract class AbstractFilePart extends PartBase {
51
42
* @param contentId the content id
52
43
* @param transfertEncoding the transfer encoding
53
44
*/
54
- public AbstractFilePart (String name , String contentType , Charset charset , String contentId , String transfertEncoding ) {
45
+ public FileLikePart (String name , String contentType , Charset charset , String contentId , String transfertEncoding ) {
55
46
super (name ,//
56
47
contentType == null ? DEFAULT_CONTENT_TYPE : contentType ,//
57
48
charset ,//
58
49
contentId ,//
59
50
transfertEncoding == null ? DEFAULT_TRANSFER_ENCODING : transfertEncoding );
60
51
}
61
52
62
- protected void visitDispositionHeader (PartVisitor visitor ) throws IOException {
63
- super .visitDispositionHeader (visitor );
64
- if (fileName != null ) {
65
- visitor .withBytes (FILE_NAME_BYTES );
66
- visitor .withByte (QUOTE_BYTE );
67
- visitor .withBytes (fileName .getBytes (getCharset () != null ? getCharset () : US_ASCII ));
68
- visitor .withByte (QUOTE_BYTE );
69
- }
70
- }
71
-
72
- protected byte [] generateFileStart (byte [] boundary ) throws IOException {
73
- ByteArrayOutputStream out = new ByteArrayOutputStream ();
74
- OutputStreamPartVisitor visitor = new OutputStreamPartVisitor (out );
75
- visitStart (visitor , boundary );
76
- visitDispositionHeader (visitor );
77
- visitContentTypeHeader (visitor );
78
- visitTransferEncodingHeader (visitor );
79
- visitContentIdHeader (visitor );
80
- visitCustomHeaders (visitor );
81
- visitEndOfHeaders (visitor );
82
- return out .toByteArray ();
83
- }
84
-
85
- protected byte [] generateFileEnd () throws IOException {
86
- ByteArrayOutputStream out = new ByteArrayOutputStream ();
87
- OutputStreamPartVisitor visitor = new OutputStreamPartVisitor (out );
88
- visitEnd (visitor );
89
- return out .toByteArray ();
90
- }
91
-
92
53
public void setStalledTime (long ms ) {
93
54
stalledTime = ms ;
94
55
}
0 commit comments