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) {
}
}
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));
}
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");
}
}
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) {
}
;
}
}
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);
}
}
Aggregations