]>
Dogcows Code - chaz/vimcoder/blob - dogcows/Utilities.java
5 import java
.util
.Arrays
;
9 * @author Charles McGarvey
12 public abstract class Utilities
15 public static <T
> T
[] concat(T
[] a
, T
[] b
)
17 T
[] result
= Arrays
.copyOf(a
, a
.length
+ b
.length
);
18 System
.arraycopy(b
, 0, result
, a
.length
, b
.length
);
22 public static String
join(String
[] a
, String glue
)
24 if (a
.length
== 0) return "";
25 StringBuilder result
= new StringBuilder();
27 for (int i
= 1; i
< a
.length
; ++i
) result
.append(glue
).append(a
[i
]);
28 return result
.toString();
31 public static String
quote(String a
)
33 a
= a
.replaceAll("\\\\", "\\\\\\\\");
34 a
= a
.replaceAll("\"", "\\\\\\\"");
38 public static String
readFile(File file
) throws IOException
40 StringBuilder text
= new StringBuilder();
42 BufferedReader reader
= new BufferedReader(new FileReader(file
.getPath()));
47 while ((line
= reader
.readLine()) != null)
49 text
.append(line
+ System
.getProperty("line.separator"));
57 return text
.toString();
60 public static String
readResource(String path
) throws IOException
62 StringBuilder text
= new StringBuilder();
64 InputStream stream
= Utilities
.class.getResourceAsStream("resources/" + path
);
69 byte[] buffer
= new byte[4096];
71 while (0 < (numBytes
= stream
.read(buffer
)))
73 text
.append(new String(buffer
, 0, numBytes
));
82 return text
.toString();
85 public static String
expandTemplate(String template
, Map
<String
,String
> terms
)
87 String text
= template
;
88 for (String key
: terms
.keySet())
90 text
= text
.replaceAll("\\$" + key
+ "\\$",
91 Utilities
.quote(terms
.get(key
)));
This page took 0.0357 seconds and 4 git commands to generate.