1 package org.apache.maven.plugins.shade.resource.properties.io;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.BufferedWriter;
23 import java.io.IOException;
24 import java.io.Writer;
25
26
27
28
29 public class SkipPropertiesDateLineWriter extends BufferedWriter
30 {
31 private State currentState = State.MUST_SKIP_DATE_COMMENT;
32
33 public SkipPropertiesDateLineWriter( Writer out )
34 {
35 super( out );
36 }
37
38 @Override
39 public void write( String str ) throws IOException
40 {
41 if ( currentState.shouldSkip( str ) )
42 {
43 currentState = currentState.next();
44 return;
45 }
46 super.write( str );
47 }
48
49 private enum State
50 {
51 MUST_SKIP_DATE_COMMENT
52 {
53 @Override
54 boolean shouldSkip( String content )
55 {
56 return content.length() > 1 && content.startsWith( "#" ) && !content.startsWith( "# " );
57 }
58
59 @Override
60 State next()
61 {
62 return SKIPPED_DATE_COMMENT;
63 }
64 },
65 SKIPPED_DATE_COMMENT
66 {
67 @Override
68 boolean shouldSkip( String content )
69 {
70 return content.trim().isEmpty();
71 }
72
73 @Override
74 State next()
75 {
76 return DONE;
77 }
78 },
79 DONE
80 {
81 @Override
82 boolean shouldSkip( String content )
83 {
84 return false;
85 }
86
87 @Override
88 State next()
89 {
90 throw new UnsupportedOperationException( "done is a terminal state" );
91 }
92 };
93
94 abstract boolean shouldSkip( String content );
95 abstract State next();
96 }
97 }