Java Code Examples for org.apache.hadoop.io.DataOutputBuffer#writeBytes()

The following examples show how to use org.apache.hadoop.io.DataOutputBuffer#writeBytes() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StreamXmlRecordReader.java    From hadoop with Apache License 2.0 4 votes vote down vote up
private boolean slowReadUntilMatch(Pattern markPattern, boolean includePat,
                                   DataOutputBuffer outBufOrNull) throws IOException {
  byte[] buf = new byte[Math.max(lookAhead_, maxRecSize_)];
  int read = 0;
  bin_.mark(Math.max(lookAhead_, maxRecSize_) + 2); //mark to invalidate if we read more
  read = bin_.read(buf);
  if (read == -1) return false;

  String sbuf = new String(buf, 0, read, "UTF-8");
  Matcher match = markPattern.matcher(sbuf);

  firstMatchStart_ = NA;
  firstMatchEnd_ = NA;
  int bufPos = 0;
  int state = synched_ ? CDATA_OUT : CDATA_UNK;
  int s = 0;

  while (match.find(bufPos)) {
    int input;
    if (match.group(1) != null) {
      input = CDATA_BEGIN;
    } else if (match.group(2) != null) {
      input = CDATA_END;
      firstMatchStart_ = NA; // |<DOC CDATA[ </DOC> ]]> should keep it
    } else {
      input = RECORD_MAYBE;
    }
    if (input == RECORD_MAYBE) {
      if (firstMatchStart_ == NA) {
        firstMatchStart_ = match.start();
        firstMatchEnd_ = match.end();
      }
    }
    state = nextState(state, input, match.start());
    if (state == RECORD_ACCEPT) {
      break;
    }
    bufPos = match.end();
    s++;
  }
  if (state != CDATA_UNK) {
    synched_ = true;
  }
  boolean matched = (firstMatchStart_ != NA) && (state == RECORD_ACCEPT || state == CDATA_UNK);
  if (matched) {
    int endPos = includePat ? firstMatchEnd_ : firstMatchStart_;
    bin_.reset();

    for (long skiplen = endPos; skiplen > 0; ) {
      skiplen -= bin_.skip(skiplen); // Skip succeeds as we have read this buffer
    }

    pos_ += endPos;
    if (outBufOrNull != null) {
      outBufOrNull.writeBytes(sbuf.substring(0,endPos));
    }
  }
  return matched;
}
 
Example 2
Source File: StreamXmlRecordReader.java    From big-c with Apache License 2.0 4 votes vote down vote up
private boolean slowReadUntilMatch(Pattern markPattern, boolean includePat,
                                   DataOutputBuffer outBufOrNull) throws IOException {
  byte[] buf = new byte[Math.max(lookAhead_, maxRecSize_)];
  int read = 0;
  bin_.mark(Math.max(lookAhead_, maxRecSize_) + 2); //mark to invalidate if we read more
  read = bin_.read(buf);
  if (read == -1) return false;

  String sbuf = new String(buf, 0, read, "UTF-8");
  Matcher match = markPattern.matcher(sbuf);

  firstMatchStart_ = NA;
  firstMatchEnd_ = NA;
  int bufPos = 0;
  int state = synched_ ? CDATA_OUT : CDATA_UNK;
  int s = 0;

  while (match.find(bufPos)) {
    int input;
    if (match.group(1) != null) {
      input = CDATA_BEGIN;
    } else if (match.group(2) != null) {
      input = CDATA_END;
      firstMatchStart_ = NA; // |<DOC CDATA[ </DOC> ]]> should keep it
    } else {
      input = RECORD_MAYBE;
    }
    if (input == RECORD_MAYBE) {
      if (firstMatchStart_ == NA) {
        firstMatchStart_ = match.start();
        firstMatchEnd_ = match.end();
      }
    }
    state = nextState(state, input, match.start());
    if (state == RECORD_ACCEPT) {
      break;
    }
    bufPos = match.end();
    s++;
  }
  if (state != CDATA_UNK) {
    synched_ = true;
  }
  boolean matched = (firstMatchStart_ != NA) && (state == RECORD_ACCEPT || state == CDATA_UNK);
  if (matched) {
    int endPos = includePat ? firstMatchEnd_ : firstMatchStart_;
    bin_.reset();

    for (long skiplen = endPos; skiplen > 0; ) {
      skiplen -= bin_.skip(skiplen); // Skip succeeds as we have read this buffer
    }

    pos_ += endPos;
    if (outBufOrNull != null) {
      outBufOrNull.writeBytes(sbuf.substring(0,endPos));
    }
  }
  return matched;
}
 
Example 3
Source File: StreamXmlRecordReader.java    From RDFS with Apache License 2.0 4 votes vote down vote up
private boolean slowReadUntilMatch(Pattern markPattern, boolean includePat,
                                   DataOutputBuffer outBufOrNull) throws IOException {

    byte[] buf = new byte[Math.max(lookAhead_, maxRecSize_)];
    int read = 0;
    boolean success = true;
    long skippedBytes = 0;
    bin_.mark(Math.max(lookAhead_, maxRecSize_) + 2); //mark to invalidate if we read more
    read = bin_.read(buf);
    if (read == -1) return false;
 
    String sbuf = new String(buf, 0, read, "UTF-8");
    Matcher match = markPattern.matcher(sbuf);
 

    firstMatchStart_ = NA;
    firstMatchEnd_ = NA;
    int bufPos = 0;
    int state = synched_ ? CDATA_OUT : CDATA_UNK;
    int s = 0;
    int matchLen = 0;
    int LL = 120000 * 10;

    while (match.find(bufPos)) {
        int input;
        matchLen = match.group(0).length();
        if (match.group(1) != null) {
            input = CDATA_BEGIN;
        } else if (match.group(2) != null) {
            input = CDATA_END;
            firstMatchStart_ = NA; // |<DOC CDATA[ </DOC> ]]> should keep it
        } else {
            input = RECORD_MAYBE;
        }
        if (input == RECORD_MAYBE) {
            if (firstMatchStart_ == NA) {
                firstMatchStart_ = match.start();
                firstMatchEnd_ = match.end();
            }
        }
        state = nextState(state, input, match.start());
        if (state == RECORD_ACCEPT) {
            bufPos = match.end();
            break;
        }
        bufPos = match.end();
        s++;
    }
    if (state != CDATA_UNK) {
        synched_ = true;
    }
    boolean matched = (firstMatchStart_ != NA) && (state == RECORD_ACCEPT || state == CDATA_UNK);
    if (matched) {
        int endPos = includePat ? firstMatchEnd_ : firstMatchStart_;
        bin_.reset();
        skippedBytes = bin_.skip(endPos); //Skip succeeds as we have already read this is buffer
        pos_ += endPos;
        if (outBufOrNull != null) {
            outBufOrNull.writeBytes(sbuf.substring(0,endPos));
        }
    }
    return matched;
}
 
Example 4
Source File: StreamXmlRecordReader.java    From RDFS with Apache License 2.0 4 votes vote down vote up
private boolean slowReadUntilMatch(Pattern markPattern, boolean includePat,
                                   DataOutputBuffer outBufOrNull) throws IOException {
  byte[] buf = new byte[Math.max(lookAhead_, maxRecSize_)];
  int read = 0;
  bin_.mark(Math.max(lookAhead_, maxRecSize_) + 2); //mark to invalidate if we read more
  read = bin_.read(buf);
  if (read == -1) return false;

  String sbuf = new String(buf, 0, read, "UTF-8");
  Matcher match = markPattern.matcher(sbuf);

  firstMatchStart_ = NA;
  firstMatchEnd_ = NA;
  int bufPos = 0;
  int state = synched_ ? CDATA_OUT : CDATA_UNK;
  int s = 0;

  while (match.find(bufPos)) {
    int input;
    if (match.group(1) != null) {
      input = CDATA_BEGIN;
    } else if (match.group(2) != null) {
      input = CDATA_END;
      firstMatchStart_ = NA; // |<DOC CDATA[ </DOC> ]]> should keep it
    } else {
      input = RECORD_MAYBE;
    }
    if (input == RECORD_MAYBE) {
      if (firstMatchStart_ == NA) {
        firstMatchStart_ = match.start();
        firstMatchEnd_ = match.end();
      }
    }
    state = nextState(state, input, match.start());
    if (state == RECORD_ACCEPT) {
      break;
    }
    bufPos = match.end();
    s++;
  }
  if (state != CDATA_UNK) {
    synched_ = true;
  }
  boolean matched = (firstMatchStart_ != NA) && (state == RECORD_ACCEPT || state == CDATA_UNK);
  if (matched) {
    int endPos = includePat ? firstMatchEnd_ : firstMatchStart_;
    bin_.reset();

    for (long skiplen = endPos; skiplen > 0; ) {
      skiplen -= bin_.skip(skiplen); // Skip succeeds as we have read this buffer
    }

    pos_ += endPos;
    if (outBufOrNull != null) {
      outBufOrNull.writeBytes(sbuf.substring(0,endPos));
    }
  }
  return matched;
}
 
Example 5
Source File: StreamXmlRecordReader.java    From hadoop-gpu with Apache License 2.0 4 votes vote down vote up
private boolean slowReadUntilMatch(Pattern markPattern, boolean includePat,
                                   DataOutputBuffer outBufOrNull) throws IOException {
  byte[] buf = new byte[Math.max(lookAhead_, maxRecSize_)];
  int read = 0;
  bin_.mark(Math.max(lookAhead_, maxRecSize_) + 2); //mark to invalidate if we read more
  read = bin_.read(buf);
  if (read == -1) return false;

  String sbuf = new String(buf, 0, read, "UTF-8");
  Matcher match = markPattern.matcher(sbuf);

  firstMatchStart_ = NA;
  firstMatchEnd_ = NA;
  int bufPos = 0;
  int state = synched_ ? CDATA_OUT : CDATA_UNK;
  int s = 0;

  while (match.find(bufPos)) {
    int input;
    if (match.group(1) != null) {
      input = CDATA_BEGIN;
    } else if (match.group(2) != null) {
      input = CDATA_END;
      firstMatchStart_ = NA; // |<DOC CDATA[ </DOC> ]]> should keep it
    } else {
      input = RECORD_MAYBE;
    }
    if (input == RECORD_MAYBE) {
      if (firstMatchStart_ == NA) {
        firstMatchStart_ = match.start();
        firstMatchEnd_ = match.end();
      }
    }
    state = nextState(state, input, match.start());
    if (state == RECORD_ACCEPT) {
      break;
    }
    bufPos = match.end();
    s++;
  }
  if (state != CDATA_UNK) {
    synched_ = true;
  }
  boolean matched = (firstMatchStart_ != NA) && (state == RECORD_ACCEPT || state == CDATA_UNK);
  if (matched) {
    int endPos = includePat ? firstMatchEnd_ : firstMatchStart_;
    bin_.reset();

    for (long skiplen = endPos; skiplen > 0; ) {
      skiplen -= bin_.skip(skiplen); // Skip succeeds as we have read this buffer
    }

    pos_ += endPos;
    if (outBufOrNull != null) {
      outBufOrNull.writeBytes(sbuf.substring(0,endPos));
    }
  }
  return matched;
}