Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #1645 adding until 12 indent levels #1747

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2021 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0, which is available at
Expand All @@ -21,21 +21,21 @@
/**
* {@link UTF8XmlOutput} with indentation.
*
* TODO: not sure if it's a good idea to move the indenting functionality to another class.
*
* Doesn't have to be final, but it helps the JVM.
*
* @author Kohsuke Kawaguchi
*/
public final class IndentingUTF8XmlOutput extends UTF8XmlOutput {

private static final int MAX_DEPTH = 12;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private static final int MAX_DEPTH = 12;
private static final int MAX_DEPTH = Integer.getInteger("jaxb.ri.max_depth", 12);

/**
* Null if the writer should perform no indentation.
*
* Otherwise this will keep the 8 copies of the string for indentation.
* (so that we can write 8 indentation at once.)
* Otherwise this will keep the MAX_DEPTH copies of the string for indentation.
* (so that we can write MAX_DEPTH indentation at once.)
*/
private final Encoded indent8;
private final Encoded indentDepth;

/**
* Length of one indentation.
Expand All @@ -57,13 +57,13 @@ public IndentingUTF8XmlOutput(OutputStream out, String indentStr, Encoded[] loca

if(indentStr!=null) {
Encoded e = new Encoded(indentStr);
indent8 = new Encoded();
indent8.ensureSize(e.len*8);
indentDepth = new Encoded();
indentDepth.ensureSize(e.len*MAX_DEPTH);
unitLen = e.len;
for( int i=0; i<8; i++ )
System.arraycopy(e.buf, 0, indent8.buf, unitLen*i, unitLen);
for( int i=0; i<MAX_DEPTH; i++ )
System.arraycopy(e.buf, 0, indentDepth.buf, unitLen*i, unitLen);
} else {
this.indent8 = null;
this.indentDepth = null;
this.unitLen = 0;
}
}
Expand Down Expand Up @@ -109,14 +109,15 @@ private void indentEndTag() throws IOException {

private void printIndent() throws IOException {
write('\n');
int i = depth%8;
int i = depth%MAX_DEPTH;

write( indent8.buf, 0, i*unitLen );
write( indentDepth.buf, 0, i*unitLen );

i>>=3; // really i /= 8;
//i>>=3; // really i /= 8;
i /= MAX_DEPTH;

for( ; i>0; i-- )
indent8.write(this);
indentDepth.write(this);
}

@Override
Expand Down