class MultiPartParser {

    public boolean parse(ByteBuffer buffer, boolean last) {
        boolean handle = false;
        while (!handle && BufferUtils.hasContent(buffer)) {
            switch (state) {
                case PREAMBLE:
                    parsePreamble(buffer);
                    continue;

                case DELIMITER:
                case DELIMITER_PADDING:
                case DELIMITER_CLOSE:
                    parseDelimiter(buffer);
                    continue;

                case BODY_PART:
                    handle = parseMimePartHeaders(buffer);
                    break;

                case FIRST_OCTETS:
                case OCTETS:
                    handle = parseOctetContent(buffer);
                    break;

                case EPILOGUE:
                    BufferUtils.clear(buffer);
                    break;

                case END:
                    handle = true;
                    break;

                default:
                    throw new IllegalStateException();
            }
        }

        if (last && BufferUtils.isEmpty(buffer)) {
            if (state == State.EPILOGUE) {
                state = State.END;

                if (LOG.isDebugEnabled())
                    LOG.debug("messageComplete {}", this);

                return handler.messageComplete();
            } else {
                if (LOG.isDebugEnabled())
                    LOG.debug("earlyEOF {}", this);

                handler.earlyEOF();
                return true;
            }
        }

        return handle;
    }

    public  MultiPartParser(Handler handler, String boundary);

}