public Template createTemplate(File file) throws CompilationFailedException, ClassNotFoundException, IOException { Reader reader = new FileReader(file); try { return createTemplate(reader); } finally { DefaultGroovyMethodsSupport.closeWithWarning(reader); } }
public void copyBinaryResource(String template, String destFileName) { if (resourceManager instanceof ClasspathResourceManager) { OutputStream outputStream = null; try { InputStream inputStream = ((ClasspathResourceManager) resourceManager).getInputStream(template); outputStream = new FileOutputStream(destFileName); IOGroovyMethods.leftShift(outputStream, inputStream); } catch (IOException e) { System.err.println("Resource " + template + " skipped due to: " + e.getMessage()); } catch (NullPointerException e) { System.err.println("Resource " + template + " not found so skipped"); } finally { DefaultGroovyMethodsSupport.closeQuietly(outputStream); } } } }
@SuppressWarnings("unchecked") protected static <T> Collection<T> cloneSimilarCollection(Collection<T> orig, int newCapacity) { Collection<T> answer = (Collection<T>) cloneObject(orig); if (answer != null) return answer; // fall back to creation answer = createSimilarCollection(orig, newCapacity); answer.addAll(orig); return answer; }
protected static <T> Collection<T> createSimilarCollection(Collection<T> orig, int newCapacity) { if (orig instanceof Set) { return createSimilarSet((Set<T>) orig); } if (orig instanceof List) { return createSimilarList((List<T>) orig, newCapacity); } if (orig instanceof Queue) { return createSimilarQueue((Queue<T>) orig); } return new ArrayList<T>(newCapacity); }
/** * get value from char[] using normalized index */ public static char cArrayGet(char[] a, int i) { try { return a[i]; } catch (Throwable t) { return a[DefaultGroovyMethodsSupport.normaliseIndex(i,a.length)]; } }
protected static Collection createSimilarCollection(Collection collection, int newCapacity) { if (collection instanceof Set) { return createSimilarSet((Set) collection); } if (collection instanceof List) { return createSimilarList((List) collection, newCapacity); } return new ArrayList(newCapacity); }
protected static Collection createSimilarOrDefaultCollection(Object object) { if (object instanceof Collection) { return createSimilarCollection((Collection<?>) object); } return new ArrayList(); }
@SuppressWarnings("unchecked") protected static <K, V> Map<K ,V> cloneSimilarMap(Map<K, V> orig) { Map<K, V> answer = (Map<K, V>) cloneObject(orig); if (answer != null) return answer;
/** * get value from float[] using normalized index */ public static float fArrayGet(float[] a, int i) { try { return a[i]; } catch (Throwable t) { return a[DefaultGroovyMethodsSupport.normaliseIndex(i,a.length)]; } }
protected static Collection createSimilarCollection(Collection orig, int newCapacity) { if (orig instanceof Set) { return createSimilarSet((Set) orig); } if (orig instanceof List) { return createSimilarList((List) orig, newCapacity); } if (orig instanceof Queue) { return new LinkedList(); } return new ArrayList(newCapacity); }
protected static <T> Collection<T> createSimilarCollection(Iterable<T> iterable) { if (iterable instanceof Collection) { return createSimilarCollection((Collection<T>) iterable); } else { return new ArrayList<T>(); } }
protected static <K, V> Map<K ,V> cloneSimilarMap(Map<K, V> orig) { Map<K, V> answer = (Map<K, V>) cloneObject(orig); if (answer != null) return answer; // fall back to some defaults if (orig instanceof TreeMap) return new TreeMap<K, V>(orig); if (orig instanceof Properties) { Map<K, V> map = (Map<K, V>) new Properties(); map.putAll(orig); return map; } if (orig instanceof Hashtable) return new Hashtable<K, V>(orig); return new LinkedHashMap<K, V>(orig); }
public Template createTemplate(URL url) throws CompilationFailedException, ClassNotFoundException, IOException { Reader reader = new InputStreamReader(url.openStream()); try { return createTemplate(reader); } finally { DefaultGroovyMethodsSupport.closeWithWarning(reader); } } }
/** * get value from byte[] using normalized index */ public static byte bArrayGet(byte[] a, int i) { try { return a[i]; } catch (Throwable t) { return a[DefaultGroovyMethodsSupport.normaliseIndex(i,a.length)]; } }
protected static <T> Collection<T> createSimilarCollection(Collection<T> orig, int newCapacity) { if (orig instanceof Set) { return createSimilarSet((Set<T>) orig); } if (orig instanceof List) { return createSimilarList((List<T>) orig, newCapacity); } if (orig instanceof Queue) { return new LinkedList<T>(); } return new ArrayList<T>(newCapacity); }
@SuppressWarnings("unchecked") protected static <T> Collection<T> cloneSimilarCollection(Collection<T> orig, int newCapacity) { Collection<T> answer = (Collection<T>) cloneObject(orig); if (answer != null) return answer; // fall back to creation answer = createSimilarCollection(orig, newCapacity); answer.addAll(orig); return answer; }
protected static <T> Collection<T> createSimilarCollection(Collection<T> collection) { return createSimilarCollection(collection, collection.size()); }
private void scanExtensionModuleFromMetaInf(final URL metadata) { Properties properties = new Properties(); InputStream inStream = null; try { inStream = URLStreams.openUncachedStream(metadata); properties.load(inStream); } catch (IOException e) { throw new GroovyRuntimeException("Unable to load module META-INF descriptor", e); } finally { closeQuietly(inStream); } scanExtensionModuleFromProperties(properties); }
protected static Map cloneSimilarMap(Map orig) { Map answer = (Map) cloneObject(orig); if (answer != null) return answer; // fall back to some defaults if (orig instanceof TreeMap) return new TreeMap(orig); if (orig instanceof Properties) { Map map = new Properties(); map.putAll(orig); return map; } if (orig instanceof Hashtable) return new Hashtable(orig); return new LinkedHashMap(orig); }
public void run() { InputStream in = new BufferedInputStream(getIn(left)); OutputStream out = new BufferedOutputStream(getOut(right)); byte[] buf = new byte[8192]; int next; try { while ((next = in.read(buf)) != -1) { out.write(buf, 0, next); } } catch (IOException e) { throw new GroovyRuntimeException("exception while reading process stream", e); } finally { closeWithWarning(out); closeWithWarning(in); } } }).start();