EMMA Coverage Report (generated Thu May 22 12:08:10 CDT 2014)
[all classes][org.springframework.batch.item.file.separator]

COVERAGE SUMMARY FOR SOURCE FILE [JsonRecordSeparatorPolicy.java]

nameclass, %method, %block, %line, %
JsonRecordSeparatorPolicy.java100% (1/1)100% (2/2)100% (19/19)100% (3/3)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class JsonRecordSeparatorPolicy100% (1/1)100% (2/2)100% (19/19)100% (3/3)
JsonRecordSeparatorPolicy (): void 100% (1/1)100% (3/3)100% (1/1)
isEndOfRecord (String): boolean 100% (1/1)100% (16/16)100% (2/2)

1/*
2 * Copyright 2006-2007 the original author or authors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 
17package org.springframework.batch.item.file.separator;
18 
19import org.springframework.util.StringUtils;
20 
21/**
22 * JSON-based record separator. Waits for a valid JSON object before returning a
23 * complete line. A valid object has balanced braces ({}), possibly nested, and
24 * ends with a closing brace. This separator can be used to split a stream into
25 * JSON objects, even if those objects are spread over multiple lines, e.g.
26 * 
27 * <pre>
28 * {"foo": "bar",
29 *  "value": { "spam": 2 }}
30 *  {"foo": "rab",
31 *  "value": { "spam": 3, "foo": "bar" }}
32 * </pre>
33 * 
34 * @author Dave Syer
35 * 
36 */
37public class JsonRecordSeparatorPolicy extends SimpleRecordSeparatorPolicy {
38 
39        /**
40         * True if the line can be parsed to a JSON object.
41         * 
42         * @see RecordSeparatorPolicy#isEndOfRecord(String)
43         */
44    @Override
45        public boolean isEndOfRecord(String line) {
46                return StringUtils.countOccurrencesOf(line, "{") == StringUtils.countOccurrencesOf(line, "}")
47                                && line.trim().endsWith("}");
48        }
49 
50}

[all classes][org.springframework.batch.item.file.separator]
EMMA 2.0.5312 (C) Vladimir Roubtsov