Skip to content

Commit fde8b42

Browse files
New media support API. (helidon-io#1356)
Rework media support API. - Fixes helidon-io#820 - a few APIs are deprecated to be handled later with helidon-io#1375 - building block for the upcoming HTTP client and Multipart media support
1 parent d88f650 commit fde8b42

87 files changed

Lines changed: 5096 additions & 1980 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

common/common/src/main/java/io/helidon/common/GenericType.java

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2019 Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -70,7 +70,7 @@ public class GenericType<T> implements Type {
7070
* deriving the class.
7171
*
7272
* @param genericType the generic type
73-
* @param <N> generic type of the returned GenericType
73+
* @param <N> generic type of the returned GenericType
7474
* @return new type wrapping the provided type
7575
* @throws IllegalArgumentException if genericType is {@code null} or not an instance of
7676
* {@code Class} or {@link ParameterizedType} whose raw
@@ -82,6 +82,28 @@ public static <N> GenericType<N> create(Type genericType) throws IllegalArgument
8282
return new GenericType<>(genericType, GenericTypeUtil.rawClass(genericType));
8383
}
8484

85+
/**
86+
* Constructs a new generic type instance representing the given class.
87+
* @param <N> generic type of the returned GenericType
88+
* @param clazz the class to represent
89+
* @return new type wrapping the provided class
90+
*/
91+
public static <N> GenericType<N> create(Class<N> clazz) {
92+
return new GenericType<>(clazz, clazz);
93+
}
94+
95+
/**
96+
* Constructs a new generic type instance representing the class of the
97+
* given object.
98+
*
99+
* @param <N> generic type of the returned GenericType
100+
* @param object the object to derive the class of
101+
* @return new type wrapping the class of the provided object
102+
*/
103+
public static <N> GenericType<N> create(N object) {
104+
return GenericType.<N>create(object.getClass());
105+
}
106+
85107
private GenericType(Type type, Class<?> rawType) {
86108
this.type = type;
87109
this.rawType = rawType;
@@ -164,11 +186,9 @@ public boolean equals(Object obj) {
164186
if (this == obj) {
165187
return true;
166188
}
167-
168189
if (obj instanceof GenericType) {
169190
return ((GenericType<?>) obj).type.equals(this.type);
170191
}
171-
172192
return false;
173193
}
174194

common/http/src/main/java/io/helidon/common/http/CharMatcher.java

Lines changed: 37 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -42,7 +42,7 @@
4242
* @author Kevin Bourrillion
4343
*/
4444
@SuppressWarnings({"checkstyle:VisibilityModifier", "checkstyle:RedundantModifier"})
45-
abstract class CharMatcher {
45+
public abstract class CharMatcher {
4646

4747
/**
4848
* Constructor for use by subclasses. When subclassing, you may want to override
@@ -54,16 +54,22 @@ protected CharMatcher() {
5454
/**
5555
* Determines whether a character is ASCII, meaning that its code point is less than 128.
5656
*
57-
* @since 19.0 (since 1.0 as constant {@code ASCII})
57+
* @return a CharMatcher instance that matches ASCII characters
5858
*/
5959
public static CharMatcher ascii() {
6060
return Ascii.INSTANCE;
6161
}
6262

6363
/**
64-
* Returns a {@code char} matcher that matches any character except the one specified.
64+
* Returns a {@code char} matcher that matches any character except the one
65+
* specified.
6566
*
66-
* <p>To negate another {@code CharMatcher}, use {@link #negate()}.
67+
* <p>
68+
* To negate another {@code CharMatcher}, use {@link #negate()}.
69+
*
70+
* @param match the character that should not match
71+
* @return a CharMatcher instance that matches any character except the one
72+
* specified
6773
*/
6874
public static CharMatcher isNot(final char match) {
6975
return new IsNot(match);
@@ -72,16 +78,16 @@ public static CharMatcher isNot(final char match) {
7278
/**
7379
* Matches any character.
7480
*
75-
* @since 19.0 (since 1.0 as constant {@code ANY})
81+
* @return a CharMatcher that matches any character
7682
*/
7783
public static CharMatcher any() {
7884
return Any.INSTANCE;
7985
}
8086

8187
/**
82-
* Matches no characters.
88+
* Matches no character.
8389
*
84-
* @since 19.0 (since 1.0 as constant {@code NONE})
90+
* @return a CharMatcher that matches no character
8591
*/
8692
public static CharMatcher none() {
8793
return None.INSTANCE;
@@ -91,14 +97,16 @@ public static CharMatcher none() {
9197
* Determines whether a character is an ISO control character as specified by
9298
* {@link Character#isISOControl(char)}.
9399
*
94-
* @since 19.0 (since 1.0 as constant {@code JAVA_ISO_CONTROL})
100+
* @return a CharMatcher that matches ISO control character
95101
*/
96102
public static CharMatcher javaIsoControl() {
97103
return JavaIsoControl.INSTANCE;
98104
}
99105

100106
/**
101107
* Returns a {@code char} matcher that matches only one specified character.
108+
* @param match the character that should match
109+
* @return a CharMatcher that matches the one specified character
102110
*/
103111
public static CharMatcher is(final char match) {
104112
return new Is(match);
@@ -111,6 +119,8 @@ private static CharMatcher.IsEither isEither(char c1, char c2) {
111119
/**
112120
* Returns a {@code char} matcher that matches any character not present in the given character
113121
* sequence.
122+
* @param sequence all the characters that should not be matched
123+
* @return a CharMatcher that matches any character not present in the given sequence
114124
*/
115125
public static CharMatcher noneOf(CharSequence sequence) {
116126
return anyOf(sequence).negate();
@@ -119,6 +129,8 @@ public static CharMatcher noneOf(CharSequence sequence) {
119129
/**
120130
* Returns a {@code char} matcher that matches any character present in the given character
121131
* sequence.
132+
* @param sequence all the characters that should be matched
133+
* @return a CharMatcher that matches any character present in the given sequence
122134
*/
123135
public static CharMatcher anyOf(final CharSequence sequence) {
124136
switch (sequence.length()) {
@@ -151,25 +163,38 @@ private static String showCharacter(char c) {
151163

152164
/**
153165
* Determines a true or false value for the given character.
166+
*
167+
* @param c the character to match
168+
* @return {@code true} if this {@code CharMatcher} instance matches the
169+
* given character, {@code false} otherwise
154170
*/
155171
public abstract boolean matches(char c);
156172

157173
/**
158174
* Returns a matcher that matches any character not matched by this matcher.
175+
*
176+
* @return new {@code CharMatcher} instance representing the logical
177+
* negation of this instance
159178
*/
160179
public CharMatcher negate() {
161180
return new Negated(this);
162181
}
163182

164183
/**
165184
* Returns a matcher that matches any character matched by both this matcher and {@code other}.
185+
* @param other the other instance
186+
* @return new {@code CharMatcher} instance representing the logical
187+
* and of this instance and the {@code other} instance
166188
*/
167189
public CharMatcher and(CharMatcher other) {
168190
return new And(this, other);
169191
}
170192

171193
/**
172194
* Returns a matcher that matches any character matched by either this matcher or {@code other}.
195+
* @param other the other instance
196+
* @return new {@code CharMatcher} instance representing the logical
197+
* and of this instance and the {@code other} instance
173198
*/
174199
public CharMatcher or(CharMatcher other) {
175200
return new Or(this, other);
@@ -281,6 +306,8 @@ public int indexIn(CharSequence sequence, int start) {
281306

282307
/**
283308
* Returns the number of matching characters found in a character sequence.
309+
* @param sequence sequence to count the number of matching characters
310+
* @return count of matching characters
284311
*/
285312
public int countIn(CharSequence sequence) {
286313
int count = 0;
@@ -327,15 +354,10 @@ public final String toString() {
327354
}
328355

329356
/**
330-
* A matcher for which precomputation will not yield any significant benefit.
357+
* A matcher for which pre-computation will not yield any significant benefit.
331358
*/
332359
abstract static class FastMatcher extends CharMatcher {
333360

334-
// @Override
335-
// public final CharMatcher precomputed() {
336-
// return this;
337-
// }
338-
339361
@Override
340362
public CharMatcher negate() {
341363
return new NegatedFastMatcher(this);
@@ -350,11 +372,6 @@ static class NegatedFastMatcher extends Negated {
350372
NegatedFastMatcher(CharMatcher original) {
351373
super(original);
352374
}
353-
354-
// @Override
355-
// public final CharMatcher precomputed() {
356-
// return this;
357-
// }
358375
}
359376

360377
/**
@@ -584,11 +601,6 @@ public boolean matches(char c) {
584601
return c == match;
585602
}
586603

587-
// @Override
588-
// public String replaceFrom(CharSequence sequence, char replacement) {
589-
// return sequence.toString().replace(match, replacement);
590-
// }
591-
592604
@Override
593605
public CharMatcher and(CharMatcher other) {
594606
return other.matches(match) ? this : none();
@@ -643,11 +655,6 @@ public int indexIn(CharSequence sequence, int start) {
643655
return (start == length) ? -1 : start;
644656
}
645657

646-
// @Override
647-
// public int lastIndexIn(CharSequence sequence) {
648-
// return sequence.length() - 1;
649-
// }
650-
651658
@Override
652659
public boolean matchesAllOf(CharSequence sequence) {
653660
Objects.requireNonNull(sequence);
@@ -659,39 +666,6 @@ public boolean matchesNoneOf(CharSequence sequence) {
659666
return sequence.length() == 0;
660667
}
661668

662-
// @Override
663-
// public String removeFrom(CharSequence sequence) {
664-
// Objects.requireNonNull(sequence);
665-
// return "";
666-
// }
667-
//
668-
// @Override
669-
// public String replaceFrom(CharSequence sequence, char replacement) {
670-
// char[] array = new char[sequence.length()];
671-
// Arrays.fill(array, replacement);
672-
// return new String(array);
673-
// }
674-
//
675-
// @Override
676-
// public String replaceFrom(CharSequence sequence, CharSequence replacement) {
677-
// StringBuilder result = new StringBuilder(sequence.length() * replacement.length());
678-
// for (int i = 0; i < sequence.length(); i++) {
679-
// result.append(replacement);
680-
// }
681-
// return result.toString();
682-
// }
683-
//
684-
// @Override
685-
// public String collapseFrom(CharSequence sequence, char replacement) {
686-
// return (sequence.length() == 0) ? "" : String.valueOf(replacement);
687-
// }
688-
//
689-
// @Override
690-
// public String trimFrom(CharSequence sequence) {
691-
// Objects.requireNonNull(sequence);
692-
// return "";
693-
// }
694-
695669
@Override
696670
public int countIn(CharSequence sequence) {
697671
return sequence.length();
@@ -743,12 +717,6 @@ public int indexIn(CharSequence sequence, int start) {
743717
return -1;
744718
}
745719

746-
// @Override
747-
// public int lastIndexIn(CharSequence sequence) {
748-
// Objects.requireNonNull(sequence);
749-
// return -1;
750-
// }
751-
752720
@Override
753721
public boolean matchesAllOf(CharSequence sequence) {
754722
return sequence.length() == 0;
@@ -760,42 +728,6 @@ public boolean matchesNoneOf(CharSequence sequence) {
760728
return true;
761729
}
762730

763-
// @Override
764-
// public String removeFrom(CharSequence sequence) {
765-
// return sequence.toString();
766-
// }
767-
//
768-
// @Override
769-
// public String replaceFrom(CharSequence sequence, char replacement) {
770-
// return sequence.toString();
771-
// }
772-
//
773-
// @Override
774-
// public String replaceFrom(CharSequence sequence, CharSequence replacement) {
775-
// Objects.requireNonNull(replacement);
776-
// return sequence.toString();
777-
// }
778-
//
779-
// @Override
780-
// public String collapseFrom(CharSequence sequence, char replacement) {
781-
// return sequence.toString();
782-
// }
783-
//
784-
// @Override
785-
// public String trimFrom(CharSequence sequence) {
786-
// return sequence.toString();
787-
// }
788-
//
789-
// @Override
790-
// public String trimLeadingFrom(CharSequence sequence) {
791-
// return sequence.toString();
792-
// }
793-
//
794-
// @Override
795-
// public String trimTrailingFrom(CharSequence sequence) {
796-
// return sequence.toString();
797-
// }
798-
799731
@Override
800732
public int countIn(CharSequence sequence) {
801733
Objects.requireNonNull(sequence);

common/http/src/main/java/io/helidon/common/http/Content.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2019 Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -40,7 +40,9 @@
4040
* It is possible to register function to convert publisher to {@link CompletionStage} of a single entity using
4141
* {@link #registerReader(Class, Reader)} or {@link #registerReader(Predicate, Reader)} methods. It
4242
* is then possible to use {@link #as(Class)} method to obtain such entity.
43+
* @deprecated use {@code io.helidon.media.common.MessageBodyReadableContent} instead
4344
*/
45+
@Deprecated
4446
public interface Content extends Flow.Publisher<DataChunk> {
4547
/**
4648
* If possible, adds the given Subscriber to this publisher. This publisher is effectively
@@ -70,7 +72,9 @@ public interface Content extends Flow.Publisher<DataChunk> {
7072
*
7173
* @param function a function that transforms a given publisher (that is either the original
7274
* publisher or the publisher transformed by the last previously registered filter).
75+
* @deprecated use {@code io.helidon.media.common.MessageBodyReaderContext.registerFilter}
7376
*/
77+
@Deprecated
7478
void registerFilter(Function<Flow.Publisher<DataChunk>, Flow.Publisher<DataChunk>> function);
7579

7680
/**
@@ -88,7 +92,9 @@ public interface Content extends Flow.Publisher<DataChunk> {
8892
* If an exception is thrown, the resulting completion stage of
8993
* {@link #as(Class)} method call ends exceptionally.
9094
* @param <T> the requested type
95+
* @deprecated use {@code io.helidon.media.common.MessageBodyReaderContext.registerReader}
9196
*/
97+
@Deprecated
9298
<T> void registerReader(Class<T> type, Reader<T> reader);
9399

94100
/**
@@ -109,7 +115,9 @@ public interface Content extends Flow.Publisher<DataChunk> {
109115
* If an exception is thrown, the resulting completion stage of
110116
* {@link #as(Class)} method call ends exceptionally.
111117
* @param <T> the requested type
118+
* @deprecated use {@code io.helidon.media.common.MessageBodyReaderContext.registerReader}
112119
*/
120+
@Deprecated
113121
<T> void registerReader(Predicate<Class<?>> predicate, Reader<T> reader);
114122

115123
/**

0 commit comments

Comments
 (0)