Search in sources :

Example 1 with StringPart

use of com.stanfy.enroscar.rest.request.net.multipart.StringPart in project enroscar by stanfy.

the class UploadPostConverter method composeParts.

/**
   * @param context application context
   * @param requestDescription request description
   * @return upload request parts obtained from the request description
   * @throws IOException if an I/O error happens
   */
protected static Part[] composeParts(final Context context, final RequestDescription requestDescription) throws IOException {
    final ArrayList<BinaryData<?>> binaryData = requestDescription.getBinaryData();
    final List<Parameter> params = requestDescription.getSimpleParameters().getChildren();
    int realCount = 0;
    final int binaryCount = binaryData != null ? binaryData.size() : 0;
    Part[] parts = new Part[params.size() + binaryCount];
    for (final Parameter p : params) {
        if (p instanceof ParameterValue) {
            final ParameterValue pv = (ParameterValue) p;
            if (pv.getValue() == null) {
                continue;
            }
            parts[realCount++] = new StringPart(pv.getName(), pv.getValue(), requestDescription.getEncoding().name());
        }
    }
    for (int i = 0; i < binaryCount; i++) {
        final Part part = binaryData.get(i).createHttpPart(context);
        if (part != null) {
            parts[realCount++] = part;
        }
    }
    if (realCount < parts.length) {
        final Part[] trim = new Part[realCount];
        System.arraycopy(parts, 0, trim, 0, realCount);
        parts = trim;
    }
    return parts;
}
Also used : ParameterValue(com.stanfy.enroscar.net.operation.ParameterValue) Part(com.stanfy.enroscar.rest.request.net.multipart.Part) StringPart(com.stanfy.enroscar.rest.request.net.multipart.StringPart) StringPart(com.stanfy.enroscar.rest.request.net.multipart.StringPart) Parameter(com.stanfy.enroscar.net.operation.Parameter) BinaryData(com.stanfy.enroscar.rest.request.binary.BinaryData)

Example 2 with StringPart

use of com.stanfy.enroscar.rest.request.net.multipart.StringPart in project enroscar by stanfy.

the class StringBinaryData method createHttpPart.

@Override
public Part createHttpPart(final Context context) throws IOException {
    StringPart sp = new StringPart("", str, IoUtils.UTF_8_NAME);
    sp.setContentType(getContentType());
    return sp;
}
Also used : StringPart(com.stanfy.enroscar.rest.request.net.multipart.StringPart)

Aggregations

StringPart (com.stanfy.enroscar.rest.request.net.multipart.StringPart)2 Parameter (com.stanfy.enroscar.net.operation.Parameter)1 ParameterValue (com.stanfy.enroscar.net.operation.ParameterValue)1 BinaryData (com.stanfy.enroscar.rest.request.binary.BinaryData)1 Part (com.stanfy.enroscar.rest.request.net.multipart.Part)1