The newest version of nomos license scanner found:

Apache-2.0 (#1)Legend:

license relevant text

1 2 3 [Next][Last]

/*
* Copyright (c) 2008-2016 MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.bson;

import org.bson.types.Decimal128;
import org.bson.types.ObjectId;

import java.io.Closeable;

import static java.lang.String.format;
import static java.util.Arrays.asList;

/**
* Abstract base class for BsonReader implementations.
*
* @since 3.0
*/
public abstract class AbstractBsonReader implements Closeable, BsonReader {
private State state;
private Context context;
private BsonType currentBsonType;
private String currentName;
private boolean closed;

/**
* Initializes a new instance of the BsonReader class.
*/
protected AbstractBsonReader() {
state = State.INITIAL;
}

@Override
public BsonType getCurrentBsonType() {
return currentBsonType;
}

@Override
public String getCurrentName() {
if (state != State.VALUE) {
throwInvalidState("getCurrentName", State.VALUE);
}
return currentName;
}

/**
* Sets the type of the current value being read.
*
* @param newType the BSON Type.
*/
protected void setCurrentBsonType(final BsonType newType) {
currentBsonType = newType;
}

/**
* @return The current state of the reader.
*/
public State getState() {
return state;
}

/**
* Sets the new current state of this reader.
*
* @param newState the state to set this reader to.
*/
protected void setState(final State newState) {
state = newState;
}

/**
* Sets the field name for the key/value pair being read.
*
* @param newName the field name
*/
protected void setCurrentName(final String newName) {
currentName = newName;
}

/**
* Closes the reader.
*/
public void close() {
closed = true;
}

/**
* Return true if the reader has been closed.
*
* @return true if closed
*/
protected boolean isClosed() {
return closed;
}

/**
* Handles the logic to read binary data
*
* @return the BsonBinary value
*/
protected abstract BsonBinary doReadBinaryData();

/**
* Handles the logic to peek at the binary subtype.
*
* @return the binary subtype
*/
protected abstract byte doPeekBinarySubType();

/**
* Handles the logic to peek at the binary size.
*
* @return the binary size
* @since 3.4
*/
protected abstract int doPeekBinarySize();

/**
* Handles the logic to read booleans
*
* @return the boolean value
*/
protected abstract boolean doReadBoolean();

/**
* Handles the logic to read date time
*
* @return the long value
*/
protected abstract long doReadDateTime();

/**
* Handles the logic to read doubles
*
* @return the double value
*/
protected abstract double doReadDouble();

/**
* Handles the logic when reading the end of an array
*/
protected abstract void doReadEndArray();

/**
* Handles the logic when reading the end of a document
*/
protected abstract void doReadEndDocument();

/**
* Handles the logic to read 32 bit ints
*
* @return the int value
*/
protected abstract int doReadInt32();

/**
* Handles the logic to read 64 bit ints
*
* @return the long value
*/
protected abstract long doReadInt64();


/**
* Handles the logic to read Decimal128
*
* @return the Decimal128 value
* @since 3.4
*/
protected abstract Decimal128 doReadDecimal128();

/**
* Handles the logic to read Javascript functions
*
* @return the String value
*/
protected abstract String doReadJavaScript();

/**
* Handles the logic to read scoped Javascript functions
*
* @return the String value
*/
protected abstract String doReadJavaScriptWithScope();

/**
* Handles the logic to read a Max key
*/
protected abstract void doReadMaxKey();

/**
* Handles the logic to read a Min key
*/
protected abstract void doReadMinKey();

/**
* Handles the logic to read a null value
*/
protected abstract void doReadNull();

/**
* Handles the logic to read an ObjectId
*
* @return the ObjectId value
*/
protected abstract ObjectId doReadObjectId();

/**
* Handles the logic to read a regular expression
*
* @return the BsonRegularExpression value
*/
protected abstract BsonRegularExpression doReadRegularExpression();

/**
* Handles the logic to read a DBPointer
*
* @return the BsonDbPointer value
*/
protected abstract BsonDbPointer doReadDBPointer();

/**
* Handles the logic to read the start of an array
*/
protected abstract void doReadStartArray();

/**
* Handles the logic to read the start of a document
*/
protected abstract void doReadStartDocument();

/**
* Handles the logic to read a String
*
* @return the String value
*/
protected abstract String doReadString();

/**
* Handles the logic to read a Symbol
*
* @return the String value
*/
protected abstract String doReadSymbol();

/**
* Handles the logic to read a timestamp
*
* @return the BsonTimestamp value
*/
protected abstract BsonTimestamp doReadTimestamp();

/**
* Handles the logic to read an Undefined value
*/
protected abstract void doReadUndefined();

/**
* Handles any logic required to skip the name (reader must be positioned on a name).
*/
protected abstract void doSkipName();

/**
* Handles any logic required to skip the value (reader must be positioned on a value).
*/
protected abstract void doSkipValue();

@Override
public BsonBinary readBinaryData() {
checkPreconditions("readBinaryData", BsonType.BINARY);
setState(getNextState());
return doReadBinaryData();
}

@Override
public byte peekBinarySubType() {
checkPreconditions("readBinaryData", BsonType.BINARY);
return doPeekBinarySubType();
}

@Override
public int peekBinarySize() {
checkPreconditions("readBinaryData", BsonType.BINARY);
return doPeekBinarySize();
}

@Override
public boolean readBoolean() {
checkPreconditions("readBoolean", BsonType.BOOLEAN);
setState(getNextState());
return doReadBoolean();
}

@Override
public abstract BsonType readBsonType();

@Override
public long readDateTime() {
checkPreconditions("readDateTime", BsonType.DATE_TIME);
setState(getNextState());
return doReadDateTime();
}

@Override
public double readDouble() {
checkPreconditions("readDouble", BsonType.DOUBLE);
setState(getNextState());
return doReadDouble();
}

@Override
public void readEndArray() {
if (isClosed()) {
throw new IllegalStateException("BSONBinaryWriter");
}
if (getContext().getContextType() != BsonContextType.ARRAY) {
throwInvalidContextType("readEndArray", getContext().getContextType(), BsonContextType.ARRAY);
}
if (getState() == State.TYPE) {
readBsonType(); // will set state to EndOfArray if at end of array
}
if (getState() != State.END_OF_ARRAY) {
throwInvalidState("ReadEndArray", State.END_OF_ARRAY);