Changeset 8132 in josm for trunk/src/com/drew/lang/StringUtil.java
- Timestamp:
- 2015-03-10T01:17:39+01:00 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified trunk/src/com/drew/lang/StringUtil.java ¶
r6127 r8132 1 1 /* 2 * Copyright 2002-201 2Drew Noakes2 * Copyright 2002-2015 Drew Noakes 3 3 * 4 4 * Licensed under the Apache License, Version 2.0 (the "License"); … … 16 16 * More information about this project is available at: 17 17 * 18 * http://drewnoakes.com/code/exif/ 19 * http ://code.google.com/p/metadata-extractor/18 * https://drewnoakes.com/code/exif/ 19 * https://github.com/drewnoakes/metadata-extractor 20 20 */ 21 21 … … 23 23 24 24 import com.drew.lang.annotations.NotNull; 25 import com.drew.lang.annotations.Nullable; 25 26 27 import java.io.BufferedReader; 28 import java.io.IOException; 29 import java.io.InputStream; 30 import java.io.InputStreamReader; 26 31 import java.util.Iterator; 27 32 28 /** @author Drew Noakes http://drewnoakes.com */ 33 /** 34 * @author Drew Noakes https://drewnoakes.com 35 */ 29 36 public class StringUtil 30 37 { 38 @NotNull 31 39 public static String join(@NotNull Iterable<? extends CharSequence> strings, @NotNull String delimiter) 32 40 { … … 50 58 } 51 59 60 @NotNull 52 61 public static <T extends CharSequence> String join(@NotNull T[] strings, @NotNull String delimiter) 53 62 { … … 69 78 return buffer.toString(); 70 79 } 80 81 @NotNull 82 public static String fromStream(@NotNull InputStream stream) throws IOException 83 { 84 BufferedReader reader = new BufferedReader(new InputStreamReader(stream)); 85 StringBuilder sb = new StringBuilder(); 86 String line; 87 while ((line = reader.readLine()) != null) { 88 sb.append(line); 89 } 90 return sb.toString(); 91 } 92 93 public static int compare(@Nullable String s1, @Nullable String s2) 94 { 95 boolean null1 = s1 == null; 96 boolean null2 = s2 == null; 97 98 if (null1 && null2) { 99 return 0; 100 } else if (null1) { 101 return -1; 102 } else if (null2) { 103 return 1; 104 } else { 105 return s1.compareTo(s2); 106 } 107 } 108 109 @NotNull 110 public static String urlEncode(@NotNull String name) 111 { 112 // Sufficient for now, it seems 113 return name.replace(" ", "%20"); 114 } 71 115 }
Note:
See TracChangeset
for help on using the changeset viewer.