Top Description Inners Fields Constructors Methods
org.springframework.aot.nativex

pack-priv Class BasicJsonWriter

extends Object
Class Inheritance
Imports
java.io.IOException, .Writer, java.util.Iterator, .List, .Map, java.util.function.Consumer, org.springframework.aot.hint.TypeReference

Very basic json writer for the purposes of translating runtime hints to native configuration.
Author
Stephane Nicoll

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class

Field Summary

Modifier and TypeField and Description
private final BasicJsonWriter.IndentingWriter

Constructor Summary

AccessConstructor and Description
public
BasicJsonWriter(Writer
the writer to use
writer
,
String
the value of one indent
singleIndent
)

Create a new instance with the specified indent value.

public
BasicJsonWriter(Writer
the writer to use
writer
)

Create a new instance using two whitespaces for the indent.

Method Summary

Modifier and TypeMethod and Description
private static String
private String
quote(String name)

private <T> Runnable
writeAll(Iterator<T> it, Consumer<T> writer)

public void
writeArray(List<?>
the items to write
items
)

Write an array with the specified items.

private void
writeArray(List<?> items, boolean newLine)

private void
public void
writeObject(Map<String, Object>
the attributes of the object
attributes
)

Write an object with the specified attributes.

private void
writeObject(Map<String, Object> attributes, boolean newLine)

private void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

writerback to summary
private final BasicJsonWriter.IndentingWriter writer

Constructor Detail

BasicJsonWriterback to summary
public BasicJsonWriter(Writer writer, String singleIndent)

Create a new instance with the specified indent value.

Parameters
writer:Writer

the writer to use

singleIndent:String

the value of one indent

BasicJsonWriterback to summary
public BasicJsonWriter(Writer writer)

Create a new instance using two whitespaces for the indent.

Parameters
writer:Writer

the writer to use

Method Detail

escapeback to summary
private static String escape(CharSequence input)
quoteback to summary
private String quote(String name)
writeAllback to summary
private <T> Runnable writeAll(Iterator<T> it, Consumer<T> writer)
writeArrayback to summary
public void writeArray(List<?> items)

Write an array with the specified items. Each item in the list is written either as a nested object or as an attribute depending on its type.

Parameters
items:List<?>

the items to write

See Also
writeObject(Map)
writeArrayback to summary
private void writeArray(List<?> items, boolean newLine)
writeAttributeback to summary
private void writeAttribute(String name, Object value)
writeObjectback to summary
public void writeObject(Map<String, Object> attributes)

Write an object with the specified attributes. Each attribute is written according to its value type:

  • Map: write the value as a nested object
  • List: write the value as a nested array
  • Otherwise, write a single value
Parameters
attributes:Map<String, Object>

the attributes of the object

writeObjectback to summary
private void writeObject(Map<String, Object> attributes, boolean newLine)
writeValueback to summary
private void writeValue(Object value)
Annotations
@SuppressWarnings:unchecked
org.springframework.aot.nativex back to summary

pack-priv Class BasicJsonWriter.IndentingWriter

extends Writer
Class Inheritance

Field Summary

Modifier and TypeField and Description
private String
private int
private final Writer
private boolean
private final String
Inherited from java.io.Writer:
lock

Constructor Summary

AccessConstructor and Description
pack-priv
IndentingWriter(Writer out, String singleIndent)

Method Summary

Modifier and TypeMethod and Description
public void
close()

Implements abstract java.io.Writer.close.

Implements java.io.Closeable.close.

Closes the stream, flushing it first.

public void
flush()

Implements abstract java.io.Writer.flush.

Implements java.io.Flushable.flush.

Flushes the stream.

private BasicJsonWriter.IndentingWriter
indent()

Increase the indentation level.

public BasicJsonWriter.IndentingWriter
indented(Runnable
the code to execute within an extra indentation level
runnable
)

Increase the indentation level and execute the Runnable.

private BasicJsonWriter.IndentingWriter
outdent()

Decrease the indentation level.

public BasicJsonWriter.IndentingWriter
print(String
the content to write
string
)

Write the specified text.

public BasicJsonWriter.IndentingWriter
println(String
the content to write
string
)

Write the specified text and append a new line.

public BasicJsonWriter.IndentingWriter
println()

Write a new line.

private BasicJsonWriter.IndentingWriter
public void
write(char[]
Array of characters
chars
,
int
Offset from which to start writing characters
offset
,
int
Number of characters to write
length
)

Implements abstract java.io.Writer.write.

Writes a portion of an array of characters.

Inherited from java.io.Writer:
appendappendappendnullWriterwritewritewritewrite

Field Detail

currentIndentback to summary
private String currentIndent
levelback to summary
private int level
outback to summary
private final Writer out
prependIndentback to summary
private boolean prependIndent
singleIndentback to summary
private final String singleIndent

Constructor Detail

IndentingWriterback to summary
pack-priv IndentingWriter(Writer out, String singleIndent)

Method Detail

closeback to summary
public void close() throws IOException

Implements abstract java.io.Writer.close.

Implements java.io.Closeable.close.

Doc from java.io.Writer.close.

Closes the stream, flushing it first. Once the stream has been closed, further write() or flush() invocations will cause an IOException to be thrown. Closing a previously closed stream has no effect.

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs
flushback to summary
public void flush() throws IOException

Implements abstract java.io.Writer.flush.

Implements java.io.Flushable.flush.

Doc from java.io.Writer.flush.

Flushes the stream. If the stream has saved any characters from the various write() methods in a buffer, write them immediately to their intended destination. Then, if that destination is another character or byte stream, flush it. Thus one flush() invocation will flush all the buffers in a chain of Writers and OutputStreams.

If the intended destination of this stream is an abstraction provided by the underlying operating system, for example a file, then flushing the stream guarantees only that bytes previously written to the stream are passed to the operating system for writing; it does not guarantee that they are actually written to a physical device such as a disk drive.

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs
indentback to summary
private BasicJsonWriter.IndentingWriter indent()

Increase the indentation level.

indentedback to summary
public BasicJsonWriter.IndentingWriter indented(Runnable runnable)

Increase the indentation level and execute the Runnable. Decrease the indentation level on completion.

Parameters
runnable:Runnable

the code to execute within an extra indentation level

outdentback to summary
private BasicJsonWriter.IndentingWriter outdent()

Decrease the indentation level.

printback to summary
public BasicJsonWriter.IndentingWriter print(String string)

Write the specified text.

Parameters
string:String

the content to write

printlnback to summary
public BasicJsonWriter.IndentingWriter println(String string)

Write the specified text and append a new line.

Parameters
string:String

the content to write

printlnback to summary
public BasicJsonWriter.IndentingWriter println()

Write a new line.

refreshIndentback to summary
private BasicJsonWriter.IndentingWriter refreshIndent()
writeback to summary
public void write(char[] chars, int offset, int length)

Implements abstract java.io.Writer.write.

Doc from java.io.Writer.write.

Writes a portion of an array of characters.

Parameters
chars:char[]

Array of characters

offset:int

Offset from which to start writing characters

length:int

Number of characters to write

Annotations
@Override