/** * 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; }