public PageImpl(final int pageNumber, final int resultsPerPage) { super(); Assert.greaterThan(pageNumber, 0, "pageNumber"); Assert.greaterThan(resultsPerPage, 0, "resultsPerPage"); this.pageNumber = pageNumber; this.resultsPerPage = resultsPerPage; }
public Collection<LDAPSearchResult> search(final LDAPFilter filter) { Assert.notNull(filter, "filter"); try { if ((this.connectOnSearch) && (!this.isConnected())) { this.connect(); } Assert.notNull(this.context, "context"); SearchControls controls = new SearchControls(); controls.setReturningAttributes(filter.getAttributes()); controls.setCountLimit(filter.getLimit()); controls.setTimeLimit(0); controls.setSearchScope(SearchControls.SUBTREE_SCOPE); NamingEnumeration<SearchResult> results = this.context.search(filter.getBaseName(), filter.getFilter(), controls); Collection<LDAPSearchResult> c = LDAPHelper.toCollection(results); if (this.connectOnSearch) { this.disconnect(); } return c; } catch (NamingException e) { throw new LDAPException(e); } }
public static String toString(final Reader reader, final Charset charset) throws IOException { Assert.notNull(reader, "reader"); Assert.notNull(charset, "charset"); byte[] bytes = IOUtils.toByteArray(reader); String s = new String(bytes, charset); return s; }
public static String toString(final InputStream inputStream, final Charset charset) throws IOException { Assert.notNull(inputStream, "inputStream"); Assert.notNull(charset, "charset"); byte[] bytes = IOUtils.toByteArray(inputStream); String s = new String(bytes, charset); return s; }
public static void copy(final Reader reader, final Writer writer) throws IOException { Assert.notNull(reader, "reader"); Assert.notNull(writer, "writer"); int i = 0; char[] chars = new char[IOUtils.BUFFER_SIZE]; do { i = reader.read(chars); if (i != -1) { writer.write(chars, 0, i); } } while (i != -1); }
public static void copy(final InputStream inputStream, final OutputStream outputStream) throws IOException { Assert.notNull(inputStream, "inputStream"); Assert.notNull(outputStream, "outputStream"); int i = 0; byte[] bytes = new byte[IOUtils.BUFFER_SIZE]; do { i = inputStream.read(bytes); if (i != -1) { outputStream.write(bytes, 0, i); } } while (i != -1); }
public static InputStream gunzip(final InputStream inputStream) throws IOException { Assert.notNull(inputStream, "inputStream"); GZIPInputStream gzipInputStream = new GZIPInputStream(inputStream); InputOutputStream inputOutputStream = new InputOutputStream(); IOUtils.copy(gzipInputStream, inputOutputStream); return inputOutputStream.getInputStream(); }
public static byte[] toByteArray(final InputStream inputStream) throws IOException { Assert.notNull(inputStream, "inputStream"); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); IOUtils.copy(inputStream, outputStream); return outputStream.toByteArray(); }
public static byte[] toByteArray(final Reader reader) throws IOException { Assert.notNull(reader, "reader"); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); Writer writer = new OutputStreamWriter(outputStream); IOUtils.copy(reader, writer); return outputStream.toByteArray(); }
@Override public Cache get(final String id) { Assert.notEmpty(id, "id"); for (Cache cache : this.caches) { if (((MemoryCacheImpl) cache).getId().equals(id)) { return cache; } } return null; }
@Override public Cache create(final String id) { Assert.notEmpty(id, "id"); if (this.contains(id)) { throw new IllegalArgumentException("A cache with name " + id + " already exists"); } Cache c = new MemoryCacheImpl(id); this.caches.add(c); return c; }
public static byte[] toByteArray(final File file) throws IOException { Assert.notNull(file, "file"); FileInputStream inputStream = new FileInputStream(file); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); IOUtils.copy(inputStream, outputStream); inputStream.close(); return outputStream.toByteArray(); }
@Override public void remove(final String id) { Assert.notEmpty(id, "id"); Iterator<Cache> iterator = this.caches.iterator(); while (iterator.hasNext()) { Cache cache = iterator.next(); if (((MemoryCacheImpl) cache).getId().equals(id)) { iterator.remove(); break; } } }
@Override public boolean contains(final String id) { Assert.notEmpty(id, "id"); boolean b = false; for (Cache cache : this.caches) { if (((MemoryCacheImpl) cache).getId().equals(id)) { b = true; break; } } return b; }
public static InputStream gunzip(final byte[] bytes) throws IOException { Assert.notNull(bytes, "bytes"); return IOUtils.gunzip(new ByteArrayInputStream(bytes)); }
public static Reader toReader(final InputStream inputStream) { Assert.notNull(inputStream, "inputStream"); return new InputStreamReader(inputStream); }