use of java.io.BufferedInputStream in project jetty.project by eclipse.
the class SelectChannelEndPointTest method testWriteBlocked.
@Test
public void testWriteBlocked() throws Exception {
Socket client = newClient();
client.setSoTimeout(10000);
SocketChannel server = _connector.accept();
server.configureBlocking(false);
_manager.accept(server);
// Write client to server
_writeCount = 10000;
String data = "Now is the time for all good men to come to the aid of the party";
client.getOutputStream().write(data.getBytes(StandardCharsets.UTF_8));
BufferedInputStream in = new BufferedInputStream(client.getInputStream());
int byteNum = 0;
try {
for (int i = 0; i < _writeCount; i++) {
if (i % 1000 == 0)
TimeUnit.MILLISECONDS.sleep(200);
// Verify echo server to client
for (int j = 0; j < data.length(); j++) {
char c = data.charAt(j);
int b = in.read();
byteNum++;
assertTrue(b > 0);
assertEquals("test-" + i + "/" + j, c, (char) b);
}
if (i == 0)
_lastEndPoint.setIdleTimeout(60000);
}
} catch (SocketTimeoutException e) {
System.err.println("SelectorManager.dump() = " + _manager.dump());
LOG.warn("Server: " + server);
LOG.warn("Error reading byte #" + byteNum, e);
throw e;
}
client.close();
for (int i = 0; i < 10; ++i) {
if (server.isOpen())
Thread.sleep(10);
else
break;
}
assertFalse(server.isOpen());
}
use of java.io.BufferedInputStream in project buck by facebook.
the class ExopackageSoLoader method copySoFileIfRequired.
private static File copySoFileIfRequired(String libname) {
File libraryFile = new File(privateNativeLibsDir, libname + ".so");
if (libraryFile.exists()) {
return libraryFile;
}
if (!abi1Libraries.containsKey(libname) && !abi2Libraries.containsKey(libname)) {
return null;
}
String abiDir;
String sourceFilename;
if (abi1Libraries.containsKey(libname)) {
sourceFilename = abi1Libraries.get(libname);
abiDir = Build.CPU_ABI;
} else {
sourceFilename = abi2Libraries.get(libname);
abiDir = Build.CPU_ABI2;
}
String sourcePath = nativeLibsDir + abiDir + "/" + sourceFilename;
try {
InputStream in = null;
OutputStream out = null;
try {
in = new BufferedInputStream(new FileInputStream(sourcePath));
out = new BufferedOutputStream(new FileOutputStream(libraryFile));
byte[] buffer = new byte[4 * 1024];
int len;
while ((len = in.read(buffer)) > 0) {
out.write(buffer, 0, len);
}
} finally {
if (in != null) {
in.close();
}
if (out != null) {
out.close();
}
}
} catch (IOException e) {
throw new RuntimeException(e);
}
return libraryFile;
}
use of java.io.BufferedInputStream in project buck by facebook.
the class AppleSdkDiscovery method buildSdkFromPath.
private static boolean buildSdkFromPath(Path sdkDir, AppleSdk.Builder sdkBuilder, ImmutableMap<String, AppleToolchain> xcodeToolchains, Optional<AppleToolchain> defaultToolchain, AppleConfig appleConfig) throws IOException {
try (InputStream sdkSettingsPlist = Files.newInputStream(sdkDir.resolve("SDKSettings.plist"));
BufferedInputStream bufferedSdkSettingsPlist = new BufferedInputStream(sdkSettingsPlist)) {
NSDictionary sdkSettings;
try {
sdkSettings = (NSDictionary) PropertyListParser.parse(bufferedSdkSettingsPlist);
} catch (PropertyListFormatException | ParseException | SAXException e) {
LOG.error(e, "Malformatted SDKSettings.plist. Skipping SDK path %s.", sdkDir);
return false;
} catch (ParserConfigurationException e) {
throw new IOException(e);
}
String name = sdkSettings.objectForKey("CanonicalName").toString();
String version = sdkSettings.objectForKey("Version").toString();
NSDictionary defaultProperties = (NSDictionary) sdkSettings.objectForKey("DefaultProperties");
Optional<ImmutableList<String>> toolchains = appleConfig.getToolchainsOverrideForSDKName(name);
boolean foundToolchain = false;
if (!toolchains.isPresent()) {
NSArray settingsToolchains = (NSArray) sdkSettings.objectForKey("Toolchains");
if (settingsToolchains != null) {
toolchains = Optional.of(Arrays.stream(settingsToolchains.getArray()).map(Object::toString).collect(MoreCollectors.toImmutableList()));
}
}
if (toolchains.isPresent()) {
for (String toolchainId : toolchains.get()) {
AppleToolchain toolchain = xcodeToolchains.get(toolchainId);
if (toolchain != null) {
foundToolchain = true;
sdkBuilder.addToolchains(toolchain);
} else {
LOG.debug("Specified toolchain %s not found for SDK path %s", toolchainId, sdkDir);
}
}
}
if (!foundToolchain && defaultToolchain.isPresent()) {
foundToolchain = true;
sdkBuilder.addToolchains(defaultToolchain.get());
}
if (!foundToolchain) {
LOG.warn("No toolchains found and no default toolchain. Skipping SDK path %s.", sdkDir);
return false;
} else {
NSString platformName = (NSString) defaultProperties.objectForKey("PLATFORM_NAME");
ApplePlatform applePlatform = ApplePlatform.of(platformName.toString());
sdkBuilder.setName(name).setVersion(version).setApplePlatform(applePlatform);
ImmutableList<String> architectures = validArchitecturesForPlatform(applePlatform, sdkDir);
sdkBuilder.addAllArchitectures(architectures);
return true;
}
} catch (NoSuchFileException e) {
LOG.warn(e, "Skipping SDK at path %s, no SDKSettings.plist found", sdkDir);
return false;
}
}
use of java.io.BufferedInputStream in project buck by facebook.
the class AppleToolchainDiscovery method toolchainFromPlist.
private static Optional<AppleToolchain> toolchainFromPlist(Path toolchainDir, String plistName) throws IOException {
Path toolchainInfoPlistPath = toolchainDir.resolve(plistName);
InputStream toolchainInfoPlist = Files.newInputStream(toolchainInfoPlistPath);
BufferedInputStream bufferedToolchainInfoPlist = new BufferedInputStream(toolchainInfoPlist);
NSDictionary parsedToolchainInfoPlist;
try {
parsedToolchainInfoPlist = (NSDictionary) PropertyListParser.parse(bufferedToolchainInfoPlist);
} catch (PropertyListFormatException | ParseException | ParserConfigurationException | SAXException e) {
LOG.error(e, "Failed to parse %s: %s, ignoring", plistName, toolchainInfoPlistPath);
return Optional.empty();
}
NSObject identifierObject = parsedToolchainInfoPlist.objectForKey("Identifier");
if (identifierObject == null) {
LOG.error("Identifier not found for toolchain path %s, ignoring", toolchainDir);
return Optional.empty();
}
String identifier = identifierObject.toString();
NSObject versionObject = parsedToolchainInfoPlist.objectForKey("DTSDKBuild");
Optional<String> version = versionObject == null ? Optional.empty() : Optional.of(versionObject.toString());
LOG.debug("Mapped SDK identifier %s to path %s", identifier, toolchainDir);
AppleToolchain.Builder toolchainBuilder = AppleToolchain.builder();
toolchainBuilder.setIdentifier(identifier);
toolchainBuilder.setVersion(version);
toolchainBuilder.setPath(toolchainDir);
return Optional.of(toolchainBuilder.build());
}
use of java.io.BufferedInputStream in project elasticsearch by elastic.
the class XContentHelper method createParser.
/**
* Creates a parser for the bytes using the supplied content-type
*/
public static XContentParser createParser(NamedXContentRegistry xContentRegistry, BytesReference bytes, XContentType xContentType) throws IOException {
Objects.requireNonNull(xContentType);
Compressor compressor = CompressorFactory.compressor(bytes);
if (compressor != null) {
InputStream compressedInput = compressor.streamInput(bytes.streamInput());
if (compressedInput.markSupported() == false) {
compressedInput = new BufferedInputStream(compressedInput);
}
return XContentFactory.xContent(xContentType).createParser(xContentRegistry, compressedInput);
} else {
return xContentType.xContent().createParser(xContentRegistry, bytes.streamInput());
}
}
Aggregations