Skip to content

Commit

Permalink
Add "foldLines" method to chaining API
Browse files Browse the repository at this point in the history
  • Loading branch information
mangstadt committed Aug 12, 2017
1 parent 234f3a9 commit f0e68fb
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/main/java/ezvcard/io/chain/ChainingTextWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public class ChainingTextWriter extends ChainingWriter<ChainingTextWriter> {
private VCardVersion version;
private boolean caretEncoding = false;
private Boolean includeTrailingSemicolons;
private boolean foldLines = true;
private TargetApplication targetApplication;

/**
Expand Down Expand Up @@ -116,6 +117,25 @@ public ChainingTextWriter includeTrailingSemicolons(Boolean include) {
return this;
}

/**
* <p>
* Sets whether to fold long lines. Line folding is when long lines are
* split up into multiple lines. No data is lost or changed when a line is
* folded.
* </p>
* <p>
* Line folding is enabled by default. If the vCard consumer is not parsing
* your vCards properly, disabling line folding may help.
* </p>
* @param foldLines true to enable line folding, false to disable it
* (defaults to true)
* @return this
*/
public ChainingTextWriter foldLines(boolean foldLines) {
this.foldLines = foldLines;
return this;
}

/**
* <p>
* Sets the application that the vCards will be targeted for.
Expand Down Expand Up @@ -213,6 +233,9 @@ private void go(VCardWriter writer) throws IOException {
writer.setCaretEncodingEnabled(caretEncoding);
writer.setVersionStrict(versionStrict);
writer.setIncludeTrailingSemicolons(includeTrailingSemicolons);
if (!foldLines) {
writer.getVObjectWriter().getFoldedLineWriter().setLineLength(null);
}
writer.setTargetApplication(targetApplication);
if (index != null) {
writer.setScribeIndex(index);
Expand Down
16 changes: 16 additions & 0 deletions src/test/java/ezvcard/EzvcardTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,22 @@ public void write_caretEncoding() throws Exception {
}
}

@Test
public void write_foldLines() throws Exception {
VCard vcard = new VCard();
vcard.addNote("In the beginning God created the heavens and the earth. Now the earth was formless and empty, darkness was over the surface of the deep, and the Spirit of God was hovering over the waters.");

//default should be "true"
String actual = Ezvcard.write(vcard).go();
assertTrue(actual.contains("\r\nNOTE:In the beginning God created the heavens and the earth. Now the earth \r\n was formless and empty\\, darkness was over the surface of the deep\\, and t\r\n he Spirit of God was hovering over the waters."));

actual = Ezvcard.write(vcard).foldLines(false).go();
assertTrue(actual.contains("\r\nNOTE:In the beginning God created the heavens and the earth. Now the earth was formless and empty\\, darkness was over the surface of the deep\\, and the Spirit of God was hovering over the waters."));

actual = Ezvcard.write(vcard).foldLines(true).go();
assertTrue(actual.contains("\r\nNOTE:In the beginning God created the heavens and the earth. Now the earth \r\n was formless and empty\\, darkness was over the surface of the deep\\, and t\r\n he Spirit of God was hovering over the waters."));
}

@Test
public void write_versionStrict() throws Exception {
VCard vcard = new VCard();
Expand Down

0 comments on commit f0e68fb

Please sign in to comment.