package com.safaribooks.junitattachments;

import java.io.File;
import java.io.IOException;

import org.apache.commons.io.FileUtils;

public class RecordAttachment {

    public static void record(File path, byte[] value) {
        try {
            FileUtils.writeByteArrayToFile(path, value);

            System.out.println();
            // according to
            // https://wiki.jenkins-ci.org/display/JENKINS/JUnit+Attachments+Plugin
            // format must be [[ATTACHMENT|/absolute/path/to/some/file]]
            System.out.println("[[ATTACHMENT|" + path.getAbsolutePath() + "]]");
            System.out.println();

        } catch (IOException e1) {
            System.out.println("unable to write'" + path + "':" + e1);
        }
    }
}

@@ -160,20 +160,17 @@
 ment %7B%0A%0A
-    
+%09
 public s
@@ -197,17 +197,16 @@
 le path,
- 
 byte%5B%5D v
@@ -214,37 +214,21 @@
 lue)
- 
 %7B%0A
-        try %7B%0A            
+%09%09try %7B%0A%09%09%09
 File
@@ -269,28 +269,19 @@
 alue);%0A%0A
-            
+%09%09%09
 System.o
@@ -294,28 +294,19 @@
 ntln();%0A
-            
+%09%09%09
 // accor
@@ -312,31 +312,16 @@
 rding to
-%0A            //
  https:/
@@ -382,28 +382,19 @@
 +Plugin%0A
-            
+%09%09%09
 // forma
@@ -446,28 +446,19 @@
 /file%5D%5D%0A
-            
+%09%09%09
 System.o
@@ -517,29 +517,21 @@
 + %22%5D%5D%22);
-%0A            
+ %0A%09%09%09
 System.o
@@ -544,25 +544,22 @@
 ntln();%0A
-%0A        
+%09%09%09%0A%09%09
 %7D catch 
@@ -581,20 +581,11 @@
 ) %7B%0A
-            
+%09%09%09
 Syst
@@ -643,22 +643,13 @@
 1);%0A
-        %7D%0A    
+%09%09%7D%0A%09
 %7D%0A%7D%0A

Correct formatting