| 1 | /** | 
| 2 | * Licensed to jclouds, Inc. (jclouds) under one or more | 
| 3 | * contributor license agreements.  See the NOTICE file | 
| 4 | * distributed with this work for additional information | 
| 5 | * regarding copyright ownership.  jclouds licenses this file | 
| 6 | * to you under the Apache License, Version 2.0 (the | 
| 7 | * "License"); you may not use this file except in compliance | 
| 8 | * with the License.  You may obtain a copy of the License at | 
| 9 | * | 
| 10 | *   http://www.apache.org/licenses/LICENSE-2.0 | 
| 11 | * | 
| 12 | * Unless required by applicable law or agreed to in writing, | 
| 13 | * software distributed under the License is distributed on an | 
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | 
| 15 | * KIND, either express or implied.  See the License for the | 
| 16 | * specific language governing permissions and limitations | 
| 17 | * under the License. | 
| 18 | */ | 
| 19 | package org.jclouds.util; | 
| 20 |  | 
| 21 | import java.io.IOException; | 
| 22 | import java.io.InputStream; | 
| 23 | import java.io.OutputStream; | 
| 24 | import java.lang.reflect.InvocationTargetException; | 
| 25 | import java.util.Comparator; | 
| 26 | import java.util.List; | 
| 27 | import java.util.Map; | 
| 28 | import java.util.Properties; | 
| 29 | import java.util.Map.Entry; | 
| 30 | import java.util.regex.Pattern; | 
| 31 |  | 
| 32 | import org.jclouds.javax.annotation.Nullable; | 
| 33 |  | 
| 34 | import org.jclouds.PropertiesBuilder; | 
| 35 | import org.jclouds.domain.Credentials; | 
| 36 | import org.jclouds.rest.Providers; | 
| 37 | import org.jclouds.rest.RestContextBuilder; | 
| 38 |  | 
| 39 | import com.google.common.base.Supplier; | 
| 40 | import com.google.common.io.OutputSupplier; | 
| 41 | import com.google.inject.Module; | 
| 42 | import com.google.inject.ProvisionException; | 
| 43 | import com.google.inject.util.Modules; | 
| 44 |  | 
| 45 | /** | 
| 46 | * General utilities used in jclouds code. | 
| 47 | * | 
| 48 | * <h4>note</h4> Please look for locations of new utility methods | 
| 49 | * | 
| 50 | * @author Adrian Cole | 
| 51 | */ | 
| 52 | @Deprecated | 
| 53 | public class Utils { | 
| 54 |  | 
| 55 | /** | 
| 56 | * | 
| 57 | * @see Throwables2.propagateAuthorizationOrOriginalException | 
| 58 | */ | 
| 59 | @Deprecated | 
| 60 | public static <T> T propagateAuthorizationOrOriginalException(Exception e) { | 
| 61 | return Throwables2.<T> propagateAuthorizationOrOriginalException(e); | 
| 62 | } | 
| 63 |  | 
| 64 | /** | 
| 65 | * | 
| 66 | * @see Lists2#multiMax | 
| 67 | */ | 
| 68 | @Deprecated | 
| 69 | public static <T, E extends T> List<E> multiMax(Comparator<T> ordering, Iterable<E> iterable) { | 
| 70 | return Lists2.<T, E> multiMax(ordering, iterable); | 
| 71 | } | 
| 72 |  | 
| 73 | /** | 
| 74 | * | 
| 75 | * @see Throwables2#propagateOrNull | 
| 76 | */ | 
| 77 | @Deprecated | 
| 78 | public static <T> T propagateOrNull(Exception from) { | 
| 79 | return Throwables2.<T> propagateOrNull(from); | 
| 80 | } | 
| 81 |  | 
| 82 | /** | 
| 83 | * | 
| 84 | * @see Throwables2#getFirstThrowableOfType(Throwable, Class) | 
| 85 | */ | 
| 86 | @Deprecated | 
| 87 | public static <T extends Throwable> T getFirstThrowableOfType(Throwable from, Class<T> clazz) { | 
| 88 | return Throwables2.<T> getFirstThrowableOfType(from, clazz); | 
| 89 | } | 
| 90 |  | 
| 91 | /** | 
| 92 | * | 
| 93 | * @see Throwables2#getFirstThrowableOfType(ProvisionException, Class) | 
| 94 | */ | 
| 95 | @Deprecated | 
| 96 | public static <T extends Throwable> T getFirstThrowableOfType(ProvisionException e, Class<T> clazz) { | 
| 97 | return Throwables2.<T> getFirstThrowableOfType(e, clazz); | 
| 98 | } | 
| 99 |  | 
| 100 | /** | 
| 101 | * | 
| 102 | * @see Strings2#replaceTokens | 
| 103 | */ | 
| 104 | @Deprecated | 
| 105 | public static String replaceTokens(String value, Iterable<Entry<String, String>> tokenValues) { | 
| 106 | return Strings2.replaceTokens(value, tokenValues); | 
| 107 | } | 
| 108 |  | 
| 109 | /** | 
| 110 | * | 
| 111 | * @see Strings2#replaceAll(String,Pattern, String) | 
| 112 | */ | 
| 113 | @Deprecated | 
| 114 | public static String replaceAll(String returnVal, Pattern pattern, String replace) { | 
| 115 | return Strings2.replaceAll(returnVal, pattern, replace); | 
| 116 | } | 
| 117 |  | 
| 118 | /** | 
| 119 | * | 
| 120 | * @see Strings2#replaceAll(String,char,Pattern, String) | 
| 121 | */ | 
| 122 | @Deprecated | 
| 123 | public static String replaceAll(String input, char ifMatch, Pattern pattern, String replacement) { | 
| 124 | return Strings2.replaceAll(input, ifMatch, pattern, replacement); | 
| 125 | } | 
| 126 |  | 
| 127 | /** | 
| 128 | * | 
| 129 | * @see Strings2#replaceAll(String,char, String) | 
| 130 | */ | 
| 131 | @Deprecated | 
| 132 | public static String replaceAll(String input, char match, String replacement) { | 
| 133 | return Strings2.replaceAll(input, match, replacement); | 
| 134 | } | 
| 135 |  | 
| 136 | /** | 
| 137 | * | 
| 138 | * @see Suppliers2#newOutputStreamSupplier | 
| 139 | */ | 
| 140 | @Deprecated | 
| 141 | public static OutputSupplier<OutputStream> newOutputStreamSupplier(final OutputStream output) { | 
| 142 | return Suppliers2.newOutputStreamSupplier(output); | 
| 143 | } | 
| 144 |  | 
| 145 | /** | 
| 146 | * | 
| 147 | * @see Assertions#eventuallyTrue | 
| 148 | */ | 
| 149 | @Deprecated | 
| 150 | public static boolean eventuallyTrue(Supplier<Boolean> assertion, long inconsistencyMillis) | 
| 151 | throws InterruptedException { | 
| 152 | return Assertions.eventuallyTrue(assertion, inconsistencyMillis); | 
| 153 | } | 
| 154 |  | 
| 155 | /** | 
| 156 | * | 
| 157 | * @see Strings2#toStringAndClose | 
| 158 | */ | 
| 159 | @Deprecated | 
| 160 | public static String toStringAndClose(InputStream input) throws IOException { | 
| 161 | return Strings2.toStringAndClose(input); | 
| 162 | } | 
| 163 |  | 
| 164 | /** | 
| 165 | * | 
| 166 | * @see Strings2#toInputStream | 
| 167 | */ | 
| 168 | @Deprecated | 
| 169 | public static InputStream toInputStream(String in) { | 
| 170 | return Strings2.toInputStream(in); | 
| 171 | } | 
| 172 |  | 
| 173 | /** | 
| 174 | * | 
| 175 | * @see Strings2#encodeString(String, String) | 
| 176 | */ | 
| 177 | @Deprecated | 
| 178 | public static byte[] encodeString(String str, String charsetName) { | 
| 179 | return Strings2.encodeString(str, charsetName); | 
| 180 | } | 
| 181 |  | 
| 182 | /** | 
| 183 | * | 
| 184 | * @see Strings2#encodeString(String) | 
| 185 | */ | 
| 186 | @Deprecated | 
| 187 | public static byte[] encodeString(String str) { | 
| 188 | return Strings2.encodeString(str); | 
| 189 | } | 
| 190 |  | 
| 191 | /** | 
| 192 | * | 
| 193 | * @see Strings2#replaceTokens(String,Map) | 
| 194 | */ | 
| 195 | @Deprecated | 
| 196 | public static String replaceTokens(String input, Map<String, String> replacements) { | 
| 197 | return Strings2.replaceTokens(input, replacements); | 
| 198 | } | 
| 199 |  | 
| 200 | /** | 
| 201 | * | 
| 202 | * @see Preconditions2#checkNotEmpty(String) | 
| 203 | */ | 
| 204 | @Deprecated | 
| 205 | public static void checkNotEmpty(String nullableString) { | 
| 206 | Preconditions2.checkNotEmpty(nullableString); | 
| 207 | } | 
| 208 |  | 
| 209 | /** | 
| 210 | * | 
| 211 | * @see Preconditions2#checkNotEmpty(String,String) | 
| 212 | */ | 
| 213 | @Deprecated | 
| 214 | public static void checkNotEmpty(String nullableString, String message) { | 
| 215 | Preconditions2.checkNotEmpty(nullableString, message); | 
| 216 | } | 
| 217 |  | 
| 218 | /** | 
| 219 | * | 
| 220 | * @see Providers#getSupportedProviders | 
| 221 | */ | 
| 222 | @Deprecated | 
| 223 | public static Iterable<String> getSupportedProviders() { | 
| 224 | return Providers.getSupportedProviders(); | 
| 225 | } | 
| 226 |  | 
| 227 | /** | 
| 228 | * | 
| 229 | * @see Providers#getSupportedProvidersOfType | 
| 230 | */ | 
| 231 | @SuppressWarnings("unchecked") | 
| 232 | @Deprecated | 
| 233 | public static Iterable<String> getSupportedProvidersOfType(Class<? extends RestContextBuilder> type) { | 
| 234 | return Providers.getSupportedProvidersOfType(type); | 
| 235 | } | 
| 236 |  | 
| 237 | /** | 
| 238 | * | 
| 239 | * @see Providers#getSupportedProvidersOfTypeInProperties | 
| 240 | */ | 
| 241 | @SuppressWarnings("unchecked") | 
| 242 | @Deprecated | 
| 243 | public static Iterable<String> getSupportedProvidersOfTypeInProperties( | 
| 244 | final Class<? extends RestContextBuilder<?,?>> type, final Properties properties) { | 
| 245 | return Providers.getSupportedProvidersOfTypeInProperties(type, properties); | 
| 246 | } | 
| 247 |  | 
| 248 | /** | 
| 249 | * | 
| 250 | * @see Providers#resolveContextBuilderClass | 
| 251 | */ | 
| 252 | @Deprecated | 
| 253 | public static <S, A> Class<RestContextBuilder<S, A>> resolveContextBuilderClass(String provider, | 
| 254 | Properties properties) throws ClassNotFoundException, IllegalArgumentException, SecurityException, | 
| 255 | InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException { | 
| 256 | return Providers.<S, A> resolveContextBuilderClass(provider, properties); | 
| 257 | } | 
| 258 |  | 
| 259 | /** | 
| 260 | * | 
| 261 | * @see Providers#initContextBuilder | 
| 262 | */ | 
| 263 | @Deprecated | 
| 264 | public static <S, A> RestContextBuilder<S, A> initContextBuilder( | 
| 265 | Class<RestContextBuilder<S, A>> contextBuilderClass, @Nullable Class<S> sync, @Nullable Class<A> async, | 
| 266 | Properties properties) throws ClassNotFoundException, IllegalArgumentException, SecurityException, | 
| 267 | InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException { | 
| 268 | return Providers.<S, A> initContextBuilder(contextBuilderClass, sync, async, properties); | 
| 269 | } | 
| 270 |  | 
| 271 | /** | 
| 272 | * | 
| 273 | * @see Providers#resolvePropertiesBuilderClass | 
| 274 | */ | 
| 275 | @Deprecated | 
| 276 | public static Class<PropertiesBuilder> resolvePropertiesBuilderClass(String providerName, Properties props) | 
| 277 | throws ClassNotFoundException, InstantiationException, IllegalAccessException, InvocationTargetException, | 
| 278 | NoSuchMethodException { | 
| 279 | return Providers.resolvePropertiesBuilderClass(providerName, props); | 
| 280 | } | 
| 281 |  | 
| 282 | /** | 
| 283 | * | 
| 284 | * @see Modules#modulesForProviderInProperties | 
| 285 | */ | 
| 286 | @Deprecated | 
| 287 | public static Iterable<Module> modulesForProviderInProperties(String providerName, Properties props) { | 
| 288 | return Modules2.modulesForProviderInProperties(providerName, props); | 
| 289 | } | 
| 290 |  | 
| 291 | /** | 
| 292 | * | 
| 293 | * @see Modules#modulesFromProperty | 
| 294 | */ | 
| 295 | @Deprecated | 
| 296 | public static Iterable<Module> modulesFromProperty(Properties props, String property) { | 
| 297 | return Modules2.modulesFromProperty(props, property); | 
| 298 | } | 
| 299 |  | 
| 300 | /** | 
| 301 | * | 
| 302 | * @see Modules#modulesFromCommaDelimitedString | 
| 303 | */ | 
| 304 | @Deprecated | 
| 305 | public static Iterable<Module> modulesFromCommaDelimitedString(String moduleClasses) { | 
| 306 | return Modules2.modulesFromCommaDelimitedString(moduleClasses); | 
| 307 | } | 
| 308 |  | 
| 309 | /** | 
| 310 | * | 
| 311 | * @see CredentialUtils#isPrivateKeyCredential | 
| 312 | */ | 
| 313 | @Deprecated | 
| 314 | public static boolean isPrivateKeyCredential(Credentials credentials) { | 
| 315 | return CredentialUtils.isPrivateKeyCredential(credentials); | 
| 316 | } | 
| 317 |  | 
| 318 | /** | 
| 319 | * | 
| 320 | * @see CredentialUtils#overrideCredentialsIfSupplied | 
| 321 | */ | 
| 322 | @Deprecated | 
| 323 | public static Credentials overrideCredentialsIfSupplied(Credentials defaultCredentials, | 
| 324 | @Nullable Credentials overridingCredentials) { | 
| 325 | return CredentialUtils.overrideCredentialsIfSupplied(defaultCredentials, overridingCredentials); | 
| 326 | } | 
| 327 |  | 
| 328 | } |