[OLINGO-1391]Code Improvements

This commit is contained in:
ramya vasanth 2019-09-12 15:24:46 +05:30
parent 7f3f9c5261
commit 7049f4ebf0
70 changed files with 308 additions and 372 deletions

View File

@ -783,9 +783,6 @@ public class Services {
} else {
jsonSerializer.write(writer, container);
}
writer.flush();
writer.close();
return xml.createResponse(
location,
new ByteArrayInputStream(content.toByteArray()),

View File

@ -122,8 +122,7 @@ public class FSManager {
content.reset();
new JsonSerializer(true, ContentType.JSON_FULL_METADATA).write(writer, container);
writer.flush();
putInMemory(new ByteArrayInputStream(content.toByteArray()), getAbsolutePath(relativePath, Accept.JSON_FULLMETA));
}

View File

@ -107,7 +107,7 @@ public class ClientLink extends ClientItem implements ClientAnnotatable {
*/
private String mediaETag;
private final List<ClientAnnotation> annotations = new ArrayList<ClientAnnotation>();
private final List<ClientAnnotation> annotations = new ArrayList<>();
/**
* Constructor.

View File

@ -25,13 +25,13 @@ import java.util.Map;
public class ClientServiceDocument {
private final Map<String, URI> entitySets = new HashMap<String, URI>();
private final Map<String, URI> entitySets = new HashMap<>();
private final Map<String, URI> functionImports = new HashMap<String, URI>();
private final Map<String, URI> functionImports = new HashMap<>();
private final Map<String, URI> singletons = new HashMap<String, URI>();
private final Map<String, URI> singletons = new HashMap<>();
private final Map<String, URI> relatedServiceDocuments = new HashMap<String, URI>();
private final Map<String, URI> relatedServiceDocuments = new HashMap<>();
public Map<String, URI> getEntitySets() {
return entitySets;

View File

@ -62,7 +62,7 @@ public class ConfigurationImpl implements Configuration {
public static final int DEFAULT_BUFFER_SIZE = 4 * 1024 * 1024; // 4MB
private final Map<String, Object> CONF = new HashMap<String, Object>();
private final Map<String, Object> CONF = new HashMap<>();
private transient ExecutorService executor = createExecutor(10);

View File

@ -72,12 +72,7 @@ public final class ODataErrorResponseChecker {
}
}
}
} catch (final RuntimeException e) {
LOG.warn("Error deserializing error response", e);
error = getGenericError(
statusLine.getStatusCode(),
statusLine.getReasonPhrase());
} catch (final ODataDeserializerException e) {
} catch (final RuntimeException | ODataDeserializerException e) {
LOG.warn("Error deserializing error response", e);
error = getGenericError(
statusLine.getStatusCode(),

View File

@ -29,7 +29,7 @@ public class ODataHeadersImpl implements ODataHeaders {
/**
* OData request/response header key/value pairs.
*/
private final Map<String, String> headers = new TreeMap<String, String>(String.CASE_INSENSITIVE_ORDER);
private final Map<String, String> headers = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
@Override
public ODataHeaders setHeader(final String name, final String value) {

View File

@ -36,7 +36,7 @@ public class AsyncRequestFactoryImpl implements AsyncRequestFactory {
@Override
public <R extends ODataResponse> AsyncRequestWrapper<R> getAsyncRequestWrapper(final ODataRequest odataRequest) {
return new AsyncRequestWrapperImpl<R>(client, odataRequest);
return new AsyncRequestWrapperImpl<>(client, odataRequest);
}
@Override

View File

@ -95,12 +95,10 @@ public class AsyncRequestWrapperImpl<R extends ODataResponse> extends AbstractRe
this.request = odataClient.getConfiguration().getHttpUriRequestFactory().create(method, this.uri);
if (request instanceof HttpEntityEnclosingRequestBase) {
if (odataRequest instanceof AbstractODataBasicRequest) {
AbstractODataBasicRequest<?> br = (AbstractODataBasicRequest<?>) odataRequest;
HttpEntityEnclosingRequestBase httpRequest = ((HttpEntityEnclosingRequestBase) request);
httpRequest.setEntity(new InputStreamEntity(br.getPayload(), -1));
}
if (request instanceof HttpEntityEnclosingRequestBase && odataRequest instanceof AbstractODataBasicRequest) {
AbstractODataBasicRequest<?> br = (AbstractODataBasicRequest<?>) odataRequest;
HttpEntityEnclosingRequestBase httpRequest = ((HttpEntityEnclosingRequestBase) request);
httpRequest.setEntity(new InputStreamEntity(br.getPayload(), -1));
}
}

View File

@ -48,7 +48,7 @@ public abstract class AbstractODataBatchRequest<V extends ODataResponse, T exten
/**
* Expected batch response items.
*/
protected final List<ODataBatchResponseItem> expectedResItems = new ArrayList<ODataBatchResponseItem>();
protected final List<ODataBatchResponseItem> expectedResItems = new ArrayList<>();
/**
* Constructor.

View File

@ -41,7 +41,7 @@ public abstract class AbstractODataBatchResponseItem implements ODataBatchRespon
/**
* Expected OData responses for the current batch response item.
*/
protected final Map<String, ODataResponse> responses = new HashMap<String, ODataResponse>();
protected final Map<String, ODataResponse> responses = new HashMap<>();
/**
* Expected OData responses iterator.

View File

@ -166,7 +166,7 @@ public class ODataBatchUtilities {
*/
public static Map<String, Collection<String>> readHeaders(final ODataBatchLineIterator iterator) {
final Map<String, Collection<String>> target =
new TreeMap<String, Collection<String>>(String.CASE_INSENSITIVE_ORDER);
new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
readHeaders(iterator, target);
return target;
@ -214,7 +214,7 @@ public class ODataBatchUtilities {
if (targetMap.containsKey(key)) {
value = targetMap.get(key);
} else {
value = new HashSet<String>();
value = new HashSet<>();
targetMap.put(key, value);
}
value.add(headerLine.substring(sep + 1, headerLine.length()).trim());
@ -262,7 +262,7 @@ public class ODataBatchUtilities {
final Matcher matcher = RESPONSE_PATTERN.matcher(line.trim());
if (matcher.matches()) {
return new AbstractMap.SimpleEntry<Integer, String>(Integer.valueOf(matcher.group(1)), matcher.group(2));
return new AbstractMap.SimpleEntry<>(Integer.valueOf(matcher.group(1)), matcher.group(2));
}
}
@ -280,7 +280,7 @@ public class ODataBatchUtilities {
final ODataBatchLineIterator iterator, final String boundary) {
final Map<String, Collection<String>> headers =
new TreeMap<String, Collection<String>>(String.CASE_INSENSITIVE_ORDER);
new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
final String line = ODataBatchUtilities.readBatchPart(new ODataBatchController(iterator, boundary), true);

View File

@ -56,7 +56,7 @@ public class CUDRequestFactoryImpl implements CUDRequestFactory {
public <E extends ClientEntity> ODataEntityCreateRequest<E> getEntityCreateRequest(
final URI targetURI, final E entity) {
return new ODataEntityCreateRequestImpl<E>(client, targetURI, entity);
return new ODataEntityCreateRequestImpl<>(client, targetURI, entity);
}
@Override
@ -66,10 +66,10 @@ public class CUDRequestFactoryImpl implements CUDRequestFactory {
final ODataEntityUpdateRequest<E> req;
if (client.getConfiguration().isUseXHTTPMethod()) {
req = new ODataEntityUpdateRequestImpl<E>(client, HttpMethod.POST, targetURI, changes);
req = new ODataEntityUpdateRequestImpl<>(client, HttpMethod.POST, targetURI, changes);
req.setXHTTPMethod(type.getMethod().name());
} else {
req = new ODataEntityUpdateRequestImpl<E>(client, type.getMethod(), targetURI, changes);
req = new ODataEntityUpdateRequestImpl<>(client, type.getMethod(), targetURI, changes);
}
return req;
@ -86,10 +86,10 @@ public class CUDRequestFactoryImpl implements CUDRequestFactory {
final ODataEntityUpdateRequest<E> req;
if (client.getConfiguration().isUseXHTTPMethod()) {
req = new ODataEntityUpdateRequestImpl<E>(client, HttpMethod.POST, entity.getEditLink(), entity);
req = new ODataEntityUpdateRequestImpl<>(client, HttpMethod.POST, entity.getEditLink(), entity);
req.setXHTTPMethod(type.getMethod().name());
} else {
req = new ODataEntityUpdateRequestImpl<E>(client, type.getMethod(), entity.getEditLink(), entity);
req = new ODataEntityUpdateRequestImpl<>(client, type.getMethod(), entity.getEditLink(), entity);
}
return req;
@ -189,7 +189,7 @@ public class CUDRequestFactoryImpl implements CUDRequestFactory {
public <E extends ClientEntity> ODataMediaEntityCreateRequest<E> getMediaEntityCreateRequest(
final URI targetURI, final InputStream media) {
return new ODataMediaEntityCreateRequestImpl<E>(client, targetURI, media);
return new ODataMediaEntityCreateRequestImpl<>(client, targetURI, media);
}
@Override
@ -213,10 +213,10 @@ public class CUDRequestFactoryImpl implements CUDRequestFactory {
final ODataMediaEntityUpdateRequest<E> req;
if (client.getConfiguration().isUseXHTTPMethod()) {
req = new ODataMediaEntityUpdateRequestImpl<E>(client, HttpMethod.POST, URIUtils.addValueSegment(editURI), media);
req = new ODataMediaEntityUpdateRequestImpl<>(client, HttpMethod.POST, URIUtils.addValueSegment(editURI), media);
req.setXHTTPMethod(HttpMethod.PUT.name());
} else {
req = new ODataMediaEntityUpdateRequestImpl<E>(client, HttpMethod.PUT, URIUtils.addValueSegment(editURI), media);
req = new ODataMediaEntityUpdateRequestImpl<>(client, HttpMethod.PUT, URIUtils.addValueSegment(editURI), media);
}
return req;
@ -241,7 +241,7 @@ public class CUDRequestFactoryImpl implements CUDRequestFactory {
final URI reference) {
final URI contextURI = client.newURIBuilder(serviceRoot.toASCIIString()).appendMetadataSegment()
.appendRefSegment().build();
ResWrap<URI> wrappedPayload = new ResWrap<URI>(contextURI, null, reference);
ResWrap<URI> wrappedPayload = new ResWrap<>(contextURI, null, reference);
return new ODataReferenceAddingRequestImpl(client, HttpMethod.POST, targetURI, wrappedPayload);
}
@ -251,7 +251,7 @@ public class CUDRequestFactoryImpl implements CUDRequestFactory {
final URI reference) {
// See OData Protocol 11.4.6.3
final URI contextURI = client.newURIBuilder(serviceRoot.toASCIIString()).appendMetadataSegment().build();
ResWrap<URI> wrappedPayload = new ResWrap<URI>(contextURI, null, reference);
ResWrap<URI> wrappedPayload = new ResWrap<>(contextURI, null, reference);
return new ODataReferenceAddingRequestImpl(client, HttpMethod.PUT, targetURI, wrappedPayload);
}

View File

@ -79,7 +79,7 @@ public abstract class AbstractODataInvokeRequest<T extends ClientInvokeResult>
super(odataClient, method, uri);
this.reference = reference;
this.parameters = new LinkedHashMap<String, ClientValue>();
this.parameters = new LinkedHashMap<>();
}
@Override

View File

@ -41,7 +41,7 @@ public class EdmEnabledInvokeRequestFactoryImpl extends AbstractEdmEnabledInvoke
final HttpMethod method, final URI uri, final Class<RES> resultRef,
final Map<String, ClientValue> parameters) {
final ODataInvokeRequest<RES> request = new ODataInvokeRequestImpl<RES>(edmClient, resultRef, method, uri);
final ODataInvokeRequest<RES> request = new ODataInvokeRequestImpl<>(edmClient, resultRef, method, uri);
if (parameters != null) {
request.setParameters(parameters);
}

View File

@ -40,7 +40,7 @@ public class InvokeRequestFactoryImpl extends AbstractInvokeRequestFactory {
final HttpMethod method, final URI uri, final Class<RES> resultRef,
final Map<String, ClientValue> parameters) {
final ODataInvokeRequest<RES> request = new ODataInvokeRequestImpl<RES>(client, resultRef, method, uri);
final ODataInvokeRequest<RES> request = new ODataInvokeRequestImpl<>(client, resultRef, method, uri);
if (parameters != null) {
request.setParameters(parameters);
}

View File

@ -74,7 +74,7 @@ public class ODataEntitySetIteratorRequestImpl<ES extends ClientEntitySet, E ext
@Override
public ClientEntitySetIterator<ES, E> getBody() {
if (entitySetIterator == null) {
entitySetIterator = new ClientEntitySetIterator<ES, E>(
entitySetIterator = new ClientEntitySetIterator<>(
odataClient, getRawResponse(), ContentType.parse(getContentType()));
}
return entitySetIterator;

View File

@ -93,27 +93,27 @@ public class RetrieveRequestFactoryImpl implements RetrieveRequestFactory {
@Override
public ODataEntitySetRequest<ClientEntitySet> getEntitySetRequest(final URI uri) {
return new ODataEntitySetRequestImpl<ClientEntitySet>(client, uri);
return new ODataEntitySetRequestImpl<>(client, uri);
}
@Override
public ODataEntitySetIteratorRequest<ClientEntitySet, ClientEntity> getEntitySetIteratorRequest(final URI uri) {
return new ODataEntitySetIteratorRequestImpl<ClientEntitySet, ClientEntity>(client, uri);
return new ODataEntitySetIteratorRequestImpl<>(client, uri);
}
@Override
public ODataEntityRequest<ClientSingleton> getSingletonRequest(final URI uri) {
return new ODataEntityRequestImpl<ClientSingleton>(client, uri);
return new ODataEntityRequestImpl<>(client, uri);
}
@Override
public ODataEntityRequest<ClientEntity> getEntityRequest(final URI uri) {
return new ODataEntityRequestImpl<ClientEntity>(client, uri);
return new ODataEntityRequestImpl<>(client, uri);
}
@Override
public ODataPropertyRequest<ClientProperty> getPropertyRequest(final URI uri) {
return new ODataPropertyRequestImpl<ClientProperty>(client, uri);
return new ODataPropertyRequestImpl<>(client, uri);
}
@Override

View File

@ -62,7 +62,7 @@ public abstract class AbstractODataStreamedRequest<V extends ODataResponse, T ex
* Wrapper for actual streamed request's future. This holds information about the HTTP request / response currently
* open.
*/
protected final Wrapper<Future<HttpResponse>> futureWrapper = new Wrapper<Future<HttpResponse>>();
protected final Wrapper<Future<HttpResponse>> futureWrapper = new Wrapper<>();
/**
* Constructor.

View File

@ -77,7 +77,7 @@ public abstract class AbstractODataResponse implements ODataResponse {
* Response headers.
*/
protected final Map<String, Collection<String>> headers =
new TreeMap<String, Collection<String>>(String.CASE_INSENSITIVE_ORDER);
new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
/**
* Response code.
@ -154,11 +154,7 @@ public abstract class AbstractODataResponse implements ODataResponse {
try {
this.payload = res.getEntity() == null ? null : res.getEntity().getContent();
this.inputContent = null;
} catch (final IllegalStateException e) {
HttpClientUtils.closeQuietly(res);
LOG.error("Error retrieving payload", e);
throw new ODataRuntimeException(e);
} catch (final IOException e) {
} catch (final IllegalStateException | IOException e) {
HttpClientUtils.closeQuietly(res);
LOG.error("Error retrieving payload", e);
throw new ODataRuntimeException(e);
@ -168,7 +164,7 @@ public abstract class AbstractODataResponse implements ODataResponse {
if (headers.containsKey(header.getName())) {
headerValues = headers.get(header.getName());
} else {
headerValues = new HashSet<String>();
headerValues = new HashSet<>();
headers.put(header.getName(), headerValues);
}

View File

@ -92,7 +92,7 @@ public class JSONServiceDocumentDeserializer extends JsonDeserializer {
}
}
return new ResWrap<ServiceDocument>(contextURL, metadataETag, serviceDocument);
return new ResWrap<>(contextURL, metadataETag, serviceDocument);
}
public ResWrap<ServiceDocument> toServiceDocument(final InputStream input) throws ODataDeserializerException {

View File

@ -30,10 +30,10 @@ public final class ServiceDocumentImpl implements ServiceDocument {
private String title;
private final List<ServiceDocumentItem> entitySets = new ArrayList<ServiceDocumentItem>();
private final List<ServiceDocumentItem> functionImports = new ArrayList<ServiceDocumentItem>();
private final List<ServiceDocumentItem> singletons = new ArrayList<ServiceDocumentItem>();
private final List<ServiceDocumentItem> relatedServiceDocuments = new ArrayList<ServiceDocumentItem>();
private final List<ServiceDocumentItem> entitySets = new ArrayList<>();
private final List<ServiceDocumentItem> functionImports = new ArrayList<>();
private final List<ServiceDocumentItem> singletons = new ArrayList<>();
private final List<ServiceDocumentItem> relatedServiceDocuments = new ArrayList<>();
private String metadata;

View File

@ -120,7 +120,7 @@ public class XMLServiceDocumentDeserializer extends JsonDeserializer {
? URIUtils.getURI(base, "$metadata")
: URIUtils.getURI(base, contextURL.toASCIIString())).toASCIIString());
return new ResWrap<ServiceDocument>(
return new ResWrap<>(
contextURL == null ? null : URIUtils.getURI(sdoc.getBaseURI(), contextURL),
metadataETag, sdoc);
}

View File

@ -57,7 +57,7 @@ public class ClientCollectionValueImpl<OV extends ClientValue> extends AbstractC
@Override
public Collection<Object> asJavaCollection() {
final List<Object> result = new ArrayList<Object>();
final List<Object> result = new ArrayList<>();
for (ClientValue value : values) {
if (value.isPrimitive()) {
result.add(value.asPrimitive().toValue());
@ -76,7 +76,7 @@ public class ClientCollectionValueImpl<OV extends ClientValue> extends AbstractC
/**
* Values.
*/
protected final List<OV> values = new ArrayList<OV>();
protected final List<OV> values = new ArrayList<>();
/**
* Adds a value to the collection.

View File

@ -36,19 +36,19 @@ public class ClientComplexValueImpl extends AbstractClientValue implements Clien
/**
* Navigation links (might contain in-line entities or entity sets).
*/
private final List<ClientLink> navigationLinks = new ArrayList<ClientLink>();
private final List<ClientLink> navigationLinks = new ArrayList<>();
/**
* Association links.
*/
private final List<ClientLink> associationLinks = new ArrayList<ClientLink>();
private final List<ClientLink> associationLinks = new ArrayList<>();
private final List<ClientAnnotation> annotations = new ArrayList<ClientAnnotation>();
private final List<ClientAnnotation> annotations = new ArrayList<>();
/**
* Complex type fields.
*/
private final Map<String, ClientProperty> fields = new LinkedHashMap<String, ClientProperty>();
private final Map<String, ClientProperty> fields = new LinkedHashMap<>();
/**
* Constructor.
@ -137,7 +137,7 @@ public class ClientComplexValueImpl extends AbstractClientValue implements Clien
@Override
public Map<String, Object> asJavaMap() {
final Map<String, Object> result = new LinkedHashMap<String, Object>();
final Map<String, Object> result = new LinkedHashMap<>();
for (Map.Entry<String, ClientProperty> entry : fields.entrySet()) {
Object value = null;
if (entry.getValue().hasPrimitiveValue()) {

View File

@ -28,11 +28,11 @@ import org.apache.olingo.client.api.domain.ClientDeltaLink;
public class ClientDeltaImpl extends ClientEntitySetImpl implements ClientDelta {
private final List<ClientDeletedEntity> deletedEntities = new ArrayList<ClientDeletedEntity>();
private final List<ClientDeletedEntity> deletedEntities = new ArrayList<>();
private final List<ClientDeltaLink> addedLinks = new ArrayList<ClientDeltaLink>();
private final List<ClientDeltaLink> addedLinks = new ArrayList<>();
private final List<ClientDeltaLink> deletedLinks = new ArrayList<ClientDeltaLink>();
private final List<ClientDeltaLink> deletedLinks = new ArrayList<>();
public ClientDeltaImpl() {
super();

View File

@ -34,7 +34,7 @@ public class ClientDeltaLinkImpl extends ClientItem implements ClientDeltaLink {
private URI target;
private final List<ClientAnnotation> annotations = new ArrayList<ClientAnnotation>();
private final List<ClientAnnotation> annotations = new ArrayList<>();
public ClientDeltaLinkImpl() {
super(null);

View File

@ -63,27 +63,27 @@ public class ClientEntityImpl extends AbstractClientPayload implements ClientEnt
*/
private URI editLink;
private final List<ClientProperty> properties = new ArrayList<ClientProperty>();
private final List<ClientProperty> properties = new ArrayList<>();
private final List<ClientAnnotation> annotations = new ArrayList<ClientAnnotation>();
private final List<ClientAnnotation> annotations = new ArrayList<>();
private final FullQualifiedName typeName;
/**
* Navigation links (might contain in-line entities or entity sets).
*/
private final List<ClientLink> navigationLinks = new ArrayList<ClientLink>();
private final List<ClientLink> navigationLinks = new ArrayList<>();
/**
* Association links.
*/
private final List<ClientLink> associationLinks = new ArrayList<ClientLink>();
private final List<ClientLink> associationLinks = new ArrayList<>();
/**
* Media edit links.
*/
private final List<ClientLink> mediaEditLinks = new ArrayList<ClientLink>();
private final List<ClientLink> mediaEditLinks = new ArrayList<>();
/**
* Operations (legacy, functions, actions).
*/
private final List<ClientOperation> operations = new ArrayList<ClientOperation>();
private final List<ClientOperation> operations = new ArrayList<>();
public ClientEntityImpl(final FullQualifiedName typeName) {
super(typeName == null ? null : typeName.toString());

View File

@ -44,11 +44,11 @@ public class ClientEntitySetImpl extends AbstractClientPayload implements Client
private URI deltaLink;
private final List<ClientEntity> entities = new ArrayList<ClientEntity>();
private final List<ClientEntity> entities = new ArrayList<>();
private final List<ClientAnnotation> annotations = new ArrayList<ClientAnnotation>();
private final List<ClientAnnotation> annotations = new ArrayList<>();
private final List<ClientOperation> operations = new ArrayList<ClientOperation>();
private final List<ClientOperation> operations = new ArrayList<>();
public ClientEntitySetImpl() {
super(null);

View File

@ -127,7 +127,7 @@ public class ClientObjectFactoryImpl implements ClientObjectFactory {
@Override
public ClientCollectionValue<ClientValue> newCollectionValue(final String typeName) {
return new ClientCollectionValueImpl<ClientValue>(typeName);
return new ClientCollectionValueImpl<>(typeName);
}
@Override

View File

@ -28,9 +28,9 @@ import org.apache.olingo.client.api.domain.ClientValue;
public final class ClientPropertyImpl extends ClientValuableImpl implements ClientProperty {
private final List<ClientAnnotation> annotations = new ArrayList<ClientAnnotation>();
private final List<ClientAnnotation> annotations = new ArrayList<>();
private final String name;
private final List<ClientOperation> operations = new ArrayList<ClientOperation>();
private final List<ClientOperation> operations = new ArrayList<>();
public ClientPropertyImpl(final String name, final ClientValue value) {
super(value);

View File

@ -174,7 +174,7 @@ public class ClientCsdlEdmProvider extends CsdlAbstractEdmProvider {
@Override
public List<CsdlAliasInfo> getAliasInfos() throws ODataException {
ArrayList<CsdlAliasInfo> aliasInfo = new ArrayList<CsdlAliasInfo>();
ArrayList<CsdlAliasInfo> aliasInfo = new ArrayList<>();
for (CsdlSchema schema : xmlSchemas.values()) {
if (schema.getAlias() != null) {
aliasInfo.add(new CsdlAliasInfo().setNamespace(schema.getNamespace()).setAlias(schema.getAlias()));
@ -185,7 +185,7 @@ public class ClientCsdlEdmProvider extends CsdlAbstractEdmProvider {
@Override
public List<CsdlSchema> getSchemas() throws ODataException {
return new ArrayList<CsdlSchema>(xmlSchemas.values());
return new ArrayList<>(xmlSchemas.values());
}
@Override

View File

@ -73,7 +73,7 @@ public class ClientCsdlXMLMetadata extends CsdlAbstractEdmItem implements Serial
@Override
public Map<String, CsdlSchema> getSchemaByNsOrAlias() {
final Map<String, CsdlSchema> schemaByNsOrAlias = new HashMap<String, CsdlSchema>();
final Map<String, CsdlSchema> schemaByNsOrAlias = new HashMap<>();
for (CsdlSchema schema : getSchemas()) {
schemaByNsOrAlias.put(schema.getNamespace(), schema);
if (StringUtils.isNotBlank(schema.getAlias())) {

View File

@ -38,7 +38,7 @@ class ClientCsdlDataServices extends CsdlAbstractEdmItem implements Serializable
private static final long serialVersionUID = 4200317286476885204L;
private final List<CsdlSchema> schemas = new ArrayList<CsdlSchema>();
private final List<CsdlSchema> schemas = new ArrayList<>();
private String dataServiceVersion;

View File

@ -39,7 +39,7 @@ public class ClientCsdlEdmx extends CsdlAbstractEdmItem implements Serializable,
private static final long serialVersionUID = -6293476719276092572L;
private final List<Reference> references = new ArrayList<Reference>();
private final List<Reference> references = new ArrayList<>();
private String version;

View File

@ -37,7 +37,7 @@ class ClientCsdlEntityKey extends CsdlAbstractEdmItem implements Serializable {
private static final long serialVersionUID = 520227585458843347L;
private final List<CsdlPropertyRef> propertyRefs = new ArrayList<CsdlPropertyRef>();
private final List<CsdlPropertyRef> propertyRefs = new ArrayList<>();
public List<CsdlPropertyRef> getPropertyRefs() {
return propertyRefs;

View File

@ -42,9 +42,9 @@ class ClientCsdlReference extends CsdlAbstractEdmItem implements Serializable, R
private static final long serialVersionUID = 7720274712545267654L;
private URI uri;
private final List<Include> includes = new ArrayList<Include>();
private final List<IncludeAnnotations> includeAnnotations = new ArrayList<IncludeAnnotations>();
private final List<CsdlAnnotation> annotations = new ArrayList<CsdlAnnotation>();
private final List<Include> includes = new ArrayList<>();
private final List<IncludeAnnotations> includeAnnotations = new ArrayList<>();
private final List<CsdlAnnotation> annotations = new ArrayList<>();
@Override
public List<CsdlAnnotation> getAnnotations() {

View File

@ -40,17 +40,17 @@ import org.apache.olingo.commons.api.edm.provider.CsdlStructuralType;
public class CsdlTypeValidator {
private Map<String, String> aliasNamespaceMap = new HashMap<String, String>();
private Map<String, String> aliasNamespaceMap = new HashMap<>();
private Map<FullQualifiedName, CsdlEntityContainer> csdlContainersMap =
new HashMap<FullQualifiedName, CsdlEntityContainer>();
new HashMap<>();
private Map<FullQualifiedName, CsdlEntityType> csdlEntityTypesMap =
new HashMap<FullQualifiedName, CsdlEntityType>();
new HashMap<>();
private Map<FullQualifiedName, CsdlComplexType> csdlComplexTypesMap =
new HashMap<FullQualifiedName, CsdlComplexType>();
new HashMap<>();
private Map<FullQualifiedName, CsdlAction> csdlActionsMap =
new HashMap<FullQualifiedName, CsdlAction>();
new HashMap<>();
private Map<FullQualifiedName, CsdlFunction> csdlFunctionsMap =
new HashMap<FullQualifiedName, CsdlFunction>();
new HashMap<>();
private static final String V4_SCHEMA_XMLNS =
"http://docs.oasis-open.org/odata/ns/edm";

View File

@ -37,15 +37,15 @@ import org.apache.olingo.commons.api.edm.FullQualifiedName;
public class EdmTypeValidator {
private Map<String, String> aliasNamespaceMap = new HashMap<String, String>();
private Map<String, String> aliasNamespaceMap = new HashMap<>();
private Map<FullQualifiedName, EdmEntityContainer> edmContainersMap =
new HashMap<FullQualifiedName, EdmEntityContainer>();
new HashMap<>();
private Map<FullQualifiedName, EdmEntityType> edmEntityTypesMap =
new HashMap<FullQualifiedName, EdmEntityType>();
new HashMap<>();
private Map<FullQualifiedName, EdmComplexType> edmComplexTypesMap =
new HashMap<FullQualifiedName, EdmComplexType>();
new HashMap<>();
private Map<FullQualifiedName, EdmFunction> edmFunctionsMap =
new HashMap<FullQualifiedName, EdmFunction>();
new HashMap<>();
/**
*

View File

@ -204,7 +204,7 @@ public class AtomDeserializer implements ODataDeserializer {
private void fromCollection(final Valuable valuable, final XMLEventReader reader, final StartElement start,
final EdmTypeInfo typeInfo) throws XMLStreamException, EdmPrimitiveTypeException {
List<Object> values = new ArrayList<Object>();
List<Object> values = new ArrayList<>();
ValueType valueType = ValueType.COLLECTION_PRIMITIVE;
final EdmTypeInfo type = typeInfo == null ? null :
@ -372,9 +372,7 @@ public class AtomDeserializer implements ODataDeserializer {
final XMLEventReader reader = getReader(input);
final StartElement start = skipBeforeFirstStartElement(reader);
return getContainer(start, property(reader, start));
} catch (XMLStreamException e) {
throw new ODataDeserializerException(e);
} catch (final EdmPrimitiveTypeException e) {
} catch (XMLStreamException | EdmPrimitiveTypeException e) {
throw new ODataDeserializerException(e);
}
}
@ -555,7 +553,7 @@ public class AtomDeserializer implements ODataDeserializer {
private void properties(final XMLEventReader reader, final StartElement start, final Entity entity)
throws XMLStreamException, EdmPrimitiveTypeException {
final Map<String, List<Annotation>> annotations = new HashMap<String, List<Annotation>>();
final Map<String, List<Annotation>> annotations = new HashMap<>();
boolean foundEndProperties = false;
while (reader.hasNext() && !foundEndProperties) {
@ -741,9 +739,7 @@ public class AtomDeserializer implements ODataDeserializer {
} else {
return getContainer(start, entity);
}
} catch (XMLStreamException e) {
throw new ODataDeserializerException(e);
} catch (final EdmPrimitiveTypeException e) {
} catch (XMLStreamException | EdmPrimitiveTypeException e) {
throw new ODataDeserializerException(e);
}
}
@ -829,9 +825,7 @@ public class AtomDeserializer implements ODataDeserializer {
final XMLEventReader reader = getReader(input);
final StartElement start = skipBeforeFirstStartElement(reader);
return getContainer(start, entitySet(reader, start));
} catch (XMLStreamException e) {
throw new ODataDeserializerException(e);
} catch (final EdmPrimitiveTypeException e) {
} catch (XMLStreamException | EdmPrimitiveTypeException e) {
throw new ODataDeserializerException(e);
}
}
@ -925,7 +919,7 @@ public class AtomDeserializer implements ODataDeserializer {
final Attribute context = start.getAttributeByName(contextQName);
final Attribute metadataETag = start.getAttributeByName(metadataEtagQName);
return new ResWrap<T>(
return new ResWrap<>(
context == null ? null : URI.create(context.getValue()),
metadataETag == null ? null : metadataETag.getValue(),
object);

View File

@ -49,7 +49,7 @@ class AtomGeoValueDeserializer {
private List<Point> points(final XMLEventReader reader, final StartElement start,
final EdmPrimitiveTypeKind type, final SRID srid) throws XMLStreamException {
final List<Point> result = new ArrayList<Point>();
final List<Point> result = new ArrayList<>();
boolean foundEndProperty = false;
while (reader.hasNext() && !foundEndProperty) {
@ -142,7 +142,7 @@ class AtomGeoValueDeserializer {
private MultiLineString multiLineString(final XMLEventReader reader, final StartElement start,
final EdmPrimitiveTypeKind type, final SRID srid) throws XMLStreamException {
final List<LineString> lineStrings = new ArrayList<LineString>();
final List<LineString> lineStrings = new ArrayList<>();
boolean foundEndProperty = false;
while (reader.hasNext() && !foundEndProperty) {
@ -163,7 +163,7 @@ class AtomGeoValueDeserializer {
private MultiPolygon multiPolygon(final XMLEventReader reader, final StartElement start,
final EdmPrimitiveTypeKind type, final SRID srid) throws XMLStreamException {
final List<Polygon> polygons = new ArrayList<Polygon>();
final List<Polygon> polygons = new ArrayList<>();
boolean foundEndProperty = false;
while (reader.hasNext() && !foundEndProperty) {
@ -184,7 +184,7 @@ class AtomGeoValueDeserializer {
private GeospatialCollection collection(final XMLEventReader reader, final StartElement start,
final EdmPrimitiveTypeKind type, final SRID srid) throws XMLStreamException {
final List<Geospatial> geospatials = new ArrayList<Geospatial>();
final List<Geospatial> geospatials = new ArrayList<>();
boolean foundEndCollection = false;
while (reader.hasNext() && !foundEndCollection) {

View File

@ -213,7 +213,7 @@ public class AtomSerializer implements ODataSerializer {
private void writeNavigationLinks(final XMLStreamWriter writer, final List<Link> links)
throws XMLStreamException, EdmPrimitiveTypeException {
final Map<String, List<String>> entitySetLinks = new HashMap<String, List<String>>();
final Map<String, List<String>> entitySetLinks = new HashMap<>();
for (Link link : links) {
@ -264,7 +264,7 @@ public class AtomSerializer implements ODataSerializer {
if (entitySetLinks.containsKey(link.getTitle())) {
uris = entitySetLinks.get(link.getTitle());
} else {
uris = new ArrayList<String>();
uris = new ArrayList<>();
entitySetLinks.put(link.getTitle(), uris);
}
if (link.getHref() != null) {
@ -637,9 +637,7 @@ public class AtomSerializer implements ODataSerializer {
} else if (obj instanceof Link) {
link(writer, (Link) obj);
}
} catch (final XMLStreamException e) {
throw new ODataSerializerException(e);
} catch (final EdmPrimitiveTypeException e) {
} catch (final XMLStreamException | EdmPrimitiveTypeException e) {
throw new ODataSerializerException(e);
}
}
@ -676,9 +674,7 @@ public class AtomSerializer implements ODataSerializer {
} else if (obj instanceof URI) {
reference(writer, (ResWrap<URI>) container);
}
} catch (final XMLStreamException e) {
throw new ODataSerializerException(e);
} catch (final EdmPrimitiveTypeException e) {
} catch (final XMLStreamException | EdmPrimitiveTypeException e) {
throw new ODataSerializerException(e);
}
}

View File

@ -149,7 +149,7 @@ public class ClientODataDeserializerImpl implements ClientODataDeserializer {
private List<List<String>> getAllSchemaNameSpace(InputStream inputStream)
throws ParserConfigurationException, SAXException, IOException{
List<List<String>> schemaNameSpaces = new ArrayList <List<String>>();
List<List<String>> schemaNameSpaces = new ArrayList <>();
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
dbFactory.setFeature(
@ -180,7 +180,7 @@ public class ClientODataDeserializerImpl implements ClientODataDeserializer {
for (int temp = 0; temp < nList.getLength(); temp++) {
Node nNode = nList.item(temp);
List<String> nameSpaces = new ArrayList <String>();
List<String> nameSpaces = new ArrayList <>();
if (nNode.getNodeType() == Node.ELEMENT_NODE) {
Element eElement = (Element) nNode;
NamedNodeMap attributes = eElement.getAttributes();
@ -212,16 +212,14 @@ public class ClientODataDeserializerImpl implements ClientODataDeserializer {
|| contentType.isCompatible(ContentType.APPLICATION_ATOM_XML) ?
new AtomDeserializer().delta(input) :
new JsonDeltaDeserializer(false).toDelta(input);
} catch (final XMLStreamException e) {
throw new ODataDeserializerException(e);
} catch (final EdmPrimitiveTypeException e) {
} catch (final XMLStreamException | EdmPrimitiveTypeException e) {
throw new ODataDeserializerException(e);
}
}
@Override
public List<CsdlSchema> fetchTermDefinitionSchema(List<InputStream> input) {
List<CsdlSchema> schemas = new ArrayList<CsdlSchema>();
List<CsdlSchema> schemas = new ArrayList<>();
try {
for (InputStream stream : input) {
ClientCsdlEdmx edmx = getXmlMapper().readValue(stream, ClientCsdlEdmx.class);

View File

@ -79,7 +79,7 @@ public class ContextURLParser {
} else {
firstToken = isEntity ? rest : StringUtils.substringBeforeLast(rest, ")") + ")";
final List<String> parts = new ArrayList<String>();
final List<String> parts = new ArrayList<>();
for (String split : firstToken.split("\\)/")) {
parts.add(split.replaceAll("\\(.*", ""));
}

View File

@ -86,7 +86,7 @@ public class JsonDeltaDeserializer extends JsonDeserializer {
}
}
return new ResWrap<Delta>(contextURL, null, delta);
return new ResWrap<>(contextURL, null, delta);
}
public ResWrap<Delta> toDelta(final InputStream input) throws ODataDeserializerException {

View File

@ -222,7 +222,7 @@ public class JsonDeserializer implements ODataDeserializer {
final EdmTypeInfo typeInfo = typeExpression == null ? null :
new EdmTypeInfo.Builder().setTypeExpression(typeExpression).build();
return new SimpleEntry<PropertyType, EdmTypeInfo>(type, typeInfo);
return new SimpleEntry<>(type, typeInfo);
}
private EdmPrimitiveTypeKind guessPrimitiveTypeKind(final JsonNode node) {
@ -299,7 +299,7 @@ public class JsonDeserializer implements ODataDeserializer {
throws IOException, EdmPrimitiveTypeException {
final ComplexValue complexValue = new ComplexValue();
final Set<String> toRemove = new HashSet<String>();
final Set<String> toRemove = new HashSet<>();
for (final Iterator<Map.Entry<String, JsonNode>> itor = node.fields(); itor.hasNext();) {
final Map.Entry<String, JsonNode> field = itor.next();
@ -314,7 +314,7 @@ public class JsonDeserializer implements ODataDeserializer {
private void fromCollection(final Valuable valuable, final Iterator<JsonNode> nodeItor, final EdmTypeInfo typeInfo,
final ObjectCodec codec) throws IOException, EdmPrimitiveTypeException {
final List<Object> values = new ArrayList<Object>();
final List<Object> values = new ArrayList<>();
ValueType valueType = ValueType.COLLECTION_PRIMITIVE;
final EdmTypeInfo type = typeInfo == null ? null

View File

@ -140,9 +140,9 @@ public class JsonEntityDeserializer extends JsonDeserializer {
tree.remove(Constants.JSON_MEDIA_ETAG);
}
final Set<String> toRemove = new HashSet<String>();
final Set<String> toRemove = new HashSet<>();
final Map<String, List<Annotation>> annotations = new HashMap<String, List<Annotation>>();
final Map<String, List<Annotation>> annotations = new HashMap<>();
for (final Iterator<Map.Entry<String, JsonNode>> itor = tree.fields(); itor.hasNext();) {
final Map.Entry<String, JsonNode> field = itor.next();
final Matcher customAnnotation = CUSTOM_ANNOTATION.matcher(field.getKey());
@ -236,7 +236,7 @@ public class JsonEntityDeserializer extends JsonDeserializer {
throw new IOException(e);
}
return new ResWrap<Entity>(contextURL, metadataETag, entity);
return new ResWrap<>(contextURL, metadataETag, entity);
}
private Link getOrCreateMediaLink(final Entity entity, final String name) {

View File

@ -101,7 +101,7 @@ public class JsonEntitySetDeserializer extends JsonDeserializer {
}
tree.remove(Constants.VALUE);
}
final Set<String> toRemove = new HashSet<String>();
final Set<String> toRemove = new HashSet<>();
// any remaining entry is supposed to be an annotation or is ignored
for (final Iterator<Map.Entry<String, JsonNode>> itor = tree.fields(); itor.hasNext();) {
final Map.Entry<String, JsonNode> field = itor.next();
@ -127,6 +127,6 @@ public class JsonEntitySetDeserializer extends JsonDeserializer {
}
}
tree.remove(toRemove);
return new ResWrap<EntityCollection>(contextURL, metadataETag, entitySet);
return new ResWrap<>(contextURL, metadataETag, entitySet);
}
}

View File

@ -65,7 +65,7 @@ class JsonGeoValueDeserializer {
final MultiPoint multiPoint;
if (itor.hasNext()) {
final List<Point> points = new ArrayList<Point>();
final List<Point> points = new ArrayList<>();
while (itor.hasNext()) {
final Iterator<JsonNode> mpItor = itor.next().elements();
points.add(point(mpItor, type, srid));
@ -82,7 +82,7 @@ class JsonGeoValueDeserializer {
final LineString lineString;
if (itor.hasNext()) {
final List<Point> points = new ArrayList<Point>();
final List<Point> points = new ArrayList<>();
while (itor.hasNext()) {
final Iterator<JsonNode> mpItor = itor.next().elements();
points.add(point(mpItor, type, srid));
@ -101,7 +101,7 @@ class JsonGeoValueDeserializer {
final MultiLineString multiLineString;
if (itor.hasNext()) {
final List<LineString> lineStrings = new ArrayList<LineString>();
final List<LineString> lineStrings = new ArrayList<>();
while (itor.hasNext()) {
final Iterator<JsonNode> mlsItor = itor.next().elements();
lineStrings.add(lineString(mlsItor, type, srid));
@ -119,7 +119,7 @@ class JsonGeoValueDeserializer {
if (itor.hasNext()) {
final Iterator<JsonNode> extItor = itor.next().elements();
if (extItor.hasNext()) {
extPoints = new ArrayList<Point>();
extPoints = new ArrayList<>();
while (extItor.hasNext()) {
final Iterator<JsonNode> mpItor = extItor.next().elements();
extPoints.add(point(mpItor, type, srid));
@ -131,7 +131,7 @@ class JsonGeoValueDeserializer {
while (itor.hasNext()) {
final Iterator<JsonNode> intItor = itor.next().elements();
if (intItor.hasNext()) {
List<Point> intPoints = new ArrayList<Point>();
List<Point> intPoints = new ArrayList<>();
while (intItor.hasNext()) {
final Iterator<JsonNode> mpItor = intItor.next().elements();
intPoints.add(point(mpItor, type, srid));
@ -148,7 +148,7 @@ class JsonGeoValueDeserializer {
final MultiPolygon multiPolygon;
if (itor.hasNext()) {
final List<Polygon> polygons = new ArrayList<Polygon>();
final List<Polygon> polygons = new ArrayList<>();
while (itor.hasNext()) {
final Iterator<JsonNode> mpItor = itor.next().elements();
polygons.add(polygon(mpItor, type, srid));
@ -167,7 +167,7 @@ class JsonGeoValueDeserializer {
final GeospatialCollection collection;
if (itor.hasNext()) {
final List<Geospatial> geospatials = new ArrayList<Geospatial>();
final List<Geospatial> geospatials = new ArrayList<>();
while (itor.hasNext()) {
final JsonNode geo = itor.next();

View File

@ -61,7 +61,7 @@ public class JsonODataErrorDeserializer extends JsonDeserializer {
error.setTarget(errorNode.get(Constants.ERROR_TARGET).textValue());
}
if (errorNode.hasNonNull(Constants.ERROR_DETAILS)) {
List<ODataErrorDetail> details = new ArrayList<ODataErrorDetail>();
List<ODataErrorDetail> details = new ArrayList<>();
JsonODataErrorDetailDeserializer detailDeserializer = new JsonODataErrorDetailDeserializer(serverMode);
for (JsonNode jsonNode : errorNode.get(Constants.ERROR_DETAILS)) {
details.add(detailDeserializer.doDeserialize(jsonNode.traverse(parser.getCodec()))
@ -71,7 +71,7 @@ public class JsonODataErrorDeserializer extends JsonDeserializer {
error.setDetails(details);
}
if (errorNode.hasNonNull(Constants.ERROR_INNERERROR)) {
HashMap<String, String> innerErrorMap = new HashMap<String, String>();
HashMap<String, String> innerErrorMap = new HashMap<>();
final JsonNode innerError = errorNode.get(Constants.ERROR_INNERERROR);
for (final Iterator<String> itor = innerError.fieldNames(); itor.hasNext();) {
final String keyTmp = itor.next();

View File

@ -53,6 +53,6 @@ public class JsonODataErrorDetailDeserializer extends JsonDeserializer {
error.setTarget(errorNode.get(Constants.ERROR_TARGET).textValue());
}
return new ResWrap<ODataErrorDetail>((URI) null, null, error);
return new ResWrap<>((URI) null, null, error);
}
}

View File

@ -96,7 +96,7 @@ public class JsonPropertyDeserializer extends JsonDeserializer {
tree.remove(Constants.VALUE);
}
Set<String> toRemove = new HashSet<String>();
Set<String> toRemove = new HashSet<>();
// any remaining entry is supposed to be an annotation or is ignored
for (final Iterator<Map.Entry<String, JsonNode>> itor = tree.fields(); itor.hasNext();) {
final Map.Entry<String, JsonNode> field = itor.next();
@ -122,6 +122,6 @@ public class JsonPropertyDeserializer extends JsonDeserializer {
}
}
tree.remove(toRemove);
return new ResWrap<Property>(contextURL, metadataETag, property);
return new ResWrap<>(contextURL, metadataETag, property);
}
}

View File

@ -77,8 +77,7 @@ public class JsonSerializer implements ODataSerializer {
@Override
public <T> void write(final Writer writer, final T obj) throws ODataSerializerException {
try {
final JsonGenerator json = new JsonFactory().createGenerator(writer);
try (final JsonGenerator json = new JsonFactory().createGenerator(writer)) {
if (obj instanceof EntityCollection) {
new JsonEntitySetSerializer(serverMode, contentType).doSerialize((EntityCollection) obj, json);
} else if (obj instanceof Entity) {
@ -89,9 +88,7 @@ public class JsonSerializer implements ODataSerializer {
link((Link) obj, json);
}
json.flush();
} catch (final IOException e) {
throw new ODataSerializerException(e);
} catch (final EdmPrimitiveTypeException e) {
} catch (final IOException | EdmPrimitiveTypeException e) {
throw new ODataSerializerException(e);
}
}
@ -111,8 +108,7 @@ public class JsonSerializer implements ODataSerializer {
@Override
public <T> void write(final Writer writer, final ResWrap<T> container) throws ODataSerializerException {
final T obj = container == null ? null : container.getPayload();
try {
final JsonGenerator json = new JsonFactory().createGenerator(writer);
try (final JsonGenerator json = new JsonFactory().createGenerator(writer)) {
if (obj instanceof EntityCollection) {
new JsonEntitySetSerializer(serverMode, contentType).doContainerSerialize(
(ResWrap<EntityCollection>) container, json);
@ -126,9 +122,7 @@ public class JsonSerializer implements ODataSerializer {
reference((ResWrap<URI>) container, json);
}
json.flush();
} catch (final IOException e) {
throw new ODataSerializerException(e);
} catch (final EdmPrimitiveTypeException e) {
} catch (final IOException | EdmPrimitiveTypeException e) {
throw new ODataSerializerException(e);
}
}
@ -152,7 +146,7 @@ public class JsonSerializer implements ODataSerializer {
protected void clientLinks(final Linked linked, final JsonGenerator jgen)
throws IOException, EdmPrimitiveTypeException {
final Map<String, List<String>> entitySetLinks = new HashMap<String, List<String>>();
final Map<String, List<String>> entitySetLinks = new HashMap<>();
for (Link link : linked.getNavigationLinks()) {
for (Annotation annotation : link.getAnnotations()) {
valuable(jgen, annotation, link.getTitle() + "@" + annotation.getTerm());
@ -163,7 +157,7 @@ public class JsonSerializer implements ODataSerializer {
if (entitySetLinks.containsKey(link.getTitle())) {
uris = entitySetLinks.get(link.getTitle());
} else {
uris = new ArrayList<String>();
uris = new ArrayList<>();
entitySetLinks.put(link.getTitle(), uris);
}
if (link.getHref() != null && !link.getHref().isEmpty()) {

View File

@ -343,7 +343,7 @@ public class ODataBinderImpl implements ODataBinder {
} else if (value.isPrimitive()) {
valueResource = value.asPrimitive().toValue();
} else if (value.isComplex()) {
List<Property> complexProperties = new ArrayList<Property>();
List<Property> complexProperties = new ArrayList<>();
for (final ClientProperty propertyValue : value.asComplex()) {
complexProperties.add(getProperty(propertyValue));
}
@ -356,7 +356,7 @@ public class ODataBinderImpl implements ODataBinder {
} else if (value.isCollection()) {
final ClientCollectionValue<? extends ClientValue> _value = value.asCollection();
ArrayList<Object> lcValueResource = new ArrayList<Object>();
ArrayList<Object> lcValueResource = new ArrayList<>();
for (final ClientValue collectionValue : _value) {
lcValueResource.add(getValue(collectionValue));
@ -703,7 +703,7 @@ public class ODataBinderImpl implements ODataBinder {
entity.setMediaETag(resource.getPayload().getMediaETag());
}
Map<String, Integer> countMap = new HashMap<String, Integer>();
Map<String, Integer> countMap = new HashMap<>();
for (final Property property : resource.getPayload().getProperties()) {
EdmType propertyType = null;
if (edmType instanceof EdmEntityType) {

View File

@ -44,11 +44,11 @@ public class ODataMetadataValidationImpl implements ODataMetadataValidation {
@Override
public void validateMetadata(Edm edm) {
Map<FullQualifiedName, EdmEntityType> edmEntityTypesMap = new HashMap<FullQualifiedName, EdmEntityType>();
Map<FullQualifiedName, EdmComplexType> edmComplexTypesMap = new HashMap<FullQualifiedName, EdmComplexType>();
Map<FullQualifiedName, EdmFunction> edmFunctionsMap = new HashMap<FullQualifiedName, EdmFunction>();
Map<FullQualifiedName, EdmEntityContainer> edmContainersMap = new HashMap<FullQualifiedName, EdmEntityContainer>();
Map<String, String> aliasNamespaceMap = new HashMap<String, String>();
Map<FullQualifiedName, EdmEntityType> edmEntityTypesMap = new HashMap<>();
Map<FullQualifiedName, EdmComplexType> edmComplexTypesMap = new HashMap<>();
Map<FullQualifiedName, EdmFunction> edmFunctionsMap = new HashMap<>();
Map<FullQualifiedName, EdmEntityContainer> edmContainersMap = new HashMap<>();
Map<String, String> aliasNamespaceMap = new HashMap<>();
List<EdmSchema> edmSchemas = edm.getSchemas();
for (EdmSchema edmSchema : edmSchemas) {
List<EdmEntityType> edmEntityTypes = edmSchema.getEntityTypes();
@ -75,13 +75,13 @@ public class ODataMetadataValidationImpl implements ODataMetadataValidation {
@Override
public void validateMetadata(XMLMetadata xmlMetadata) {
Map<FullQualifiedName, CsdlEntityType> csdlEntityTypesMap = new HashMap<FullQualifiedName, CsdlEntityType>();
Map<FullQualifiedName, CsdlComplexType> csdlComplexTypesMap = new HashMap<FullQualifiedName, CsdlComplexType>();
Map<FullQualifiedName, CsdlAction> csdlActionsMap = new HashMap<FullQualifiedName, CsdlAction>();
Map<FullQualifiedName, CsdlFunction> csdlFunctionsMap = new HashMap<FullQualifiedName, CsdlFunction>();
Map<FullQualifiedName, CsdlEntityType> csdlEntityTypesMap = new HashMap<>();
Map<FullQualifiedName, CsdlComplexType> csdlComplexTypesMap = new HashMap<>();
Map<FullQualifiedName, CsdlAction> csdlActionsMap = new HashMap<>();
Map<FullQualifiedName, CsdlFunction> csdlFunctionsMap = new HashMap<>();
Map<FullQualifiedName, CsdlEntityContainer> csdlContainersMap =
new HashMap<FullQualifiedName, CsdlEntityContainer>();
Map<String, String> aliasNamespaceMap = new HashMap<String, String>();
new HashMap<>();
Map<String, String> aliasNamespaceMap = new HashMap<>();
List<CsdlSchema> csdlSchemas = xmlMetadata.getSchemas();
for (CsdlSchema csdlSchema : csdlSchemas) {
List<CsdlEntityType> csdlEntityTypes = csdlSchema.getEntityTypes();

View File

@ -93,7 +93,7 @@ public class ODataReaderImpl implements ODataReader {
try {
if (ClientEntitySetIterator.class.isAssignableFrom(reference)) {
res = new ResWrap<T>(
res = new ResWrap<>(
(URI) null,
null,
reference.cast(new ClientEntitySetIterator<ClientEntitySet, ClientEntity>(
@ -101,24 +101,24 @@ public class ODataReaderImpl implements ODataReader {
} else if (ClientEntitySet.class.isAssignableFrom(reference)) {
final ResWrap<EntityCollection> resource = client.getDeserializer(ContentType.parse(format))
.toEntitySet(src);
res = new ResWrap<T>(
res = new ResWrap<>(
resource.getContextURL(),
resource.getMetadataETag(),
reference.cast(client.getBinder().getODataEntitySet(resource)));
} else if (ClientEntity.class.isAssignableFrom(reference)) {
final ResWrap<Entity> container = client.getDeserializer(ContentType.parse(format)).toEntity(src);
res = new ResWrap<T>(
res = new ResWrap<>(
container.getContextURL(),
container.getMetadataETag(),
reference.cast(client.getBinder().getODataEntity(container)));
} else if (ClientProperty.class.isAssignableFrom(reference)) {
final ResWrap<Property> container = client.getDeserializer(ContentType.parse(format)).toProperty(src);
res = new ResWrap<T>(
res = new ResWrap<>(
container.getContextURL(),
container.getMetadataETag(),
reference.cast(client.getBinder().getODataProperty(container)));
} else if (ClientValue.class.isAssignableFrom(reference)) {
res = new ResWrap<T>(
res = new ResWrap<>(
(URI) null,
null,
reference.cast(client.getObjectFactory().newPrimitiveValueBuilder().
@ -127,19 +127,19 @@ public class ODataReaderImpl implements ODataReader {
setValue(IOUtils.toString(src)) // TODO: set correct value
.build()));
} else if (XMLMetadata.class.isAssignableFrom(reference)) {
res = new ResWrap<T>(
res = new ResWrap<>(
(URI) null,
null,
reference.cast(readMetadata(src)));
} else if (ClientServiceDocument.class.isAssignableFrom(reference)) {
final ResWrap<ServiceDocument> resource =
client.getDeserializer(ContentType.parse(format)).toServiceDocument(src);
res = new ResWrap<T>(
res = new ResWrap<>(
resource.getContextURL(),
resource.getMetadataETag(),
reference.cast(client.getBinder().getODataServiceDocument(resource.getPayload())));
} else if (ODataError.class.isAssignableFrom(reference)) {
res = new ResWrap<T>(
res = new ResWrap<>(
(URI) null,
null,
reference.cast(readError(src, ContentType.parse(format))));

View File

@ -82,22 +82,22 @@ public class URIBuilderImpl implements URIBuilder {
private final Configuration configuration;
protected final List<Segment> segments = new ArrayList<Segment>();
protected final List<Segment> segments = new ArrayList<>();
/**
* Insertion-order map of query options.
*/
protected final Map<String, String> queryOptions = new LinkedHashMap<String, String>();
protected final Map<String, String> queryOptions = new LinkedHashMap<>();
/**
* Insertion-order map of custom query options.
*/
protected final Map<String, String> customQueryOptions = new LinkedHashMap<String, String>();
protected final Map<String, String> customQueryOptions = new LinkedHashMap<>();
/**
* Insertion-order map of parameter aliases.
*/
protected final Map<String, String> parameters = new LinkedHashMap<String, String>();
protected final Map<String, String> parameters = new LinkedHashMap<>();
@Override
public URIBuilder addQueryOption(final QueryOption option, final String value) {
@ -301,7 +301,7 @@ public class URIBuilderImpl implements URIBuilder {
try {
if ((customQueryOptions.size() + queryOptions.size() + parameters.size()) > 0) {
segmentsBuilder.append("?");
List<NameValuePair> list1 = new LinkedList<NameValuePair>();
List<NameValuePair> list1 = new LinkedList<>();
for (Map.Entry<String, String> option : queryOptions.entrySet()) {
list1.add(new BasicNameValuePair("$" + option.getKey(), option.getValue()));
}
@ -372,7 +372,7 @@ public class URIBuilderImpl implements URIBuilder {
public URIBuilder appendKeySegment(final Map<String, Pair<EdmEnumType, String>> enumValues,
final Map<String, Object> segmentValues) {
final Map<String, Object> values = new LinkedHashMap<String, Object>();
final Map<String, Object> values = new LinkedHashMap<>();
for (Map.Entry<String, Pair<EdmEnumType, String>> entry : enumValues.entrySet()) {
values.put(entry.getKey(), entry.getValue().getKey().toUriLiteral(entry.getValue().getValue()));
}
@ -453,7 +453,7 @@ public class URIBuilderImpl implements URIBuilder {
@Override
public URIBuilder expandWithOptions(String expandItem, boolean pathRef,
boolean pathCount, Map<QueryOption, Object> options) {
final Map<String, Object> _options = new LinkedHashMap<String, Object>();
final Map<String, Object> _options = new LinkedHashMap<>();
for (Map.Entry<QueryOption, Object> entry : options.entrySet()) {
_options.put("$" + entry.getKey().toString(), entry.getValue());
}

View File

@ -257,9 +257,7 @@ public final class URIUtils {
? quoteString((String) obj, singleQuoteEscape)
: obj.toString();
}
} catch (final EdmPrimitiveTypeException e) {
value = obj.toString();
} catch (final UnsupportedEncodingException e) {
} catch (final EdmPrimitiveTypeException | UnsupportedEncodingException e) {
value = obj.toString();
}

View File

@ -26,7 +26,7 @@ import java.util.List;
*/
public abstract class Annotatable {
private final List<Annotation> annotations = new ArrayList<Annotation>();
private final List<Annotation> annotations = new ArrayList<>();
/**
* Get Annotations.

View File

@ -26,7 +26,7 @@ import java.util.List;
*/
public class ComplexValue extends Linked {
private final List<Property> value = new ArrayList<Property>();
private final List<Property> value = new ArrayList<>();
private String typeName;

View File

@ -129,21 +129,19 @@ public class ODataNettyHandlerImpl implements ODataNettyHandler {
* @param response
*/
static void copyContent(final ReadableByteChannel input, final HttpResponse response) {
WritableByteChannel output = null;
try {
ByteBuffer inBuffer = ByteBuffer.allocate(COPY_BUFFER_SIZE);
output = Channels.newChannel(new ByteBufOutputStream(((HttpContent)response).content()));
while (input.read(inBuffer) > 0) {
inBuffer.flip();
output.write(inBuffer);
inBuffer.clear();
try (WritableByteChannel output = Channels.newChannel(new ByteBufOutputStream(((HttpContent)response).content()))){
ByteBuffer inBuffer = ByteBuffer.allocate(COPY_BUFFER_SIZE);
while (input.read(inBuffer) > 0) {
inBuffer.flip();
output.write(inBuffer);
inBuffer.clear();
}
closeStream(output);
} catch (IOException e) {
throw new ODataRuntimeException("Error on reading request content", e);
} finally {
closeStream(input);
}
} catch (IOException e) {
throw new ODataRuntimeException("Error on reading request content", e);
} finally {
closeStream(input);
closeStream(output);
}
}
private static void closeStream(final Channel closeable) {

View File

@ -179,10 +179,8 @@ public class ODataHttpHandlerImpl implements ODataHttpHandler {
}
static void copyContent(final ReadableByteChannel input, final HttpServletResponse servletResponse) {
WritableByteChannel output = null;
try {
try (WritableByteChannel output = Channels.newChannel(servletResponse.getOutputStream());) {
ByteBuffer inBuffer = ByteBuffer.allocate(COPY_BUFFER_SIZE);
output = Channels.newChannel(servletResponse.getOutputStream());
while (input.read(inBuffer) > 0) {
inBuffer.flip();
output.write(inBuffer);
@ -192,7 +190,6 @@ public class ODataHttpHandlerImpl implements ODataHttpHandler {
throw new ODataRuntimeException("Error on reading request content", e);
} finally {
closeStream(input);
closeStream(output);
}
}

View File

@ -132,13 +132,10 @@ public class DebugResponseHelperImpl implements DebugResponseHelper {
private InputStream wrapInJson(final List<DebugTab> parts) throws IOException {
OutputStream outputStream = null;
try {
CircleStreamBuffer csb = new CircleStreamBuffer();
outputStream = csb.getOutputStream();
// Create JSON generator (the object mapper is necessary to write expression trees).
JsonGenerator gen = new ObjectMapper().getFactory().createGenerator(outputStream);
CircleStreamBuffer csb = new CircleStreamBuffer();
outputStream = csb.getOutputStream();
// Create JSON generator (the object mapper is necessary to write expression trees).
try (JsonGenerator gen = new ObjectMapper().getFactory().createGenerator(outputStream)) {
gen.writeStartObject();
DebugTab requestInfo = parts.get(0);
gen.writeFieldName(requestInfo.getName().toLowerCase(Locale.ROOT));
@ -159,8 +156,6 @@ public class DebugResponseHelperImpl implements DebugResponseHelper {
gen.writeEndObject();
gen.close();
outputStream.close();
return csb.getInputStream();
} finally {
if (outputStream != null) {

View File

@ -499,15 +499,14 @@ public class DebugTabUri implements DebugTab {
public void appendHtml(final Writer writer) throws IOException {
// factory for JSON generators (the object mapper is necessary to write expression trees)
final JsonFactory jsonFactory = new ObjectMapper().getFactory();
JsonGenerator json;
if (uriInfo.getKind() == UriInfoKind.resource) {
writer.append("<h2>Resource Path</h2>\n")
.append("<ul>\n<li class=\"json\">");
json = jsonFactory.createGenerator(writer).useDefaultPrettyPrinter();
appendURIResourceParts(json, uriInfo.getUriResourceParts());
json.close();
writer.append("\n</li>\n</ul>\n");
try (JsonGenerator json = jsonFactory.createGenerator(writer).useDefaultPrettyPrinter()) {
appendURIResourceParts(json, uriInfo.getUriResourceParts());
json.close();
writer.append("\n</li>\n</ul>\n");
}
} else if (uriInfo.getKind() == UriInfoKind.crossjoin) {
writer.append("<h2>Crossjoin EntitySet Names</h2>\n")
.append("<ul>\n");
@ -528,37 +527,41 @@ public class DebugTabUri implements DebugTab {
if (uriInfo.getSearchOption() != null) {
writer.append("<h2>Search Option</h2>\n")
.append("<ul>\n<li class=\"json\">");
json = jsonFactory.createGenerator(writer).useDefaultPrettyPrinter();
appendSearchJson(json, uriInfo.getSearchOption().getSearchExpression());
json.close();
writer.append("\n</li>\n</ul>\n");
try (JsonGenerator json = jsonFactory.createGenerator(writer).useDefaultPrettyPrinter()) {
appendSearchJson(json, uriInfo.getSearchOption().getSearchExpression());
json.close();
writer.append("\n</li>\n</ul>\n");
}
}
if (uriInfo.getFilterOption() != null) {
writer.append("<h2>Filter Option</h2>\n")
.append("<ul>\n<li class=\"json\">");
json = jsonFactory.createGenerator(writer).useDefaultPrettyPrinter();
appendExpressionJson(json, uriInfo.getFilterOption().getExpression());
json.close();
writer.append("\n</li>\n</ul>\n");
try (JsonGenerator json = jsonFactory.createGenerator(writer).useDefaultPrettyPrinter()) {
appendExpressionJson(json, uriInfo.getFilterOption().getExpression());
json.close();
writer.append("\n</li>\n</ul>\n");
}
}
if (uriInfo.getOrderByOption() != null) {
writer.append("<h2>OrderBy Option</h2>\n")
.append("<ul>\n<li class=\"json\">");
json = jsonFactory.createGenerator(writer).useDefaultPrettyPrinter();
appendOrderByItemsJson(json, uriInfo.getOrderByOption().getOrders());
json.close();
writer.append("\n</li>\n</ul>\n");
try (JsonGenerator json = jsonFactory.createGenerator(writer).useDefaultPrettyPrinter()) {
appendOrderByItemsJson(json, uriInfo.getOrderByOption().getOrders());
json.close();
writer.append("\n</li>\n</ul>\n");
}
}
if (uriInfo.getExpandOption() != null) {
writer.append("<h2>Expand Option</h2>\n")
.append("<ul>\n<li class=\"json\">");
json = jsonFactory.createGenerator(writer).useDefaultPrettyPrinter();
appendExpandedPropertiesJson(json, uriInfo.getExpandOption().getExpandItems());
json.close();
writer.append("\n</li>\n</ul>\n");
try (JsonGenerator json = jsonFactory.createGenerator(writer).useDefaultPrettyPrinter()) {
appendExpandedPropertiesJson(json, uriInfo.getExpandOption().getExpandItems());
json.close();
writer.append("\n</li>\n</ul>\n");
}
}
if (uriInfo.getSelectOption() != null) {
@ -573,10 +576,11 @@ public class DebugTabUri implements DebugTab {
if (uriInfo.getApplyOption() != null) {
writer.append("<h2>Apply Option</h2>\n")
.append("<ul>\n<li class=\"json\">");
json = jsonFactory.createGenerator(writer).useDefaultPrettyPrinter();
appendApplyItemsJson(json, uriInfo.getApplyOption().getApplyItems());
json.close();
writer.append("\n</li>\n</ul>\n");
try (JsonGenerator json = jsonFactory.createGenerator(writer).useDefaultPrettyPrinter()) {
appendApplyItemsJson(json, uriInfo.getApplyOption().getApplyItems());
json.close();
writer.append("\n</li>\n</ul>\n");
}
}
if (uriInfo.getCountOption() != null

View File

@ -84,12 +84,14 @@ public class AsyncResponseSerializer {
InputStream input = response.getContent();
if (input != null) {
ByteBuffer inBuffer = ByteBuffer.allocate(BUFFER_SIZE);
ReadableByteChannel ic = Channels.newChannel(input);
WritableByteChannel oc = Channels.newChannel(buffer);
while (ic.read(inBuffer) > 0) {
inBuffer.flip();
oc.write(inBuffer);
inBuffer.rewind();
try (ReadableByteChannel ic = Channels.newChannel(input)) {
try (WritableByteChannel oc = Channels.newChannel(buffer)) {
while (ic.read(inBuffer) > 0) {
inBuffer.flip();
oc.write(inBuffer);
inBuffer.rewind();
}
}
}
}
}

View File

@ -258,12 +258,14 @@ public class BatchResponseSerializer {
res.write(Channels.newChannel(output));
}
} else {
ReadableByteChannel ic = Channels.newChannel(response.getContent());
WritableByteChannel oc = Channels.newChannel(output);
while (ic.read(inBuffer) > 0) {
inBuffer.flip();
oc.write(inBuffer);
inBuffer.rewind();
try (WritableByteChannel oc = Channels.newChannel(output)) {
try (ReadableByteChannel ic = Channels.newChannel(response.getContent())) {
while (ic.read(inBuffer) > 0) {
inBuffer.flip();
oc.write(inBuffer);
inBuffer.rewind();
}
}
}
}
return output.toByteArray();

View File

@ -95,10 +95,10 @@ public class EdmAssistedJsonSerializer implements EdmAssistedSerializer {
contextURL).toASCIIString();
OutputStream outputStream = null;
SerializerException cachedException = null;
try {
CircleStreamBuffer buffer = new CircleStreamBuffer();
outputStream = buffer.getOutputStream();
JsonGenerator json = new JsonFactory().createGenerator(outputStream);
CircleStreamBuffer buffer = new CircleStreamBuffer();
outputStream = buffer.getOutputStream();
try (JsonGenerator json = new JsonFactory().createGenerator(outputStream)) {
if (obj instanceof AbstractEntityCollection) {
doSerialize(entityType, (AbstractEntityCollection) obj, contextURLString, metadataETag, json);
} else if (obj instanceof Entity) {
@ -108,7 +108,6 @@ public class EdmAssistedJsonSerializer implements EdmAssistedSerializer {
}
json.flush();
json.close();
outputStream.close();
return SerializerResultImpl.with().content(buffer.getInputStream()).build();
} catch (final IOException e) {
cachedException = new SerializerException(IO_EXCEPTION_TEXT, e, SerializerException.MessageKeys.IO_EXCEPTION);

View File

@ -89,28 +89,27 @@ public class JsonDeltaSerializerWithNavigations implements EdmDeltaSerializer {
OutputStream outputStream = null;
SerializerException cachedException = null;
boolean pagination = false;
try {
CircleStreamBuffer buffer = new CircleStreamBuffer();
outputStream = buffer.getOutputStream();
JsonGenerator json = new JsonFactory().createGenerator(outputStream);
json.writeStartObject();
try (JsonGenerator json = new JsonFactory().createGenerator(outputStream)) {
json.writeStartObject();
final ContextURL contextURL = checkContextURL(options == null ? null : options.getContextURL());
writeContextURL(contextURL, json);
final ContextURL contextURL = checkContextURL(options == null ? null : options.getContextURL());
writeContextURL(contextURL, json);
if (options != null && options.getCount() != null && options.getCount().getValue()) {
writeInlineCount(delta.getCount(), json);
}
json.writeFieldName(Constants.VALUE);
writeEntitySet(metadata, referencedEntityType, delta, options, json);
if (options != null && options.getCount() != null && options.getCount().getValue()) {
writeInlineCount(delta.getCount(), json);
}
json.writeFieldName(Constants.VALUE);
writeEntitySet(metadata, referencedEntityType, delta, options, json);
pagination = writeNextLink(delta, json);
writeDeltaLink(delta, json, pagination);
pagination = writeNextLink(delta, json);
writeDeltaLink(delta, json, pagination);
json.close();
outputStream.close();
return SerializerResultImpl.with().content(buffer.getInputStream()).build();
} catch (final IOException e) {
json.close();
return SerializerResultImpl.with().content(buffer.getInputStream()).build();
} catch (final IOException e) {
cachedException =
new SerializerException(IO_EXCEPTION_TEXT, e, SerializerException.MessageKeys.IO_EXCEPTION);
throw cachedException;

View File

@ -136,19 +136,17 @@ public class ODataJsonSerializer extends AbstractODataSerializer {
OutputStream outputStream = null;
SerializerException cachedException = null;
try {
CircleStreamBuffer buffer = new CircleStreamBuffer();
outputStream = buffer.getOutputStream();
JsonGenerator json = new JsonFactory().createGenerator(outputStream);
CircleStreamBuffer buffer = new CircleStreamBuffer();
outputStream = buffer.getOutputStream();
try (JsonGenerator json = new JsonFactory().createGenerator(outputStream)) {
new ServiceDocumentJsonSerializer(metadata, serviceRoot, isODataMetadataNone).writeServiceDocument(json);
json.close();
outputStream.close();
return SerializerResultImpl.with().content(buffer.getInputStream()).build();
} catch (final IOException e) {
cachedException =
new SerializerException(IO_EXCEPTION_TEXT, e, SerializerException.MessageKeys.IO_EXCEPTION);
throw cachedException;
cachedException =
new SerializerException(IO_EXCEPTION_TEXT, e, SerializerException.MessageKeys.IO_EXCEPTION);
throw cachedException;
} finally {
closeCircleStreamBufferOutput(outputStream, cachedException);
}
@ -159,14 +157,12 @@ public class ODataJsonSerializer extends AbstractODataSerializer {
OutputStream outputStream = null;
SerializerException cachedException = null;
try {
CircleStreamBuffer buffer = new CircleStreamBuffer();
outputStream = buffer.getOutputStream();
JsonGenerator json = new JsonFactory().createGenerator(outputStream);
CircleStreamBuffer buffer = new CircleStreamBuffer();
outputStream = buffer.getOutputStream();
try (JsonGenerator json = new JsonFactory().createGenerator(outputStream)) {
new MetadataDocumentJsonSerializer(serviceMetadata).writeMetadataDocument(json);
json.close();
outputStream.close();
return SerializerResultImpl.with().content(buffer.getInputStream()).build();
} catch (final IOException e) {
cachedException =
@ -181,14 +177,13 @@ public class ODataJsonSerializer extends AbstractODataSerializer {
public SerializerResult error(final ODataServerError error) throws SerializerException {
OutputStream outputStream = null;
SerializerException cachedException = null;
try {
CircleStreamBuffer buffer = new CircleStreamBuffer();
outputStream = buffer.getOutputStream();
JsonGenerator json = new JsonFactory().createGenerator(outputStream);
CircleStreamBuffer buffer = new CircleStreamBuffer();
outputStream = buffer.getOutputStream();
try (JsonGenerator json = new JsonFactory().createGenerator(outputStream)) {
new ODataErrorSerializer().writeErrorDocument(json, error);
json.close();
outputStream.close();
return SerializerResultImpl.with().content(buffer.getInputStream()).build();
} catch (final IOException e) {
cachedException =
@ -206,10 +201,10 @@ public class ODataJsonSerializer extends AbstractODataSerializer {
OutputStream outputStream = null;
SerializerException cachedException = null;
boolean pagination = false;
try {
CircleStreamBuffer buffer = new CircleStreamBuffer();
outputStream = buffer.getOutputStream();
JsonGenerator json = new JsonFactory().createGenerator(outputStream);
CircleStreamBuffer buffer = new CircleStreamBuffer();
outputStream = buffer.getOutputStream();
try (JsonGenerator json = new JsonFactory().createGenerator(outputStream)) {
json.writeStartObject();
final ContextURL contextURL = checkContextURL(options == null ? null : options.getContextURL());
@ -233,13 +228,8 @@ public class ODataJsonSerializer extends AbstractODataSerializer {
writeDeltaLink(entitySet, json, pagination);
json.close();
outputStream.close();
return SerializerResultImpl.with().content(buffer.getInputStream()).build();
} catch (final IOException e) {
cachedException =
new SerializerException(IO_EXCEPTION_TEXT, e, SerializerException.MessageKeys.IO_EXCEPTION);
throw cachedException;
} catch (DecoderException e) {
} catch (final IOException | DecoderException e) {
cachedException =
new SerializerException(IO_EXCEPTION_TEXT, e, SerializerException.MessageKeys.IO_EXCEPTION);
throw cachedException;
@ -286,11 +276,7 @@ public class ODataJsonSerializer extends AbstractODataSerializer {
writeNextLink(entitySet, json, pagination);
json.close();
} catch (final IOException e) {
cachedException =
new SerializerException(IO_EXCEPTION_TEXT, e, SerializerException.MessageKeys.IO_EXCEPTION);
throw cachedException;
} catch (DecoderException e) {
} catch (final IOException | DecoderException e) {
cachedException =
new SerializerException(IO_EXCEPTION_TEXT, e, SerializerException.MessageKeys.IO_EXCEPTION);
throw cachedException;
@ -302,11 +288,11 @@ public class ODataJsonSerializer extends AbstractODataSerializer {
final Entity entity, final EntitySerializerOptions options) throws SerializerException {
OutputStream outputStream = null;
SerializerException cachedException = null;
try {
final ContextURL contextURL = checkContextURL(options == null ? null : options.getContextURL());
CircleStreamBuffer buffer = new CircleStreamBuffer();
outputStream = buffer.getOutputStream();
JsonGenerator json = new JsonFactory().createGenerator(outputStream);
final ContextURL contextURL = checkContextURL(options == null ? null : options.getContextURL());
CircleStreamBuffer buffer = new CircleStreamBuffer();
outputStream = buffer.getOutputStream();
try (JsonGenerator json = new JsonFactory().createGenerator(outputStream)) {
String name = contextURL == null ? null:contextURL.getEntitySetOrSingletonOrType();
writeEntity(metadata, entityType, entity, contextURL,
options == null ? null : options.getExpand(),
@ -317,16 +303,11 @@ public class ODataJsonSerializer extends AbstractODataSerializer {
json);
json.close();
outputStream.close();
return SerializerResultImpl.with().content(buffer.getInputStream()).build();
} catch (final IOException e) {
} catch (final IOException | DecoderException e) {
cachedException =
new SerializerException(IO_EXCEPTION_TEXT, e, SerializerException.MessageKeys.IO_EXCEPTION);
throw cachedException;
} catch (DecoderException e) {
cachedException =
new SerializerException(IO_EXCEPTION_TEXT, e, SerializerException.MessageKeys.IO_EXCEPTION);
throw cachedException;
} finally {
closeCircleStreamBufferOutput(outputStream, cachedException);
}
@ -1122,11 +1103,11 @@ public class ODataJsonSerializer extends AbstractODataSerializer {
final Property property, final PrimitiveSerializerOptions options) throws SerializerException {
OutputStream outputStream = null;
SerializerException cachedException = null;
try {
final ContextURL contextURL = checkContextURL(options == null ? null : options.getContextURL());
CircleStreamBuffer buffer = new CircleStreamBuffer();
outputStream = buffer.getOutputStream();
JsonGenerator json = new JsonFactory().createGenerator(outputStream);
final ContextURL contextURL = checkContextURL(options == null ? null : options.getContextURL());
CircleStreamBuffer buffer = new CircleStreamBuffer();
outputStream = buffer.getOutputStream();
try (JsonGenerator json = new JsonFactory().createGenerator(outputStream)) {
json.writeStartObject();
writeContextURL(contextURL, json);
writeMetadataETag(metadata, json);
@ -1145,7 +1126,6 @@ public class ODataJsonSerializer extends AbstractODataSerializer {
json.writeEndObject();
json.close();
outputStream.close();
return SerializerResultImpl.with().content(buffer.getInputStream()).build();
} catch (final IOException e) {
cachedException =
@ -1227,11 +1207,11 @@ public class ODataJsonSerializer extends AbstractODataSerializer {
final Property property, final PrimitiveSerializerOptions options) throws SerializerException {
OutputStream outputStream = null;
SerializerException cachedException = null;
try {
final ContextURL contextURL = checkContextURL(options == null ? null : options.getContextURL());
CircleStreamBuffer buffer = new CircleStreamBuffer();
outputStream = buffer.getOutputStream();
JsonGenerator json = new JsonFactory().createGenerator(outputStream);
final ContextURL contextURL = checkContextURL(options == null ? null : options.getContextURL());
CircleStreamBuffer buffer = new CircleStreamBuffer();
outputStream = buffer.getOutputStream();
try (JsonGenerator json = new JsonFactory().createGenerator(outputStream)) {
json.writeStartObject();
writeContextURL(contextURL, json);
writeMetadataETag(metadata, json);
@ -1249,7 +1229,6 @@ public class ODataJsonSerializer extends AbstractODataSerializer {
json.writeEndObject();
json.close();
outputStream.close();
return SerializerResultImpl.with().content(buffer.getInputStream()).build();
} catch (final IOException e) {
cachedException =
@ -1265,11 +1244,11 @@ public class ODataJsonSerializer extends AbstractODataSerializer {
final Property property, final ComplexSerializerOptions options) throws SerializerException {
OutputStream outputStream = null;
SerializerException cachedException = null;
try {
final ContextURL contextURL = checkContextURL(options == null ? null : options.getContextURL());
CircleStreamBuffer buffer = new CircleStreamBuffer();
outputStream = buffer.getOutputStream();
JsonGenerator json = new JsonFactory().createGenerator(outputStream);
final ContextURL contextURL = checkContextURL(options == null ? null : options.getContextURL());
CircleStreamBuffer buffer = new CircleStreamBuffer();
outputStream = buffer.getOutputStream();
try (JsonGenerator json = new JsonFactory().createGenerator(outputStream)) {
json.writeStartObject();
writeContextURL(contextURL, json);
writeMetadataETag(metadata, json);
@ -1294,7 +1273,6 @@ public class ODataJsonSerializer extends AbstractODataSerializer {
json.writeEndObject();
json.close();
outputStream.close();
return SerializerResultImpl.with().content(buffer.getInputStream()).build();
} catch (final IOException e) {
cachedException =
@ -1311,12 +1289,12 @@ public class ODataJsonSerializer extends AbstractODataSerializer {
OutputStream outputStream = null;
SerializerException cachedException = null;
try {
final ContextURL contextURL = checkContextURL(options == null ? null : options.getContextURL());
CircleStreamBuffer buffer = new CircleStreamBuffer();
final UriHelper uriHelper = new UriHelperImpl();
outputStream = buffer.getOutputStream();
final JsonGenerator json = new JsonFactory().createGenerator(outputStream);
final ContextURL contextURL = checkContextURL(options == null ? null : options.getContextURL());
CircleStreamBuffer buffer = new CircleStreamBuffer();
final UriHelper uriHelper = new UriHelperImpl();
outputStream = buffer.getOutputStream();
try (final JsonGenerator json = new JsonFactory().createGenerator(outputStream)) {
json.writeStartObject();
writeContextURL(contextURL, json);
@ -1324,7 +1302,6 @@ public class ODataJsonSerializer extends AbstractODataSerializer {
json.writeEndObject();
json.close();
outputStream.close();
return SerializerResultImpl.with().content(buffer.getInputStream()).build();
} catch (final IOException e) {
cachedException =
@ -1343,12 +1320,11 @@ public class ODataJsonSerializer extends AbstractODataSerializer {
SerializerException cachedException = null;
boolean pagination = false ;
try {
final ContextURL contextURL = checkContextURL(options == null ? null : options.getContextURL());
CircleStreamBuffer buffer = new CircleStreamBuffer();
final UriHelper uriHelper = new UriHelperImpl();
outputStream = buffer.getOutputStream();
final JsonGenerator json = new JsonFactory().createGenerator(outputStream);
final ContextURL contextURL = checkContextURL(options == null ? null : options.getContextURL());
CircleStreamBuffer buffer = new CircleStreamBuffer();
final UriHelper uriHelper = new UriHelperImpl();
outputStream = buffer.getOutputStream();
try (final JsonGenerator json = new JsonFactory().createGenerator(outputStream)) {
json.writeStartObject();
writeContextURL(contextURL, json);
@ -1369,7 +1345,6 @@ public class ODataJsonSerializer extends AbstractODataSerializer {
json.writeEndObject();
json.close();
outputStream.close();
return SerializerResultImpl.with().content(buffer.getInputStream()).build();
} catch (final IOException e) {
cachedException =

View File

@ -40,10 +40,10 @@ public abstract class AbstractDebugTabTest {
tab.appendHtml(writer);
} else {
// Create JSON generator (the object mapper is necessary to write expression trees).
JsonGenerator json = new ObjectMapper().getFactory().createGenerator(writer);
tab.appendJson(json);
json.flush();
json.close();
try (JsonGenerator json = new ObjectMapper().getFactory().createGenerator(writer)) {
tab.appendJson(json);
json.flush();
}
}
writer.flush();
return writer.toString();