Search in sources :

Example 26 with SequenceInputStream

use of java.io.SequenceInputStream in project validator by validator.

the class SimpleDocumentValidator method checkAsCss.

/* *
     * Packs a CSS document into an HTML wrapper and validates it.
     */
private void checkAsCss(InputSource is) throws IOException, SAXException {
    String charset = "UTF-8";
    if (is.getEncoding() != null) {
        charset = is.getEncoding();
    }
    List<InputStream> streamsList = new ArrayList<>();
    streamsList.add(new ByteArrayInputStream(CSS_CHECKING_PROLOG));
    streamsList.add(is.getByteStream());
    streamsList.add(new ByteArrayInputStream(CSS_CHECKING_EPILOG));
    Enumeration<InputStream> streams = Collections.enumeration(streamsList);
    is.setByteStream(new SequenceInputStream(streams));
    is.setEncoding(charset);
    sourceCode.setIsCss();
    sourceCode.initialize(is);
    try {
        htmlReader.parse(is);
    } catch (SAXParseException e) {
    }
}
Also used : SequenceInputStream(java.io.SequenceInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) SequenceInputStream(java.io.SequenceInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) SAXParseException(org.xml.sax.SAXParseException) ArrayList(java.util.ArrayList)

Example 27 with SequenceInputStream

use of java.io.SequenceInputStream in project webservices-axiom by apache.

the class TextHelperTest method test_toString2.

/**
 * Regression test for AXIOM-101.
 *
 * @throws Exception
 */
public void test_toString2() throws Exception {
    InputStream in = new SequenceInputStream(new ByteArrayInputStream("aa".getBytes()), new ByteArrayInputStream("a".getBytes()));
    assertEquals("YWFh", TextHelper.toString(in));
}
Also used : SequenceInputStream(java.io.SequenceInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) SequenceInputStream(java.io.SequenceInputStream) FileInputStream(java.io.FileInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream)

Example 28 with SequenceInputStream

use of java.io.SequenceInputStream in project i2p.i2p by i2p.

the class PeerAcceptor method connection.

public void connection(I2PSocket socket, InputStream in, OutputStream out) throws IOException {
    // inside this Peer constructor's handshake is where you'd deal with the other
    // side saying they want to communicate with another torrent - aka multitorrent
    // support, but because of how the protocol works, we can get away with just reading
    // ahead the first $LOOKAHEAD_SIZE bytes to figure out which infohash they want to
    // talk about, and we can just look for that in our list of active torrents.
    byte[] peerInfoHash = null;
    if (in instanceof BufferedInputStream) {
        // multitorrent
        in.mark(LOOKAHEAD_SIZE);
        long timeout = socket.getReadTimeout();
        socket.setReadTimeout(HASH_READ_TIMEOUT);
        try {
            peerInfoHash = readHash(in);
        } catch (IOException ioe) {
            // unique exception so ConnectionAcceptor can blame the peer
            throw new ProtocolException(ioe.toString());
        }
        socket.setReadTimeout(timeout);
        in.reset();
    } else {
        // Single torrent - is this working right?
        try {
            peerInfoHash = readHash(in);
            if (_log.shouldLog(Log.INFO))
                _log.info("infohash read from " + socket.getPeerDestination().calculateHash().toBase64() + ": " + Base64.encode(peerInfoHash));
        } catch (IOException ioe) {
            if (_log.shouldLog(Log.INFO))
                _log.info("Unable to read the infohash from " + socket.getPeerDestination().calculateHash().toBase64());
            throw ioe;
        }
        in = new SequenceInputStream(new ByteArrayInputStream(peerInfoHash), in);
    }
    if (coordinator != null) {
        // single torrent capability
        if (DataHelper.eq(coordinator.getInfoHash(), peerInfoHash)) {
            if (coordinator.needPeers()) {
                Peer peer = new Peer(socket, in, out, coordinator.getID(), coordinator.getInfoHash(), coordinator.getMetaInfo());
                coordinator.addPeer(peer);
            } else
                socket.close();
        } else {
            // its for another infohash, but we are only single torrent capable.  b0rk.
            throw new IOException("Peer wants another torrent (" + Base64.encode(peerInfoHash) + ") while we only support (" + Base64.encode(coordinator.getInfoHash()) + ")");
        }
    } else {
        // multitorrent capable, so lets see what we can handle
        PeerCoordinator cur = coordinators.get(peerInfoHash);
        if (cur != null) {
            if (DataHelper.eq(cur.getInfoHash(), peerInfoHash)) {
                if (cur.needPeers()) {
                    Peer peer = new Peer(socket, in, out, cur.getID(), cur.getInfoHash(), cur.getMetaInfo());
                    cur.addPeer(peer);
                    return;
                } else {
                    if (_log.shouldLog(Log.DEBUG))
                        _log.debug("Rejecting new peer for " + cur.getName());
                    socket.close();
                    return;
                }
            }
        }
        // this is only reached if none of the coordinators match the infohash
        throw new IOException("Peer wants another torrent (" + Base64.encode(peerInfoHash) + ") while we don't support that hash");
    }
}
Also used : SequenceInputStream(java.io.SequenceInputStream) BufferedInputStream(java.io.BufferedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) IOException(java.io.IOException)

Example 29 with SequenceInputStream

use of java.io.SequenceInputStream in project JavaExercises by biblelamp.

the class SequenceInputStreamEx method main.

public static void main(String[] args) {
    List<InputStream> al = new ArrayList<>();
    FileInputStream in1 = null, in2 = null;
    SequenceInputStream seq = null;
    FileOutputStream out = null;
    try {
        in1 = new FileInputStream("1.txt");
        in2 = new FileInputStream("2.txt");
        al.add(in1);
        al.add(in2);
        Enumeration<InputStream> list = Collections.enumeration(al);
        // in1, in2);
        seq = new SequenceInputStream(list);
        out = new FileOutputStream("3.txt");
        int rb = seq.read();
        while (rb != -1) {
            out.write(rb);
            rb = seq.read();
        }
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        try {
            seq.close();
        } catch (IOException e) {
        }
        ;
        try {
            out.close();
        } catch (IOException e) {
        }
        ;
    }
}
Also used : SequenceInputStream(java.io.SequenceInputStream) SequenceInputStream(java.io.SequenceInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileOutputStream(java.io.FileOutputStream) ArrayList(java.util.ArrayList) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream)

Example 30 with SequenceInputStream

use of java.io.SequenceInputStream in project freeplane by freeplane.

the class MFileManager method loadTreeImpl.

private NodeModel loadTreeImpl(final MapModel map, final File f) throws FileNotFoundException, IOException, XMLException, MapConversionException {
    final BufferedInputStream file = new BufferedInputStream(new FileInputStream(f));
    int versionInfoLength = 1000;
    final byte[] buffer = new byte[versionInfoLength];
    final int readCount = file.read(buffer);
    final String mapStart = new String(buffer, FileUtils.defaultCharset().name());
    final ByteArrayInputStream readBytes = new ByteArrayInputStream(buffer, 0, readCount);
    final InputStream sequencedInput = new SequenceInputStream(readBytes, file);
    Reader reader = null;
    MapVersionInterpreter versionInterpreter = MapVersionInterpreter.getVersionInterpreter(mapStart);
    map.addExtension(versionInterpreter);
    if (versionInterpreter.anotherDialect) {
        String message = versionInterpreter.getDialectInfo(f.getAbsolutePath());
        UITools.showMessage(message, JOptionPane.WARNING_MESSAGE);
    }
    if (versionInterpreter.needsConversion) {
        final int showResult = OptionalDontShowMeAgainDialog.show("really_convert_to_current_version", "confirmation", MMapController.RESOURCES_CONVERT_TO_CURRENT_VERSION, OptionalDontShowMeAgainDialog.ONLY_OK_SELECTION_IS_STORED);
        IMapInputStreamConverter isConverter = versionInterpreter.getMapInputStreamConverter();
        if (showResult != JOptionPane.OK_OPTION || isConverter == null) {
            reader = new InputStreamReader(sequencedInput, FileUtils.defaultCharset());
        } else {
            sequencedInput.close();
            // reader = UrlManager.getUpdateReader(f, FREEPLANE_VERSION_UPDATER_XSLT);
            reader = isConverter.getConvertedStream(f);
        }
    } else {
        reader = new InputStreamReader(sequencedInput, FileUtils.defaultCharset());
    }
    try {
        return Controller.getCurrentModeController().getMapController().getMapReader().createNodeTreeFromXml(map, reader, Mode.FILE);
    } finally {
        FileUtils.silentlyClose(reader);
    }
}
Also used : SequenceInputStream(java.io.SequenceInputStream) InputStreamReader(java.io.InputStreamReader) BufferedInputStream(java.io.BufferedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) BufferedInputStream(java.io.BufferedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) SequenceInputStream(java.io.SequenceInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) FileInputStream(java.io.FileInputStream) MapVersionInterpreter(org.freeplane.features.url.MapVersionInterpreter) IMapInputStreamConverter(org.freeplane.features.url.IMapInputStreamConverter)

Aggregations

SequenceInputStream (java.io.SequenceInputStream)119 InputStream (java.io.InputStream)76 ByteArrayInputStream (java.io.ByteArrayInputStream)65 IOException (java.io.IOException)46 ArrayList (java.util.ArrayList)31 FileInputStream (java.io.FileInputStream)22 BufferedInputStream (java.io.BufferedInputStream)13 ByteArrayOutputStream (java.io.ByteArrayOutputStream)12 Test (org.junit.Test)10 Vector (java.util.Vector)9 lombok.val (lombok.val)9 OutputStream (java.io.OutputStream)8 List (java.util.List)8 FileOutputStream (java.io.FileOutputStream)7 InputStreamReader (java.io.InputStreamReader)7 HashMap (java.util.HashMap)7 File (java.io.File)6 ByteBuffer (java.nio.ByteBuffer)6 Support_ASimpleInputStream (tests.support.Support_ASimpleInputStream)6 Reader (java.io.Reader)5