Search in sources :

Example 1 with BufferedInputStream

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());
}
Also used : SocketChannel(java.nio.channels.SocketChannel) ServerSocketChannel(java.nio.channels.ServerSocketChannel) SocketTimeoutException(java.net.SocketTimeoutException) BufferedInputStream(java.io.BufferedInputStream) Socket(java.net.Socket) Test(org.junit.Test)

Example 2 with BufferedInputStream

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;
}
Also used : BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) BufferedOutputStream(java.io.BufferedOutputStream) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream) FileInputStream(java.io.FileInputStream)

Example 3 with BufferedInputStream

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;
    }
}
Also used : NSArray(com.dd.plist.NSArray) BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) NSDictionary(com.dd.plist.NSDictionary) ImmutableList(com.google.common.collect.ImmutableList) NoSuchFileException(java.nio.file.NoSuchFileException) IOException(java.io.IOException) NSString(com.dd.plist.NSString) NSString(com.dd.plist.NSString) SAXException(org.xml.sax.SAXException) PropertyListFormatException(com.dd.plist.PropertyListFormatException) BufferedInputStream(java.io.BufferedInputStream) ParseException(java.text.ParseException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 4 with BufferedInputStream

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());
}
Also used : Path(java.nio.file.Path) NSObject(com.dd.plist.NSObject) BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) NSDictionary(com.dd.plist.NSDictionary) SAXException(org.xml.sax.SAXException) PropertyListFormatException(com.dd.plist.PropertyListFormatException) BufferedInputStream(java.io.BufferedInputStream) ParseException(java.text.ParseException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 5 with BufferedInputStream

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());
    }
}
Also used : BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) Compressor(org.elasticsearch.common.compress.Compressor)

Aggregations

BufferedInputStream (java.io.BufferedInputStream)3306 IOException (java.io.IOException)1660 FileInputStream (java.io.FileInputStream)1550 InputStream (java.io.InputStream)1473 File (java.io.File)886 BufferedOutputStream (java.io.BufferedOutputStream)499 FileOutputStream (java.io.FileOutputStream)467 ByteArrayInputStream (java.io.ByteArrayInputStream)330 URL (java.net.URL)298 FileNotFoundException (java.io.FileNotFoundException)273 DataInputStream (java.io.DataInputStream)263 OutputStream (java.io.OutputStream)253 ZipEntry (java.util.zip.ZipEntry)248 ByteArrayOutputStream (java.io.ByteArrayOutputStream)237 ArrayList (java.util.ArrayList)148 ZipInputStream (java.util.zip.ZipInputStream)143 GZIPInputStream (java.util.zip.GZIPInputStream)135 InputStreamReader (java.io.InputStreamReader)132 HttpURLConnection (java.net.HttpURLConnection)119 HashMap (java.util.HashMap)119