Java 类javax.json.stream.JsonLocation 实例源码

项目:cookjson    文件:UTF8TextJsonParserTest.java   
@Test
public void testLocation4 ()
{
    String json = "{\"abc\\t\" : []}";

    JsonParser p = new UTF8TextJsonParser (new ByteArrayInputStream (json.getBytes (BOM.utf8)));
    JsonLocation location = null;
    while (p.hasNext ())
    {
        switch (p.next ())
        {
            case START_ARRAY:
                location = p.getLocation ();
                break;
            default:
                break;
        }
    }
    p.close ();
    Assert.assertEquals (1, location.getLineNumber ());
    Assert.assertEquals (12, location.getColumnNumber ());
    Assert.assertEquals (11, location.getStreamOffset ());
}
项目:cookjson    文件:UTF8TextJsonParserTest.java   
@Test
public void testLocation5 ()
{
    String json = "[ true, false, null ]";

    JsonParser p = new UTF8TextJsonParser (new ByteArrayInputStream (json.getBytes (BOM.utf8)));
    JsonLocation location = null;
    while (p.hasNext ())
    {
        switch (p.next ())
        {
            case VALUE_TRUE:
                location = p.getLocation ();
                break;
            default:
                break;
        }
    }
    p.close ();
    Assert.assertEquals (1, location.getLineNumber ());
    Assert.assertEquals (3, location.getColumnNumber ());
    Assert.assertEquals (2, location.getStreamOffset ());
}
项目:cookjson    文件:UTF8TextJsonParserTest.java   
@Test
public void testLocation6 ()
{
    String json = "[ true, false, null ]";

    JsonParser p = new UTF8TextJsonParser (new ByteArrayInputStream (json.getBytes (BOM.utf8)));
    JsonLocation location = null;
    while (p.hasNext ())
    {
        switch (p.next ())
        {
            case VALUE_FALSE:
                location = p.getLocation ();
                break;
            default:
                break;
        }
    }
    p.close ();
    Assert.assertEquals (1, location.getLineNumber ());
    Assert.assertEquals (9, location.getColumnNumber ());
    Assert.assertEquals (8, location.getStreamOffset ());
}
项目:cookjson    文件:UTF8TextJsonParserTest.java   
@Test
public void testLocation7 ()
{
    String json = "[ true, false, null ]";

    JsonParser p = new UTF8TextJsonParser (new ByteArrayInputStream (json.getBytes (BOM.utf8)));
    JsonLocation location = null;
    while (p.hasNext ())
    {
        switch (p.next ())
        {
            case VALUE_NULL:
                location = p.getLocation ();
                break;
            default:
                break;
        }
    }
    p.close ();
    Assert.assertEquals (1, location.getLineNumber ());
    Assert.assertEquals (16, location.getColumnNumber ());
    Assert.assertEquals (15, location.getStreamOffset ());
}
项目:cookjson    文件:TextJsonParserTest.java   
@Test
public void testLocation4 ()
{
    String json = "{\"abc\\t\" : []}";

    TextJsonParser p = new TextJsonParser (new StringReader (json));
    JsonLocation location = null;
    while (p.hasNext ())
    {
        switch (p.next ())
        {
            case START_ARRAY:
                location = p.getLocation ();
                break;
            default:
                break;
        }
    }
    p.close ();
    Assert.assertEquals (1, location.getLineNumber ());
    Assert.assertEquals (12, location.getColumnNumber ());
    Assert.assertEquals (11, location.getStreamOffset ());
}
项目:cookjson    文件:TextJsonParserTest.java   
@Test
public void testLocation5 ()
{
    String json = "[ true, false, null ]";

    TextJsonParser p = new TextJsonParser (new StringReader (json));
    JsonLocation location = null;
    while (p.hasNext ())
    {
        switch (p.next ())
        {
            case VALUE_TRUE:
                location = p.getLocation ();
                break;
            default:
                break;
        }
    }
    p.close ();
    Assert.assertEquals (1, location.getLineNumber ());
    Assert.assertEquals (3, location.getColumnNumber ());
    Assert.assertEquals (2, location.getStreamOffset ());
}
项目:cookjson    文件:TextJsonParserTest.java   
@Test
public void testLocation6 ()
{
    String json = "[ true, false, null ]";

    TextJsonParser p = new TextJsonParser (new StringReader (json));
    JsonLocation location = null;
    while (p.hasNext ())
    {
        switch (p.next ())
        {
            case VALUE_FALSE:
                location = p.getLocation ();
                break;
            default:
                break;
        }
    }
    p.close ();
    Assert.assertEquals (1, location.getLineNumber ());
    Assert.assertEquals (9, location.getColumnNumber ());
    Assert.assertEquals (8, location.getStreamOffset ());
}
项目:cookjson    文件:TextJsonParserTest.java   
@Test
public void testLocation7 ()
{
    String json = "[ true, false, null ]";

    TextJsonParser p = new TextJsonParser (new StringReader (json));
    JsonLocation location = null;
    while (p.hasNext ())
    {
        switch (p.next ())
        {
            case VALUE_NULL:
                location = p.getLocation ();
                break;
            default:
                break;
        }
    }
    p.close ();
    Assert.assertEquals (1, location.getLineNumber ());
    Assert.assertEquals (16, location.getColumnNumber ());
    Assert.assertEquals (15, location.getStreamOffset ());
}
项目:johnzon    文件:JsonStreamParserImpl.java   
private JsonLocation createLocation() {

        //we start with column = 1, so column is always >= 1
        //APi is not clear in this, but starting column with 1 is convenient
        long column = 1;
        long charOffset = 0;

        if (bufferPos >= -1) {

            charOffset = pastBufferReadCount + bufferPos + 1;
            column = lastLineBreakPosition == 0 ? charOffset + 1 : charOffset - lastLineBreakPosition;
        }

        //For now its unclear how to calculate offset for (byte) inputsream.
        //API says count bytes but thats dependent on encoding and not efficient
        //skip this for now, count always bytes and defer this until the JSR TCK arrives.

        return new JsonLocationImpl(currentLine, column, charOffset);
    }
项目:johnzon    文件:LocationTest.java   
private void assertJsonLocation(String jsonString, JsonLocation expectedLocation) {
    JsonParser parser = Json.createParser(new StringReader(jsonString));
    try {
        while(parser.hasNext()) {
            parser.next();
        }
        Assert.fail("Expected to throw JsonParsingException for "+jsonString);
    } catch(JsonParsingException je) {
        // Expected
        if (expectedLocation != null) {
            JsonLocation loc = je.getLocation();
            assertEquals("for line number", expectedLocation.getLineNumber(), loc.getLineNumber());
            assertEquals("for column number", expectedLocation.getColumnNumber(), loc.getColumnNumber());
            assertEquals("for stream offset", expectedLocation.getStreamOffset(), loc.getStreamOffset());
        }
    } finally {
        parser.close();
    }
}
项目:hibiscus    文件:Messages.java   
/**
 * Returns the message that represents the problem as a whole.
 * @param locale the locale desired for the message.
 * @param location the location where the problem was found. This can be {@code null}.
 * @param description the description of the problem.
 * @return localized message for the problem.
 */
static String PROBLEM_MESSAGE(Locale locale, JsonLocation location, String description) {
    ResourceBundle bundle = getBundle(locale);
    String locationPart = null;
    if (location == null) {
        locationPart = bundle.getString("problem.location.unknown");
    } else {
        locationPart = format(bundle.getString("problem.location"), location.getLineNumber(), location.getColumnNumber());
    }
    return format(bundle.getString("problem.message"), locationPart, description);
}
项目:cookjson    文件:TextJsonParser.java   
private JsonLocation getCurrentLocation ()
{
    JsonLocationImpl location = new JsonLocationImpl ();
    location.m_columnNumber = m_column;
    location.m_streamOffset = m_offset;
    location.m_lineNumber = m_line;
    return location;
}
项目:cookjson    文件:TextJsonParser.java   
@Override
public JsonLocation getLocation ()
{
    JsonLocationImpl location = new JsonLocationImpl ();
    long diff = 0;
    switch (m_event)
    {
        case START_OBJECT:
        case START_ARRAY:
        case END_OBJECT:
        case END_ARRAY:
            diff = 1;
            break;
        case VALUE_NUMBER:
            if (m_simple)
                diff = m_len;
            else
                diff = m_appendPos;
            break;
        case KEY_NAME:
        case VALUE_STRING:
        {
            location.m_columnNumber = savedColumn - 1;  // minus 1 to account for '"'
            location.m_streamOffset = savedOffset - 1;  // minus 1 to account for '"'
            location.m_lineNumber = savedLine;
            return location;
        }
        case VALUE_FALSE:
            diff = 5;
            break;
        case VALUE_NULL:
        case VALUE_TRUE:
            diff = 4;
            break;
    }
    location.m_columnNumber = m_column - diff;
    location.m_streamOffset = m_offset - diff;
    location.m_lineNumber = m_line;
    return location;
}
项目:cookjson    文件:UTF8TextJsonParser.java   
private JsonLocation getCurrentLocation ()
{
    JsonLocationImpl location = new JsonLocationImpl ();
    location.m_columnNumber = m_column;
    location.m_streamOffset = m_offset;
    location.m_lineNumber = m_line;
    return location;
}
项目:cookjson    文件:UTF8TextJsonParser.java   
@Override
public JsonLocation getLocation ()
{
    JsonLocationImpl location = new JsonLocationImpl ();
    long diff = 0;
    switch (m_event)
    {
        case START_OBJECT:
        case START_ARRAY:
        case END_OBJECT:
        case END_ARRAY:
            diff = 1;
            break;
        case VALUE_NUMBER:
            if (m_simple)
                diff = m_len;
            else
                diff = m_appendPos;
            break;
        case KEY_NAME:
        case VALUE_STRING:
        {
            location.m_columnNumber = savedColumn - 1;  // minus 1 to account for '"'
            location.m_streamOffset = savedOffset - 1;  // minus 1 to account for '"'
            location.m_lineNumber = savedLine;
            return location;
        }
        case VALUE_FALSE:
            diff = 5;
            break;
        case VALUE_NULL:
        case VALUE_TRUE:
            diff = 4;
            break;
    }
    location.m_columnNumber = m_column - diff;
    location.m_streamOffset = m_offset - diff;
    location.m_lineNumber = m_line;
    return location;
}
项目:cookjson    文件:UTF8TextJsonParserTest.java   
@Test
public void testLocation1 ()
{
    String json = "{\"abc\" : -1234}";

    JsonParser p = new UTF8TextJsonParser (new ByteArrayInputStream (json.getBytes (BOM.utf8)));
    JsonLocation location = null;
    while (p.hasNext ())
    {
        switch (p.next ())
        {
            case KEY_NAME:
                Assert.assertEquals ("abc", p.getString ());
                location = p.getLocation ();
                Assert.assertEquals ("line 1, column 2, offset 1", location.toString ());
                break;
            case VALUE_NUMBER:
                Assert.assertEquals ("-1234", p.getString ());
                location = p.getLocation ();
                Assert.assertEquals (1, location.getLineNumber ());
                Assert.assertEquals (10, location.getColumnNumber ());
                Assert.assertEquals (9, location.getStreamOffset ());
                Assert.assertEquals ("line 1, column 10, offset 9", location.toString ());
                break;
            default:
                break;
        }
    }
    p.close ();
}
项目:cookjson    文件:UTF8TextJsonParserTest.java   
@Test
public void testLocation2 ()
{
    String json = "{\"abc\" : 1234}";

    JsonParser p = new UTF8TextJsonParser (new ByteArrayInputStream (json.getBytes (BOM.utf8)));
    JsonLocation location = null;
    while (p.hasNext ())
    {
        switch (p.next ())
        {
            case KEY_NAME:
                Assert.assertEquals ("abc", p.getString ());
                location = p.getLocation ();
                Assert.assertEquals ("line 1, column 2, offset 1", location.toString ());
                break;
            case VALUE_NUMBER:
                Assert.assertEquals ("1234", p.getString ());
                location = p.getLocation ();
                Assert.assertEquals ("line 1, column 10, offset 9", location.toString ());
                break;
            default:
                break;
        }
    }
    p.close ();
}
项目:cookjson    文件:UTF8TextJsonParserTest.java   
@Test
public void testLocation2_2 ()
{
    String json = "{\"abc\" : 1234}";

    JsonParser p = new UTF8TextJsonParser (new ByteArrayInputStream (json.getBytes (BOM.utf8)), 2);
    JsonLocation location = null;
    while (p.hasNext ())
    {
        switch (p.next ())
        {
            case KEY_NAME:
                Assert.assertEquals ("abc", p.getString ());
                location = p.getLocation ();
                Assert.assertEquals ("line 1, column 2, offset 1", location.toString ());
                break;
            case VALUE_NUMBER:
                Assert.assertEquals ("1234", p.getString ());
                location = p.getLocation ();
                Assert.assertEquals ("line 1, column 10, offset 9", location.toString ());
                break;
            default:
                break;
        }
    }
    p.close ();
}
项目:cookjson    文件:UTF8TextJsonParserTest.java   
@Test
public void testLocation3 ()
{
    String json = "{\"abc\\t\" : \"def\\t\\\"ghi\"}";

    JsonParser p = new UTF8TextJsonParser (new ByteArrayInputStream (json.getBytes (BOM.utf8)));
    JsonLocation location = null;
    while (p.hasNext ())
    {
        switch (p.next ())
        {
            case KEY_NAME:
                Assert.assertEquals ("abc\t", p.getString ());
                location = p.getLocation ();
                Assert.assertEquals ("line 1, column 2, offset 1", location.toString ());
                break;
            case VALUE_STRING:
                Assert.assertEquals ("def\t\"ghi", p.getString ());
                location = p.getLocation ();
                Assert.assertEquals ("line 1, column 12, offset 11", location.toString ());
                break;
            default:
                break;
        }
    }
    p.close ();
}
项目:cookjson    文件:TextJsonParserTest.java   
@Test
public void testLocation1 ()
{
    String json = "{\"abc\" : -1234}";

    TextJsonParser p = new TextJsonParser (new StringReader (json));
    JsonLocation location = null;
    while (p.hasNext ())
    {
        switch (p.next ())
        {
            case KEY_NAME:
                Assert.assertEquals ("abc", p.getString ());
                location = p.getLocation ();
                Assert.assertEquals ("line 1, column 2, offset 1", location.toString ());
                break;
            case VALUE_NUMBER:
                Assert.assertEquals ("-1234", p.getString ());
                location = p.getLocation ();
                Assert.assertEquals (1, location.getLineNumber ());
                Assert.assertEquals (10, location.getColumnNumber ());
                Assert.assertEquals (9, location.getStreamOffset ());
                Assert.assertEquals ("line 1, column 10, offset 9", location.toString ());
                break;
            default:
                break;
        }
    }
    p.close ();
}
项目:cookjson    文件:TextJsonParserTest.java   
@Test
public void testLocation2 ()
{
    String json = "{\"abc\" : 1234}";

    TextJsonParser p = new TextJsonParser (new StringReader (json));
    JsonLocation location = null;
    while (p.hasNext ())
    {
        switch (p.next ())
        {
            case KEY_NAME:
                Assert.assertEquals ("abc", p.getString ());
                location = p.getLocation ();
                Assert.assertEquals ("line 1, column 2, offset 1", location.toString ());
                break;
            case VALUE_NUMBER:
                Assert.assertEquals ("1234", p.getString ());
                location = p.getLocation ();
                Assert.assertEquals ("line 1, column 10, offset 9", location.toString ());
                break;
            default:
                break;
        }
    }
    p.close ();
}
项目:cookjson    文件:TextJsonParserTest.java   
@Test
public void testLocation2_2 ()
{
    String json = "{\"abc\" : 1234}";

    TextJsonParser p = new TextJsonParser (new StringReader (json), 2);
    JsonLocation location = null;
    while (p.hasNext ())
    {
        switch (p.next ())
        {
            case KEY_NAME:
                Assert.assertEquals ("abc", p.getString ());
                location = p.getLocation ();
                Assert.assertEquals ("line 1, column 2, offset 1", location.toString ());
                break;
            case VALUE_NUMBER:
                Assert.assertEquals ("1234", p.getString ());
                location = p.getLocation ();
                Assert.assertEquals ("line 1, column 10, offset 9", location.toString ());
                break;
            default:
                break;
        }
    }
    p.close ();
}
项目:cookjson    文件:TextJsonParserTest.java   
@Test
public void testLocation3 ()
{
    String json = "{\"abc\\t\" : \"def\\t\\\"ghi\"}";

    TextJsonParser p = new TextJsonParser (new StringReader (json));
    JsonLocation location = null;
    while (p.hasNext ())
    {
        switch (p.next ())
        {
            case KEY_NAME:
                Assert.assertEquals ("abc\t", p.getString ());
                location = p.getLocation ();
                Assert.assertEquals ("line 1, column 2, offset 1", location.toString ());
                break;
            case VALUE_STRING:
                Assert.assertEquals ("def\t\"ghi", p.getString ());
                location = p.getLocation ();
                Assert.assertEquals ("line 1, column 12, offset 11", location.toString ());
                break;
            default:
                break;
        }
    }
    p.close ();
}
项目:hibiscus    文件:AbstractProblem.java   
@Override
public JsonLocation getLocation() {
    return location;
}
项目:hibiscus    文件:AbstractProblem.java   
@Override
public Problem setLocation(JsonLocation location) {
    this.location = location;
    return this;
}
项目:yasson    文件:JsonbRiParser.java   
@Override
public JsonLocation getLocation() {
    return jsonParser.getLocation();
}
项目:yasson    文件:UserDeserializerParser.java   
@Override
public JsonLocation getLocation() {
    return jsonbParser.getLocation();
}
项目:cookjson    文件:JsonStructureParser.java   
@Override
public JsonLocation getLocation ()
{
    return JsonLocationImpl.Unknown;
}
项目:cookjson    文件:TextJsonParser.java   
private JsonParsingException eofError ()
{
    JsonLocation location = getCurrentLocation ();
    return new JsonParsingException ("Parsing error at " + location.toString () + ": unexpected eof.", location);
}
项目:cookjson    文件:UTF8TextJsonParser.java   
private JsonParsingException eofError ()
{
    JsonLocation location = getCurrentLocation ();
    return new JsonParsingException ("Parsing error at " + location.toString () + ": unexpected eof.", location);
}
项目:cookjson    文件:BsonParser.java   
@Override
public JsonLocation getLocation ()
{
    return m_location;
}
项目:johnzon    文件:JsonStreamParserImpl.java   
@Override
public JsonLocation getLocation() {
    return createLocation();
}
项目:johnzon    文件:JsonStreamParserImpl.java   
private JsonParsingException uexc(final char c, final String message) {
    final JsonLocation location = createLocation();
    return new JsonParsingException("Unexpected character '" + c + "' (Codepoint: " + String.valueOf(c).codePointAt(0) + ") on "
            + location + ". Reason is [[" + message + "]]", location);
}
项目:johnzon    文件:JsonStreamParserImpl.java   
private JsonParsingException tmc() {
    final JsonLocation location = createLocation();
    return new JsonParsingException("Too many characters. Maximum string/number length of " + maxValueLength + " exceeded on "
            + location + ". Maybe increase org.apache.johnzon.max-string-length in jsonp factory properties or system properties.", location);
}
项目:johnzon    文件:JsonStreamParserImpl.java   
private JsonParsingException uexio(final IOException e) {
    final JsonLocation location = createLocation();
    return new JsonParsingException("Unexpected IO exception on " + location, e, location);
}
项目:johnzon    文件:JsonStreamParserImpl.java   
private JsonParsingException cust(final String message) {
    final JsonLocation location = createLocation();
    return new JsonParsingException("General exception on " + location + ". Reason is [[" + message + "]]", location);
}
项目:johnzon    文件:JsonInMemoryParser.java   
@Override
public JsonLocation getLocation() { // no location for in memory parsers
    return JsonLocationImpl.UNKNOWN_LOCATION;
}
项目:johnzon    文件:JohnzonJsonParser.java   
@Override
public JsonLocation getLocation() {
    return jsonParser.getLocation();
}
项目:hibiscus    文件:Problem.java   
/**
 * Returns the location where this problem was found including line and column numbers
 * on the input JSON document.
 * @return {@link JsonLocation} object which holds the location of this problem.
 * @see JsonLocation
 */
JsonLocation getLocation();
项目:hibiscus    文件:Problem.java   
/**
 * Assigns the location where this problem was found.
 * @param location the location which indicates where this problem was found. 
 *                 {@code null} indicates the location is unknown.
 * @return this problem.
 */
Problem setLocation(JsonLocation location);