Skip to content

Commit

Permalink
HDFS-13168. XmlImageVisitor - Prefer Array over LinkedList. Contribut…
Browse files Browse the repository at this point in the history
…ed by BELUGA BEHR.
  • Loading branch information
Inigo Goiri committed Feb 20, 2018
1 parent 9028cca commit 17c592e
Showing 1 changed file with 10 additions and 8 deletions.
Expand Up @@ -18,16 +18,17 @@
package org.apache.hadoop.hdfs.tools.offlineImageViewer;

import java.io.IOException;
import java.util.LinkedList;
import java.util.ArrayDeque;
import java.util.Deque;

import org.apache.hadoop.hdfs.util.XMLUtils;

/**
* An XmlImageVisitor walks over an fsimage structure and writes out
* an equivalent XML document that contains the fsimage's components.
*/
public class XmlImageVisitor extends TextWriterImageVisitor {
final private LinkedList<ImageElement> tagQ =
new LinkedList<ImageElement>();
final private Deque<ImageElement> tagQ = new ArrayDeque<>();

public XmlImageVisitor(String filename) throws IOException {
super(filename, false);
Expand All @@ -51,9 +52,10 @@ void finishAbnormally() throws IOException {

@Override
void leaveEnclosingElement() throws IOException {
if(tagQ.size() == 0)
if (tagQ.isEmpty()) {
throw new IOException("Tried to exit non-existent enclosing element " +
"in FSImage file");
"in FSImage file");
}

ImageElement element = tagQ.pop();
write("</" + element.toString() + ">\n");
Expand All @@ -71,20 +73,20 @@ void visit(ImageElement element, String value) throws IOException {

@Override
void visitEnclosingElement(ImageElement element) throws IOException {
write("<" + element.toString() + ">\n");
write('<' + element.toString() + ">\n");
tagQ.push(element);
}

@Override
void visitEnclosingElement(ImageElement element,
ImageElement key, String value)
throws IOException {
write("<" + element.toString() + " " + key + "=\"" + value +"\">\n");
write('<' + element.toString() + ' ' + key + "=\"" + value +"\">\n");
tagQ.push(element);
}

private void writeTag(String tag, String value) throws IOException {
write("<" + tag + ">" +
write('<' + tag + '>' +
XMLUtils.mangleXmlString(value, true) + "</" + tag + ">\n");
}
}

0 comments on commit 17c592e

Please sign in to comment.