Tabnine Logo
StringDecoder
Code IndexAdd Tabnine to your IDE (free)

How to use
StringDecoder
in
org.springframework.core.codec

Best Java code snippets using org.springframework.core.codec.StringDecoder (Showing top 20 results out of 315)

origin: spring-projects/spring-framework

/**
 * Create a {@code StringDecoder} that supports all MIME types.
 */
public static StringDecoder allMimeTypes() {
  return allMimeTypes(DEFAULT_DELIMITERS, true);
}
origin: spring-projects/spring-framework

/**
 * Create a {@code StringDecoder} for {@code "text/plain"}.
 */
public static StringDecoder textPlainOnly() {
  return textPlainOnly(DEFAULT_DELIMITERS, true);
}
origin: spring-projects/spring-framework

/**
 * Create a {@code StringDecoder} for {@code "text/plain"}.
 * @param delimiters delimiter strings to use to split the input stream
 * @param stripDelimiter whether to remove delimiters from the resulting
 * input strings
 */
public static StringDecoder textPlainOnly(List<String> delimiters, boolean stripDelimiter) {
  return new StringDecoder(delimiters, stripDelimiter, new MimeType("text", "plain", DEFAULT_CHARSET));
}
origin: spring-projects/spring-framework

@Override
public Flux<String> decode(Publisher<DataBuffer> inputStream, ResolvableType elementType,
    @Nullable MimeType mimeType, @Nullable Map<String, Object> hints) {
  List<byte[]> delimiterBytes = getDelimiterBytes(mimeType);
  Flux<DataBuffer> inputFlux = Flux.from(inputStream)
      .flatMapIterable(dataBuffer -> splitOnDelimiter(dataBuffer, delimiterBytes))
      .bufferUntil(StringDecoder::isEndFrame)
      .map(StringDecoder::joinUntilEndFrame)
      .doOnDiscard(PooledDataBuffer.class, DataBufferUtils::release);
  return super.decode(inputFlux, elementType, mimeType, hints);
}
origin: org.springframework.fu/spring-fu-autoconfigure-adapter

  @Override
  protected void register(GenericApplicationContext context, CodecConfigurer configurer) {
    configurer.customCodecs().encoder(textPlainOnly ? CharSequenceEncoder.textPlainOnly() : CharSequenceEncoder.allMimeTypes());
    configurer.customCodecs().decoder(textPlainOnly ? StringDecoder.textPlainOnly() : StringDecoder.allMimeTypes());
  }
}
origin: spring-projects/spring-framework

assertEquals(MediaType.APPLICATION_JSON_UTF8, part.headers().getContentType());
String value = StringDecoder.textPlainOnly(false).decodeToMono(part.content(),
    ResolvableType.forClass(String.class), MediaType.TEXT_PLAIN,
    Collections.emptyMap()).block(Duration.ZERO);
assertEquals("publisher", part.name());
value = StringDecoder.textPlainOnly(false).decodeToMono(part.content(),
    ResolvableType.forClass(String.class), MediaType.TEXT_PLAIN,
    Collections.emptyMap()).block(Duration.ZERO);
origin: spring-projects/spring-framework

@Override
public Flux<Object> read(
    ResolvableType elementType, ReactiveHttpInputMessage message, Map<String, Object> hints) {
  boolean shouldWrap = isServerSentEvent(elementType);
  ResolvableType valueType = (shouldWrap ? elementType.getGeneric() : elementType);
  return stringDecoder.decode(message.getBody(), STRING_TYPE, null, hints)
      .bufferUntil(line -> line.equals(""))
      .concatMap(lines -> buildEvent(lines, valueType, shouldWrap, hints));
}
origin: spring-projects/spring-framework

private List<byte[]> getDelimiterBytes(@Nullable MimeType mimeType) {
  return this.delimitersCache.computeIfAbsent(getCharset(mimeType),
      charset -> this.delimiters.stream()
          .map(s -> s.getBytes(charset))
          .collect(Collectors.toList()));
}
origin: spring-projects/spring-framework

@Override
public Mono<Object> readMono(
    ResolvableType elementType, ReactiveHttpInputMessage message, Map<String, Object> hints) {
  // We're ahead of String + "*/*"
  // Let's see if we can aggregate the output (lest we time out)...
  if (elementType.resolve() == String.class) {
    Flux<DataBuffer> body = message.getBody();
    return stringDecoder.decodeToMono(body, elementType, null, null).cast(Object.class);
  }
  return Mono.error(new UnsupportedOperationException(
      "ServerSentEventHttpMessageReader only supports reading stream of events as a Flux"));
}
origin: spring-projects/spring-framework

byte[] matchingDelimiter = null;
for (byte[] delimiter : delimiterBytes) {
  int index = indexOf(dataBuffer, delimiter);
  if (index >= 0 && index < length) {
    length = index;
origin: org.springframework/spring-core

@Override
public Flux<String> decode(Publisher<DataBuffer> inputStream, ResolvableType elementType,
    @Nullable MimeType mimeType, @Nullable Map<String, Object> hints) {
  List<byte[]> delimiterBytes = getDelimiterBytes(mimeType);
  Flux<DataBuffer> inputFlux = Flux.from(inputStream)
      .flatMapIterable(dataBuffer -> splitOnDelimiter(dataBuffer, delimiterBytes))
      .bufferUntil(StringDecoder::isEndFrame)
      .map(StringDecoder::joinUntilEndFrame)
      .doOnDiscard(PooledDataBuffer.class, DataBufferUtils::release);
  return super.decode(inputFlux, elementType, mimeType, hints);
}
origin: org.springframework/spring-web

@Override
public Flux<Object> read(
    ResolvableType elementType, ReactiveHttpInputMessage message, Map<String, Object> hints) {
  boolean shouldWrap = isServerSentEvent(elementType);
  ResolvableType valueType = (shouldWrap ? elementType.getGeneric() : elementType);
  return stringDecoder.decode(message.getBody(), STRING_TYPE, null, hints)
      .bufferUntil(line -> line.equals(""))
      .concatMap(lines -> buildEvent(lines, valueType, shouldWrap, hints));
}
origin: org.springframework/spring-core

private List<byte[]> getDelimiterBytes(@Nullable MimeType mimeType) {
  return this.delimitersCache.computeIfAbsent(getCharset(mimeType),
      charset -> this.delimiters.stream()
          .map(s -> s.getBytes(charset))
          .collect(Collectors.toList()));
}
origin: org.springframework/spring-web

@Override
public Mono<Object> readMono(
    ResolvableType elementType, ReactiveHttpInputMessage message, Map<String, Object> hints) {
  // We're ahead of String + "*/*"
  // Let's see if we can aggregate the output (lest we time out)...
  if (elementType.resolve() == String.class) {
    Flux<DataBuffer> body = message.getBody();
    return stringDecoder.decodeToMono(body, elementType, null, null).cast(Object.class);
  }
  return Mono.error(new UnsupportedOperationException(
      "ServerSentEventHttpMessageReader only supports reading stream of events as a Flux"));
}
origin: org.springframework/spring-core

byte[] matchingDelimiter = null;
for (byte[] delimiter : delimiterBytes) {
  int index = indexOf(dataBuffer, delimiter);
  if (index >= 0 && index < length) {
    length = index;
origin: spring-projects/spring-framework

/**
 * Create a {@code StringDecoder} that supports all MIME types.
 * @param ignored ignored
 * @deprecated as of Spring 5.0.4, in favor of {@link #allMimeTypes()} or
 * {@link #allMimeTypes(List, boolean)}
 */
@Deprecated
public static StringDecoder allMimeTypes(boolean ignored) {
  return allMimeTypes();
}
origin: spring-projects/spring-framework

/**
 * Create a {@code StringDecoder} for {@code "text/plain"}.
 * @param ignored ignored
 * @deprecated as of Spring 5.0.4, in favor of {@link #textPlainOnly()} or
 * {@link #textPlainOnly(List, boolean)}
 */
@Deprecated
public static StringDecoder textPlainOnly(boolean ignored) {
  return textPlainOnly();
}
origin: spring-projects/spring-framework

/**
 * Create a {@code StringDecoder} that supports all MIME types.
 * @param delimiters delimiter strings to use to split the input stream
 * @param stripDelimiter whether to remove delimiters from the resulting
 * input strings
 */
public static StringDecoder allMimeTypes(List<String> delimiters, boolean stripDelimiter) {
  return new StringDecoder(delimiters, stripDelimiter,
      new MimeType("text", "plain", DEFAULT_CHARSET), MimeTypeUtils.ALL);
}
origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.spring-core

@Override
public Flux<String> decode(Publisher<DataBuffer> inputStream, ResolvableType elementType,
    @Nullable MimeType mimeType, @Nullable Map<String, Object> hints) {
  List<byte[]> delimiterBytes = getDelimiterBytes(mimeType);
  Flux<DataBuffer> inputFlux = Flux.from(inputStream)
      .flatMapIterable(dataBuffer -> splitOnDelimiter(dataBuffer, delimiterBytes))
      .bufferUntil(StringDecoder::isEndFrame)
      .map(StringDecoder::joinUntilEndFrame)
      .doOnDiscard(PooledDataBuffer.class, DataBufferUtils::release);
  return super.decode(inputFlux, elementType, mimeType, hints);
}
origin: spring-projects/spring-framework

@Override
protected void testDecodeError(Publisher<DataBuffer> input, ResolvableType outputType,
    @Nullable MimeType mimeType, @Nullable Map<String, Object> hints) {
  input = Flux.concat(
      Flux.from(input).take(1),
      Flux.error(new InputException()));
  Flux<String> result = this.decoder.decode(input, outputType, mimeType, hints);
  StepVerifier.create(result)
      .expectError(InputException.class)
      .verify();
}
org.springframework.core.codecStringDecoder

Javadoc

Decode from a data buffer stream to a String stream. Before decoding, this decoder realigns the incoming data buffers so that each buffer ends with a newline. This is to make sure that multibyte characters are decoded properly, and do not cross buffer boundaries. The default delimiters ( \n, \r\n)can be customized.

Partially inspired by Netty's DelimiterBasedFrameDecoder.

Most used methods

  • allMimeTypes
    Create a StringDecoder that supports all MIME types.
  • textPlainOnly
    Create a StringDecoder for "text/plain".
  • <init>
  • decode
  • decodeToMono
  • getCharset
  • getDelimiterBytes
  • indexOf
    Find the given delimiter in the given data buffer.
  • isEndFrame
    Check whether the given buffer is #END_FRAME.
  • splitOnDelimiter
    Split the given data buffer on delimiter boundaries. The returned Flux contains an #END_FRAME buffer
  • canDecode
  • canDecode

Popular in Java

  • Parsing JSON documents to java classes using gson
  • runOnUiThread (Activity)
  • addToBackStack (FragmentTransaction)
  • notifyDataSetChanged (ArrayAdapter)
  • Thread (java.lang)
    A thread is a thread of execution in a program. The Java Virtual Machine allows an application to ha
  • DecimalFormat (java.text)
    A concrete subclass of NumberFormat that formats decimal numbers. It has a variety of features desig
  • AtomicInteger (java.util.concurrent.atomic)
    An int value that may be updated atomically. See the java.util.concurrent.atomic package specificati
  • DataSource (javax.sql)
    An interface for the creation of Connection objects which represent a connection to a database. This
  • BasicDataSource (org.apache.commons.dbcp)
    Basic implementation of javax.sql.DataSource that is configured via JavaBeans properties. This is no
  • Location (org.springframework.beans.factory.parsing)
    Class that models an arbitrary location in a Resource.Typically used to track the location of proble
  • Top 12 Jupyter Notebook extensions
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now