Example usage for java.io InputStream skip

List of usage examples for java.io InputStream skip

Introduction

In this page you can find the example usage for java.io InputStream skip.

Prototype

public long skip(long n) throws IOException 

Source Link

Document

Skips over and discards n bytes of data from this input stream.

Usage

From source file:functionalTests.vfsprovider.TestProActiveProviderAutoclosing.java

@Test
public void testInputStreamOpenSkipAutocloseRead() throws Exception {
    final FileObject fo = openFileObject(TEST_FILENAME);
    // we have to use input stream to avoid Readers buffering (input stream buffering is ok) 
    final InputStream is = openInputStream(fo);
    try {//from  w  w  w . j a v a  2s .c om
        is.skip(TEST_FILE_A_CHARS_NUMBER);
        Thread.sleep(SLEEP_TIME);
        assertTrue('b' == is.read());
    } finally {
        is.close();
    }
    fo.close();
}

From source file:com.examples.with.different.packagename.coverage.BOMInputStreamTest.java

public void testSkipWithBOM() throws Exception {
    byte[] data = new byte[] { 'A', 'B', 'C', 'D' };
    InputStream in = new BOMInputStream(createDataStream(data, true));
    in.skip(2L);
    assertEquals('C', in.read());
}

From source file:com.examples.with.different.packagename.coverage.BOMInputStreamTest.java

public void testSkipWithoutBOM() throws Exception {
    byte[] data = new byte[] { 'A', 'B', 'C', 'D' };
    InputStream in = new BOMInputStream(createDataStream(data, false));
    in.skip(2L);
    assertEquals('C', in.read());
}

From source file:org.openremote.controller.protocol.samsungtv.SamsungTVSession.java

private String initialize() throws Exception {
    logger.debug("Creating socket for host " + ipAddress + " on port " + port);

    socket = new Socket();
    InetSocketAddress sockAddr = new InetSocketAddress(ipAddress, port);
    socket.connect(sockAddr, SAMSUNG_CONNECT_TIMEOUT);

    logger.debug("Socket successfully created and connected");
    InetAddress localAddress = socket.getLocalAddress();
    logger.debug("Local address is " + localAddress.getHostAddress());

    logger.debug("Sending registration message");
    writer = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
    writer.append((char) 0x00);
    writeText(writer, APP_STRING);/*from ww  w . j a va  2  s .c  o  m*/
    writeText(writer, getRegistrationPayload(localAddress.getHostAddress()));
    writer.flush();

    InputStream in = socket.getInputStream();
    reader = new InputStreamReader(in);
    String result = readRegistrationReply(reader);
    int i;
    while ((i = in.available()) > 0) {
        in.skip(i);
    }
    return result;
}

From source file:com.ibm.watson.developer_cloud.android.text_to_speech.v1.TTSUtility.java

public byte[] stripHeaderAndSaveWav(InputStream i) {
    byte[] d = new byte[0];
    try {//from w  ww . j a  va  2s  . c o m
        int headSize = 44;
        int metaDataSize = 48;
        i.skip(headSize + metaDataSize);
        d = IOUtils.toByteArray(i);
    } catch (IOException e) {
        Log.d(TAG, "Error while formatting header");
    }
    return saveWav(d);
}

From source file:ch.cyberduck.core.socket.HttpProxyAwareSocket.java

@Override
public void connect(final SocketAddress endpoint, final int timeout) throws IOException {
    if (proxy.type() == Proxy.Type.HTTP) {
        super.connect(proxy.address(), timeout);
        final InetSocketAddress address = (InetSocketAddress) endpoint;
        final OutputStream out = this.getOutputStream();
        IOUtils.write(String.format("CONNECT %s:%d HTTP/1.0\n\n", address.getHostName(), address.getPort()),
                out, Charset.defaultCharset());
        final InputStream in = this.getInputStream();
        final String response = new LineNumberReader(new InputStreamReader(in)).readLine();
        if (null == response) {
            throw new SocketException(String.format("Empty response from HTTP proxy %s",
                    ((InetSocketAddress) proxy.address()).getHostName()));
        }//from   w  w  w.  j a v  a 2  s. c om
        if (response.contains("200")) {
            in.skip(in.available());
        } else {
            throw new SocketException(String.format("Invalid response %s from HTTP proxy %s", response,
                    ((InetSocketAddress) proxy.address()).getHostName()));
        }
    } else {
        super.connect(endpoint, timeout);
    }
}

From source file:org.gss_project.gss.server.webdav.milton.GssFileResource.java

private IOException copyRange(InputStream istream, OutputStream ostream, long start, long end) {
    log.debug("Serving bytes:" + start + "-" + end);
    try {/*from  ww  w  .j  a va2 s.c  o m*/
        istream.skip(start);
    } catch (IOException e) {
        return e;
    }
    IOException exception = null;
    long bytesToRead = end - start + 1;
    byte buffer[] = new byte[input];
    int len = buffer.length;
    while (bytesToRead > 0 && len >= buffer.length) {
        try {
            len = istream.read(buffer);
            if (bytesToRead >= len) {
                ostream.write(buffer, 0, len);
                bytesToRead -= len;
            } else {
                ostream.write(buffer, 0, (int) bytesToRead);
                bytesToRead = 0;
            }
        } catch (IOException e) {
            exception = e;
            len = -1;
        }
        if (len < buffer.length)
            break;
    }
    return exception;
}

From source file:org.apache.jackrabbit.spi.commons.value.AbstractQValue.java

/**
 * This implementation creates a binary instance that uses
 * {@link #getStream()} and skipping on the given stream as its underlying
 * mechanism to provide random access defined on {@link Binary}.
 *
 * @see QValue#getBinary()/*from w  ww.j  a  va  2  s  .c o  m*/
 */
public Binary getBinary() throws RepositoryException {
    return new Binary() {
        public InputStream getStream() throws RepositoryException {
            return AbstractQValue.this.getStream();
        }

        public int read(byte[] b, long position) throws IOException, RepositoryException {
            InputStream in = getStream();
            try {
                in.skip(position);
                return in.read(b);
            } finally {
                in.close();
            }
        }

        public long getSize() throws RepositoryException {
            return getLength();
        }

        public void dispose() {
        }
    };
}

From source file:de.quist.samy.remocon.RemoteSession.java

private String initialize() throws UnknownHostException, IOException {
    logger.debug("Creating socket for host " + host + " on port " + port);

    socket = new Socket();
    socket.connect(new InetSocketAddress(host, port), 5000);

    logger.debug("Socket successfully created and connected");
    InetAddress localAddress = socket.getLocalAddress();
    logger.debug("Local address is " + localAddress.getHostAddress());

    logger.debug("Sending registration message");
    writer = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
    writer.append((char) 0x00);
    writeText(writer, APP_STRING);/* www  . ja  va  2 s  .com*/
    writeText(writer, getRegistrationPayload(localAddress.getHostAddress()));
    writer.flush();

    InputStream in = socket.getInputStream();
    reader = new InputStreamReader(in);
    String result = readRegistrationReply(reader);
    //sendPart2();
    int i;
    while ((i = in.available()) > 0) {
        in.skip(i);
    }
    return result;
}

From source file:net.seedboxer.camel.component.file.remote.ftp2.Ftp2Operations.java

private boolean resume(String targetName, InputStream is) throws IOException {
    Long size = getSize(targetName);

    // Set the offset
    client.setRestartOffset(size);//from ww w .  j ava 2 s  .c  om
    // Create stream and skip first SIZE bytes
    is.skip(size);

    try {
        OutputStream outs = client.storeFileStream(targetName);
        if (outs != null) {
            try {
                copyStream(is, outs, client.getBufferSize(), CopyStreamEvent.UNKNOWN_STREAM_SIZE,
                        client.getCopyStreamListener());
            } finally {
                outs.close();
            }
        }
    } finally {
        is.close();
    }

    return client.completePendingCommand();
}