/** * This is used to process the bytes that have been read from the cursor. This will search for the * boundary token within the body of the message part, when it is found this will returns the * number of bytes that represent the overflow. * * @param array this is a chunk read from the cursor * @param off this is the offset within the array the chunk starts * @param size this is the number of bytes within the array * @return this returns the number of bytes overflow that is read */ @Override protected int update(byte[] array, int off, int size) throws IOException { int skip = start + seek; // did we skip previously int last = off + size; int next = start; int mark = off; while (off < last) { if (start == START.length) { // search for boundary if (array[off++] != boundary[seek++]) { // boundary not found if (skip > 0) { append(START, 0, next); // write skipped start append(boundary, 0, skip - next); // write skipped boundary } skip = start = seek = 0; // reset scan position } if (seek == boundary.length) { // boundary found int excess = seek + start; // boundary bytes read int total = off - mark; // total bytes read int valid = total - excess; // body bytes read finished = true; if (valid > 0) { append(array, mark, valid); } Part part = getPart(); if (part != null) { series.addPart(part); } return size - total; // remaining excluding boundary } } else { byte octet = array[off++]; // current if (octet != START[start++]) { if (skip > 0) { append(START, 0, next); // write skipped start } skip = start = 0; // reset if (octet == START[0]) { // is previous byte the start start++; } } } } int excess = seek + start; // boundary bytes read int total = off - mark; // total bytes read int valid = total - excess; // body bytes read if (valid > 0) { // can we append processed data append(array, mark, valid); } return 0; }
/** * This method is used to acquire a <code>Part</code> from the HTTP request using a known name for * the part. This is typically used when there is a file upload with a multipart POST request. All * parts that are not files can be acquired as string values from the attachment object. * * @param name this is the name of the part object to acquire * @return the named part or null if the part does not exist */ public Part getPart(String name) { if (series != null) { return series.getPart(name); } return null; }
/** * This method is used to get all <code>Part</code> objects that are associated with the request. * Each attachment contains the body and headers associated with it. If the request is not a * multipart POST request then this will return an empty list. * * @return the list of parts associated with this request */ public List<Part> getParts() { if (series != null) { return series.getParts(); } return Collections.emptyList(); }