Java Code Examples for java.io.FilterInputStream
The following code examples are extracted from open source projects. You can click to
vote up the examples that are useful to you.
Example 1
From project jackrabbit-oak, under directory /oak-mk/src/test/java/org/apache/jackrabbit/mk/util/.
Source file: IOUtilsTest.java

public void testReadFully() throws IOException { final Random r=new Random(1); byte[] data=new byte[1000]; final AtomicInteger readCount=new AtomicInteger(); r.nextBytes(data); FilterInputStream in=new FilterInputStream(new ByteArrayInputStream(data)){ public int read( byte[] buffer, int off, int max) throws IOException { readCount.incrementAndGet(); if (r.nextInt(10) == 0) { return 0; } return in.read(buffer,off,Math.min(10,max)); } } ; in.mark(10000); byte[] test=new byte[1000]; assertEquals(0,IOUtils.readFully(in,test,0,0)); assertEquals(0,readCount.get()); assertEquals(1000,IOUtils.readFully(in,test,0,1000)); IOUtilsTest.assertEquals(data,test); test=new byte[1001]; in.reset(); in.mark(10000); assertEquals(1000,IOUtils.readFully(in,test,0,1001)); assertEquals(0,IOUtils.readFully(in,test,0,0)); }
Example 2
From project jackrabbit-oak, under directory /oak-mk/src/test/java/org/apache/jackrabbit/mk/util/.
Source file: IOUtilsTest.java

public void testSkipFully() throws IOException { final Random r=new Random(1); byte[] data=new byte[1000]; r.nextBytes(data); FilterInputStream in=new FilterInputStream(new ByteArrayInputStream(data)){ public int read( byte[] buffer, int off, int max) throws IOException { return in.read(buffer,off,Math.min(10,max)); } } ; in.mark(10000); IOUtils.skipFully(in,1000); assertEquals(-1,in.read()); in.reset(); try { IOUtils.skipFully(in,1001); fail(); } catch ( EOFException e) { } }
Example 3
From project nuxeo-tycho-osgi, under directory /nuxeo-core/nuxeo-core-api/src/main/java/org/nuxeo/ecm/core/url/nxobj/.
Source file: ObjectURLConnection.java

@Override public InputStream getInputStream() throws IOException { connect(); return new FilterInputStream(openStream()){ @Override public void close() throws IOException { super.close(); try { close(); } catch ( Exception e) { } } } ; }
Example 4
From project plexus-archiver, under directory /src/main/java/org/codehaus/plexus/archiver/tar/.
Source file: TarFile.java

/** * Returns an {@link InputStream} with the given entriescontents. This {@link InputStream} may be closed: Nothinghappens in that case, because an actual close would invalidate the underlying {@link TarInputStream}. */ public InputStream getInputStream(TarEntry entry) throws IOException { if (entry.equals((Object)currentEntry) && inputStream != null) { return new FilterInputStream(inputStream){ public void close() throws IOException { } } ; } return getInputStream(entry,currentEntry); }
Example 5
From project commons-compress, under directory /src/main/java/org/apache/commons/compress/compressors/pack200/.
Source file: Pack200CompressorInputStream.java

private Pack200CompressorInputStream(final InputStream in,final File f,final Pack200Strategy mode,final Map<String,String> props) throws IOException { originalInput=in; streamBridge=mode.newStreamBridge(); JarOutputStream jarOut=new JarOutputStream(streamBridge); Pack200.Unpacker u=Pack200.newUnpacker(); if (props != null) { u.properties().putAll(props); } if (f == null) { u.unpack(new FilterInputStream(in){ @Override public void close(){ } } ,jarOut); } else { u.unpack(f,jarOut); } jarOut.close(); }
Example 6
From project commons-fileupload, under directory /src/test/org/apache/commons/fileupload/.
Source file: StreamingTest.java

/** * Tests, whether an IOException is properly delegated. */ public void testIOException() throws IOException, FileUploadException { byte[] request=newRequest(); InputStream stream=new FilterInputStream(new ByteArrayInputStream(request)){ private int num; public int read() throws IOException { if (++num > 123) { throw new IOException("123"); } return super.read(); } public int read( byte[] pB, int pOff, int pLen) throws IOException { for (int i=0; i < pLen; i++) { int res=read(); if (res == -1) { return i == 0 ? -1 : i; } pB[pOff + i]=(byte)res; } return pLen; } } ; try { parseUpload(stream,request.length); } catch ( IOFileUploadException e) { assertTrue(e.getCause() instanceof IOException); assertEquals("123",e.getCause().getMessage()); } }
Example 7
From project fast-http, under directory /src/test/java/org/neo4j/smack/test/util/.
Source file: REST.java

private <T>T readEntity(ClientResponse response,Class<T> type){ try { final InputStream is=response.getEntityInputStream(); return jsonFactory.createJsonParser(new FilterInputStream(is){ @Override public int read() throws IOException { final int result=super.read(); System.out.print(Character.valueOf((char)result)); return result; } } ).readValueAs(type); } catch ( Exception e) { System.out.flush(); throw new RuntimeException("Error reading response object " + this,e); } }
Example 8
From project mylyn.context, under directory /org.eclipse.mylyn.context.core/src/org/eclipse/mylyn/internal/context/core/.
Source file: InteractionContextExternalizer.java

public InputStream getAdditionalInformation(File file,String contributorIdentifier) throws IOException { if (!file.exists()) { return null; } final ZipFile zipFile=new ZipFile(file); ZipEntry entry=findFileInZip(zipFile,contributorIdentifier); if (entry == null) { return null; } return new FilterInputStream(zipFile.getInputStream(entry)){ @Override public void close() throws IOException { super.close(); zipFile.close(); } } ; }
Example 9
From project nuxeo-tycho-osgi, under directory /nuxeo-core/nuxeo-core-api/src/main/java/org/nuxeo/ecm/core/url/nxdoc/.
Source file: PropertyURLConnection.java

@Override public InputStream getInputStream() throws IOException { if (!shared) { return new FilterInputStream(getStream()){ @Override public void close() throws IOException { super.close(); CoreInstance.getInstance().close(session); session=null; connected=false; } } ; } else { return getStream(); } }
Example 10
From project core_1, under directory /transform/src/test/java/org/switchyard/transform/ootb/.
Source file: OutOfTheBoxTransformersLoadingTest.java

@Test public void test_InputStream_Transforms_Loaded(){ Assert.assertNotNull(registry.getTransformer(qName(InputStream.class),qName(String.class))); Assert.assertNotNull(registry.getTransformer(qName(FilterInputStream.class),qName(String.class))); Assert.assertNotNull(registry.getTransformer(qName(InputStream.class),qName(byte[].class))); Assert.assertNotNull(registry.getTransformer(qName(FileInputStream.class),qName(byte[].class))); }
Example 11
From project legacy-maven-support, under directory /maven-agent/src/main/java/hudson/maven/agent/.
Source file: Main.java

/** * @param m2Home Maven2 installation. This is where we find Maven jars that we'll run. * @param remotingJar Hudson's remoting.jar that we'll load. * @param interceptorJar maven-interceptor.jar that we'll load. * @param tcpPort TCP socket that the launching Hudson will be listening to. This is used for the remoting communication. * @param interceptorOverrideJar Possibly null override jar to be placed in front of maven-interceptor.jar */ public static void main(File m2Home,File remotingJar,File interceptorJar,int tcpPort,File interceptorOverrideJar) throws Exception { try { m2Home=m2Home.getCanonicalFile(); } catch ( IOException e) { } if (!m2Home.exists()) { System.err.println("No such directory exists: " + m2Home); System.exit(1); } versionCheck(); System.setProperty("maven.home",m2Home.getPath()); System.setProperty("maven.interceptor",interceptorJar.getPath()); System.setProperty("maven.interceptor.override",(interceptorOverrideJar != null ? interceptorOverrideJar : interceptorJar).getPath()); boolean is206OrLater=!new File(m2Home,"core").exists(); launcher=new Launcher(); launcher.setSystemClassLoader(Main.class.getClassLoader()); launcher.configure(Main.class.getResourceAsStream(is206OrLater ? "classworlds-2.0.6.conf" : "classworlds.conf")); ClassRealm remoting=new DefaultClassRealm(launcher.getWorld(),"hudson-remoting",launcher.getSystemClassLoader()); remoting.setParent(launcher.getWorld().getRealm("plexus.core.maven")); remoting.addConstituent(remotingJar.toURI().toURL()); final Socket s=new Socket((String)null,tcpPort); Class remotingLauncher=remoting.loadClass("hudson.remoting.Launcher"); remotingLauncher.getMethod("main",new Class[]{InputStream.class,OutputStream.class}).invoke(null,new Object[]{new BufferedInputStream(new FilterInputStream(s.getInputStream()){ public void close() throws IOException { s.shutdownInput(); } } ),new BufferedOutputStream(new RealFilterOutputStream(s.getOutputStream()){ public void close() throws IOException { s.shutdownOutput(); } } )}); System.exit(0); }
Example 12
From project legacy-maven-support, under directory /maven3-agent/src/main/java/org/jvnet/hudson/maven3/agent/.
Source file: Maven3Main.java

/** * @param m2Home Maven2 installation. This is where we find Maven jars that we'll run. * @param remotingJar Hudson's remoting.jar that we'll load. * @param interceptorJar maven-listener.jar that we'll load. * @param tcpPort TCP socket that the launching Hudson will be listening to. This is used for the remoting communication. * @param projectBuildLaunch launch the projectBuilder and not a mavenExecution */ public static void main(File m2Home,File remotingJar,File interceptorJar,int tcpPort) throws Exception { try { m2Home=m2Home.getCanonicalFile(); } catch ( IOException e) { } if (!m2Home.exists()) { System.err.println("No such directory exists: " + m2Home); System.exit(1); } versionCheck(); System.setProperty("maven.home",m2Home.getPath()); if (interceptorJar != null) { System.setProperty("maven3.interceptor",interceptorJar.getPath()); } launcher=new Launcher(); launcher.setSystemClassLoader(Maven3Main.class.getClassLoader()); launcher.configure(Maven3Main.class.getResourceAsStream("classworlds.conf")); ClassRealm remoting=launcher.getWorld().newRealm("hudson-remoting",launcher.getSystemClassLoader()); remoting.setParentRealm(launcher.getWorld().getRealm("plexus.core")); remoting.addURL(remotingJar.toURI().toURL()); final Socket s=new Socket((String)null,tcpPort); Class remotingLauncher=remoting.loadClass("hudson.remoting.Launcher"); remotingLauncher.getMethod("main",new Class[]{InputStream.class,OutputStream.class}).invoke(null,new Object[]{new BufferedInputStream(new FilterInputStream(s.getInputStream()){ public void close() throws IOException { s.shutdownInput(); } } ),new BufferedOutputStream(new RealFilterOutputStream(s.getOutputStream()){ public void close() throws IOException { s.shutdownOutput(); } } )}); System.exit(0); }
Example 13
From project maven3-support, under directory /maven3-eventspy-common/src/main/java/org/hudsonci/maven/eventspy/common/.
Source file: RemotingClient.java

public void open() throws IOException, InterruptedException { if (isOpen()) { throw new IllegalStateException(); } log.debug("Opening w/port: {}",port); final Socket socket=new Socket((String)null,port); InputStream input=new BufferedInputStream(new FilterInputStream(socket.getInputStream()){ public void close() throws IOException { socket.shutdownInput(); } } ); OutputStream output=new BufferedOutputStream(new FilterOutputStream(socket.getOutputStream()){ public void close() throws IOException { socket.shutdownOutput(); } } ); channel=new Channel(getClass().getName(),executor,Channel.Mode.BINARY,input,output); log.debug("Opened"); }