Java ByteBuffer Get getCRLFCRLFIndex(ByteBuffer buffer)

Here you can find the source of getCRLFCRLFIndex(ByteBuffer buffer)

Description

get CRLFCRLF Index

License

Open Source License

Declaration

public static int getCRLFCRLFIndex(ByteBuffer buffer) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.nio.ByteBuffer;

public class Main {
    public static int getCRLFCRLFIndex(ByteBuffer buffer) {
        int len = buffer.position();
        int s = 0;
        for (int i = 0; i < len; i++) {
            switch (buffer.get(i)) {
            case '\r':
                switch (s) {
                case 0:
                    s = 1;/* ww w.  j a va  2 s  .  c  o m*/
                    break;
                case 2:
                    s = 3;
                    break;
                case 3:
                    s = 1;
                    break;
                }
                break;
            case '\n':
                switch (s) {
                case 1:
                    s = 2;
                    break;
                case 2:
                    s = 0;
                    break;
                case 3:
                    return i - 3;
                }
                break;
            default:
                s = 0;
                break;
            }
        }
        return -1;
    }
}

Related

  1. getByteAsShort(java.nio.ByteBuffer buffer)
  2. getByteLen(ByteBuffer buffer)
  3. getChars(ByteBuffer buf, int off, int count)
  4. getCPCharacter(ByteBuffer buffer)
  5. getCrcChecksum(ByteBuffer buffer)
  6. getCRLFIndex(ByteBuffer buffer)
  7. getCRLFLine(ByteBuffer buf)
  8. getData(ByteBuffer buf, int index, int size)
  9. getDataFromBuffer(ByteBuffer b)