Skip to content

Commit

Permalink
Deprecate duplicated methods and fields in MBR/MBW
Browse files Browse the repository at this point in the history
Signed-off-by: jansupol <jan.supol@oracle.com>
  • Loading branch information
jansupol committed Aug 18, 2023
1 parent cacccd9 commit e3c3941
Show file tree
Hide file tree
Showing 25 changed files with 83 additions and 56 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, 2019 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand Down Expand Up @@ -43,7 +43,7 @@ public abstract class AbstractFormProvider<T> extends AbstractMessageReaderWrite
public <M extends MultivaluedMap<String, String>> M readFrom(M map,
MediaType mediaType, boolean decode,
InputStream entityStream) throws IOException {
final String encoded = readFromAsString(entityStream, mediaType);
final String encoded = ReaderWriter.readFromAsString(entityStream, mediaType);

final String charsetName = ReaderWriter.getCharset(mediaType).name();

Expand Down Expand Up @@ -90,6 +90,6 @@ public <M extends MultivaluedMap<String, String>> void writeTo(
}
}

writeToAsString(sb.toString(), entityStream, mediaType);
ReaderWriter.writeToAsString(sb.toString(), entityStream, mediaType);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,14 @@ public static void writeTo(Reader in, Writer out) throws IOException {
* Get the character set from a media type.
* <p>
* The character set is obtained from the media type parameter "charset".
* If the parameter is not present the {@link #UTF8} charset is utilized.
* If the parameter is not present the {@link StandardCharsets#UTF_8} charset is utilized.
*
* @param m the media type.
* @return the character set.
*
* @deprecated use {@code ReaderWriter.getCharset(m)} instead
*/
@Deprecated
public static Charset getCharset(MediaType m) {
return ReaderWriter.getCharset(m);
}
Expand All @@ -99,7 +102,10 @@ public static Charset getCharset(MediaType m) {
* @return the string.
*
* @throws IOException if there is an error reading from the input stream.
*
* @deprecated use {@code ReaderWriter.readFromAsString(in, type)} instead
*/
@Deprecated
public static String readFromAsString(InputStream in, MediaType type) throws IOException {
return ReaderWriter.readFromAsString(in, type);
}
Expand All @@ -112,7 +118,10 @@ public static String readFromAsString(InputStream in, MediaType type) throws IOE
* @param type the media type that determines the character set defining
* how to decode bytes to characters.
* @throws IOException in case of a write failure.
*
* @deprecated use {@code ReaderWriter.writeToAsString(s, out, type)} instead
*/
@Deprecated
public static void writeToAsString(String s, OutputStream out, MediaType type) throws IOException {
ReaderWriter.writeToAsString(s, out, type);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2019 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand Down Expand Up @@ -144,7 +144,7 @@ public Object readFrom(
MediaType mediaType,
MultivaluedMap<String, String> httpHeaders,
InputStream entityStream) throws IOException, WebApplicationException {
final String entityString = readFromAsString(entityStream, mediaType);
final String entityString = ReaderWriter.readFromAsString(entityStream, mediaType);
if (entityString.isEmpty()) {
throw new NoContentException(LocalizationMessages.ERROR_READING_ENTITY_MISSING());
}
Expand Down Expand Up @@ -210,6 +210,6 @@ public void writeTo(
MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders,
OutputStream entityStream) throws IOException, WebApplicationException {
writeToAsString(o.toString(), entityStream, mediaType);
ReaderWriter.writeToAsString(o.toString(), entityStream, mediaType);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, 2019 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand Down Expand Up @@ -52,7 +52,7 @@ public byte[] readFrom(
MultivaluedMap<String, String> httpHeaders,
InputStream entityStream) throws IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
writeTo(entityStream, out);
ReaderWriter.writeTo(entityStream, out);
return out.toByteArray();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, 2019 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand Down Expand Up @@ -162,7 +162,7 @@ public void writeTo(
final OutputStream entityStream) throws IOException {
final InputStream in = t.getInputStream();
try {
writeTo(in, entityStream);
ReaderWriter.writeTo(in, entityStream);
} finally {
in.close();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand Down Expand Up @@ -50,7 +50,7 @@ public Enum readFrom(
MediaType mediaType,
MultivaluedMap<String, String> httpHeaders,
InputStream entityStream) throws IOException, WebApplicationException {
final String value = readFromAsString(entityStream, mediaType);
final String value = ReaderWriter.readFromAsString(entityStream, mediaType);
return Enum.valueOf(type, value);
}

Expand All @@ -67,6 +67,6 @@ public void writeTo(
MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders,
OutputStream entityStream) throws IOException, WebApplicationException {
writeToAsString(anEnum.name(), entityStream, mediaType);
ReaderWriter.writeToAsString(anEnum.name(), entityStream, mediaType);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand Down Expand Up @@ -79,7 +79,7 @@ public void writeTo(
MultivaluedMap<String, Object> httpHeaders,
OutputStream entityStream) throws IOException {
try {
writeTo(t, entityStream);
ReaderWriter.writeTo(t, entityStream);
} finally {
t.close();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand Down Expand Up @@ -66,7 +66,7 @@ public Reader readFrom(
new ByteArrayInputStream(new byte[0]), MessageUtils.getCharset(mediaType)));
}

return new BufferedReader(new InputStreamReader(entityStream, getCharset(mediaType)));
return new BufferedReader(new InputStreamReader(entityStream, ReaderWriter.getCharset(mediaType)));
}

@Override
Expand All @@ -86,8 +86,8 @@ public void writeTo(
final OutputStream entityStream) throws IOException {
try {
final OutputStreamWriter out = new OutputStreamWriter(entityStream,
getCharset(mediaType));
writeTo(t, out);
ReaderWriter.getCharset(mediaType));
ReaderWriter.writeTo(t, out);
out.flush();
} finally {
t.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,14 @@ public static void writeTo(Reader in, Writer out) throws IOException {
* Get the character set from a media type.
* <p>
* The character set is obtained from the media type parameter "charset".
* If the parameter is not present the {@link #UTF8} charset is utilized.
* If the parameter is not present the {@link StandardCharsets#UTF_8} charset is utilized.
*
* @param m the media type.
* @return the character set.
*/
public static Charset getCharset(MediaType m) {
String name = (m == null) ? null : m.getParameters().get(MediaType.CHARSET_PARAMETER);
return (name == null) ? UTF8 : Charset.forName(name);
return (name == null) ? StandardCharsets.UTF_8 : Charset.forName(name);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand Down Expand Up @@ -51,7 +51,7 @@ public String readFrom(
MediaType mediaType,
MultivaluedMap<String, String> httpHeaders,
InputStream entityStream) throws IOException {
return readFromAsString(entityStream, mediaType);
return ReaderWriter.readFromAsString(entityStream, mediaType);
}

@Override
Expand All @@ -73,6 +73,6 @@ public void writeTo(
MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders,
OutputStream entityStream) throws IOException {
writeToAsString(t, entityStream, mediaType);
ReaderWriter.writeToAsString(t, entityStream, mediaType);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
Expand Down Expand Up @@ -56,6 +57,7 @@
import javax.xml.stream.XMLStreamReader;

import org.glassfish.jersey.message.internal.EntityInputStream;
import org.glassfish.jersey.message.internal.ReaderWriter;

/**
* An abstract provider for {@code T[]}, {@code Collection&lt;T&gt;},
Expand Down Expand Up @@ -238,12 +240,12 @@ public final void writeTo(
? Arrays.asList((Object[]) t)
: (Collection) t;
final Class elementType = getElementClass(type, genericType);
final Charset charset = getCharset(mediaType);
final Charset charset = ReaderWriter.getCharset(mediaType);
final String charsetName = charset.name();

final Marshaller m = getMarshaller(elementType, mediaType);
m.setProperty(Marshaller.JAXB_FRAGMENT, true);
if (charset != UTF8) {
if (charset != StandardCharsets.UTF_8) {
m.setProperty(Marshaller.JAXB_ENCODING, charsetName);
}
setHeader(m, annotations);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;

import javax.ws.rs.BadRequestException;
import javax.ws.rs.InternalServerErrorException;
Expand All @@ -41,6 +42,7 @@

import org.glassfish.jersey.internal.LocalizationMessages;
import org.glassfish.jersey.message.internal.EntityInputStream;
import org.glassfish.jersey.message.internal.ReaderWriter;

/**
* An abstract provider for {@link JAXBElement}.
Expand Down Expand Up @@ -145,8 +147,8 @@ public final void writeTo(
OutputStream entityStream) throws IOException {
try {
final Marshaller m = getMarshaller(t.getDeclaredType(), mediaType);
final Charset c = getCharset(mediaType);
if (c != UTF8) {
final Charset c = ReaderWriter.getCharset(mediaType);
if (c != StandardCharsets.UTF_8) {
m.setProperty(Marshaller.JAXB_ENCODING, c.name());
}
setHeader(m, annotations);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;

import javax.ws.rs.BadRequestException;
import javax.ws.rs.InternalServerErrorException;
Expand All @@ -42,6 +43,7 @@

import org.glassfish.jersey.internal.LocalizationMessages;
import org.glassfish.jersey.message.internal.EntityInputStream;
import org.glassfish.jersey.message.internal.ReaderWriter;

/**
* An abstract provider for JAXB types that are annotated with
Expand Down Expand Up @@ -150,8 +152,8 @@ public final void writeTo(
OutputStream entityStream) throws IOException {
try {
final Marshaller m = getMarshaller(type, mediaType);
final Charset c = getCharset(mediaType);
if (c != UTF8) {
final Charset c = ReaderWriter.getCharset(mediaType);
if (c != StandardCharsets.UTF_8) {
m.setProperty(Marshaller.JAXB_ENCODING, c.name());
}
setHeader(m, annotations);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import org.glassfish.jersey.jsonb.LocalizationMessages;
import org.glassfish.jersey.message.internal.AbstractMessageReaderWriterProvider;
import org.glassfish.jersey.message.internal.EntityInputStream;
import org.glassfish.jersey.message.internal.ReaderWriter;

/**
* Entity provider (reader and writer) for JSONB.
Expand Down Expand Up @@ -102,7 +103,7 @@ public void writeTo(Object o, Class<?> type, Type genericType,
OutputStream entityStream) throws IOException, WebApplicationException {
Jsonb jsonb = getJsonb(type);
try {
entityStream.write(jsonb.toJson(o).getBytes(AbstractMessageReaderWriterProvider.getCharset(mediaType)));
entityStream.write(jsonb.toJson(o).getBytes(ReaderWriter.getCharset(mediaType)));
entityStream.flush();
} catch (IOException e) {
throw new ProcessingException(LocalizationMessages.ERROR_JSONB_SERIALIZATION(), e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import org.glassfish.jersey.message.internal.ReaderWriter;

/**
* Entity provider (reader and writer) for Gson.
Expand Down Expand Up @@ -81,7 +82,7 @@ public Object readFrom(Class<Object> type, Type genericType,
Gson gson = getGson(type);
try {
return gson.fromJson(new InputStreamReader(entityInputStream,
AbstractMessageReaderWriterProvider.getCharset(mediaType)), genericType);
ReaderWriter.getCharset(mediaType)), genericType);
} catch (Exception e) {
throw new ProcessingException(LocalizationMessages.ERROR_GSON_DESERIALIZATION(), e);
}
Expand All @@ -100,7 +101,7 @@ public void writeTo(Object o, Class<?> type, Type genericType,
OutputStream entityStream) throws IOException, WebApplicationException {
Gson gson = getGson(type);
try {
entityStream.write(gson.toJson(o).getBytes(AbstractMessageReaderWriterProvider.getCharset(mediaType)));
entityStream.write(gson.toJson(o).getBytes(ReaderWriter.getCharset(mediaType)));
entityStream.flush();
} catch (Exception e) {
throw new ProcessingException(LocalizationMessages.ERROR_GSON_SERIALIZATION(), e);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, 2019 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand Down Expand Up @@ -33,6 +33,7 @@

import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONException;
import org.glassfish.jersey.message.internal.ReaderWriter;

/**
* Low-level JSON media type message entity provider (reader & writer) for
Expand Down Expand Up @@ -70,7 +71,7 @@ public JSONArray readFrom(
MultivaluedMap<String, String> httpHeaders,
InputStream entityStream) throws IOException {
try {
return new JSONArray(readFromAsString(entityStream, mediaType));
return new JSONArray(ReaderWriter.readFromAsString(entityStream, mediaType));
} catch (JSONException je) {
throw new WebApplicationException(
new Exception(LocalizationMessages.ERROR_PARSING_JSON_ARRAY(), je),
Expand All @@ -89,7 +90,7 @@ public void writeTo(
OutputStream entityStream) throws IOException {
try {
OutputStreamWriter writer = new OutputStreamWriter(entityStream,
getCharset(mediaType));
ReaderWriter.getCharset(mediaType));
t.write(writer);
writer.write("\n");
writer.flush();
Expand Down
Loading

0 comments on commit e3c3941

Please sign in to comment.