Code example for StringWriter

Methods: appendwrite

0
	} 
 
	private void writeIdentation(boolean addNewLine) {
 
		if (addNewLine){
			writer.write("\n");
		} 
 
		Integer numberOfSpaces = number_of_spaces_to_use_for_identation.peek();
 
		if (numberOfSpaces == null){
			writer.write(" ");
		} 
		else{ 
			String spaces = String.format("%"+numberOfSpaces+"s", "");
			writer.write(spaces);
		} 
 
	} 
 
	public void writeAttribute(String name, String value){
 
		if (prettyPrint){
			writeIdentation(true); 
			writer.write(" ");
		} 
 
		writer.write(" ");
		writer.write(name);
		writer.write("=\"");
		char[] ch = value.toCharArray();
		write(ch, 0, ch.length, true);
		writer.write("\"");
	} 
	 
	 
	public void startElement(String name, boolean elementHasAttributes, boolean writeName) {
 
		if (prettyPrint){
			increaseNumberOfSpacesToUseForIndentation(); 
			writeIdentation(true); 
		} 
 
		writer.append("<");
		writer.append(name);
		 
		if (! elementHasAttributes){
			writer.append(">");
		} 
 
	} 
	 
	private void increaseNumberOfSpacesToUseForIndentation() { 
Contextual code suggestions in your IDE  Get Codota for Java