semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
private void loadDDL() throws IOException {
        try {
            conn.createStatement().executeQuery("SELECT * FROM reporters").close();
        } catch (SQLException e) {
            Statement stmt = null;
            if (!e.getMessage().matches(ERR_MISSING_TABLE)) {
                String msg = "Error on initial data store read";
                LOG.fatal(msg, e);
                throw new IOException(msg, e);
            }
            String[] qry = { "CREATE TABLE reporters (type LONG VARCHAR NOT NULL, key LONG VARCHAR NOT NULL, data LONG VARCHAR, PRIMARY KEY(type, key))", "CREATE TABLE listeners (event VARCHAR(255) NOT NULL, type LONG VARCHAR NOT NULL, key LONG VARCHAR NOT NULL, PRIMARY KEY(event, type, key))", "CREATE TABLE settings (var VARCHAR(32) NOT NULL, val VARCHAR(255) NOT NULL, PRIMARY KEY(var))", "INSERT INTO settings (var, val) VALUES ('schema', '1')" };
            try {
                conn.setAutoCommit(false);
                stmt = conn.createStatement();
                for (String q : qry) {
                    logQry(q);
                    stmt.executeUpdate(q);
                }
                conn.commit();
            } catch (SQLException e2) {
                String msg = "Error initializing data store";
                try {
                    conn.rollback();
                } catch (SQLException e3) {
                    LOG.fatal(msg, e3);
                }
                LOG.fatal(msg, e2);
                throw new IOException(msg);
            } finally {
                if (stmt != null) {
                    try {
                        stmt.close();
                    } catch (SQLException e4) {
                        String msg = "Unable to cleanup data store resources";
                        LOG.fatal(msg, e4);
                        throw new IOException(msg);
                    }
                }
                try {
                    conn.setAutoCommit(true);
                } catch (SQLException e3) {
                    String msg = "Unable to reset data store auto commit";
                    LOG.fatal(msg, e3);
                    throw new IOException(msg);
                }
            }
        }
        return;
    }
public static boolean processUrl(String urlPath, UrlLineHandler handler) {
        boolean ret = true;
        URL url;
        InputStream in = null;
        BufferedReader bin = null;
        try {
            url = new URL(urlPath);
            in = url.openStream();
            bin = new BufferedReader(new InputStreamReader(in));
            String line;
            while ((line = bin.readLine()) != null) {
                if (!handler.process(line)) break;
            }
        } catch (IOException e) {
            ret = false;
        } finally {
            safelyClose(bin, in);
        }
        return ret;
    }
public InputSource resolveEntity(String name, String uri) throws IOException, SAXException {
        InputSource retval;
        String mappedURI = name2uri(name);
        InputStream stream;
        if (mappedURI == null && (stream = mapResource(name)) != null) {
            uri = "java:resource:" + (String) id2resource.get(name);
            retval = new InputSource(XmlReader.createReader(stream));
        } else {
            URL url;
            URLConnection conn;
            if (mappedURI != null) uri = mappedURI; else if (uri == null) return null;
            url = new URL(uri);
            conn = url.openConnection();
            uri = conn.getURL().toString();
            if (ignoringMIME) retval = new InputSource(XmlReader.createReader(conn.getInputStream())); else {
                String contentType = conn.getContentType();
                retval = createInputSource(contentType, conn.getInputStream(), false, url.getProtocol());
            }
        }
        retval.setSystemId(uri);
        retval.setPublicId(name);
        return retval;
    }
@SuppressWarnings("unchecked")
    public InputStream openStream(URL url) throws IOException {
        List<String> lines = IOUtils.readLines(url.openStream());
        for (String line : lines) {
            Matcher m = PATTERN.matcher(line);
            if (m.matches()) {
                String origUrl = m.group(1);
                log.info("Loading content from: " + origUrl);
                return new HttpUtil<InputStream>() {

                    @Override
                    public InputStream handleResponse(InputStream response) throws IOException {
                        return new ByteArrayInputStream(IOUtils.toByteArray(response));
                    }
                }.get(new URL(origUrl));
            }
        }
        log.error("No origUrl found for url: " + url);
        return null;
    }
private void _loadInternalViews() {
        _internalViews = new HashMap<String, InternalView>();
        List<URL> list = new ArrayList<URL>();
        ClassLoader loader = _getClassLoader();
        try {
            Enumeration<URL> en = loader.getResources("META-INF/org.apache.myfaces.trinidad.render.InternalView.properties");
            while (en.hasMoreElements()) {
                list.add(en.nextElement());
            }
            en = loader.getResources("META-INF/org.apache.myfaces.trinidad.InternalView.properties");
            while (en.hasMoreElements()) {
                list.add(en.nextElement());
            }
            Collections.reverse(list);
        } catch (IOException ioe) {
            _LOG.severe(ioe);
        }
        for (URL url : list) {
            try {
                Properties properties = new Properties();
                _LOG.fine("Loading internal views from {0}", url);
                InputStream is = url.openStream();
                try {
                    properties.load(is);
                } finally {
                    is.close();
                }
                for (Map.Entry<Object, Object> entry : properties.entrySet()) {
                    String name = (String) entry.getKey();
                    String className = (String) entry.getValue();
                    Class<?> clazz = loader.loadClass(className);
                    InternalView view = (InternalView) clazz.newInstance();
                    _internalViews.put(name, view);
                }
            } catch (IllegalAccessException iae) {
                _LOG.severe("CANNOT_LOAD_URL", url);
                _LOG.severe(iae);
            } catch (InstantiationException ie) {
                _LOG.severe("CANNOT_LOAD_URL", url);
                _LOG.severe(ie);
            } catch (ClassNotFoundException cnfe) {
                _LOG.severe("CANNOT_LOAD_URL", url);
                _LOG.severe(cnfe);
            } catch (IOException ioe) {
                _LOG.severe("CANNOT_LOAD_URL", url);
                _LOG.severe(ioe);
            }
        }
    }
public String getDigest(String s) throws Exception {
        MessageDigest md = MessageDigest.getInstance(hashName);
        md.update(s.getBytes());
        byte[] dig = md.digest();
        return Base16.toHexString(dig);
    }
public static void forEachLine(final URL url, final LineListener lit, final String encoding) {
        try {
            ReaderUtils.forEachLine(url.openStream(), lit);
        } catch (final IOException ioe) {
            lit.exception(ioe);
        }
    }
public static Checksum checksum(File file, Checksum checksum) throws IOException {
        if (file.isDirectory()) {
            throw new IllegalArgumentException("Checksums can't be computed on directories");
        }
        InputStream in = null;
        try {
            in = new CheckedInputStream(new FileInputStream(file), checksum);
            IOUtils.copy(in, new NullOutputStream());
        } finally {
            IOUtils.closeQuietly(in);
        }
        return checksum;
    }
private static void downloadImage(URL url, String localFileName) {
        FileOutputStream fos = null;
        URL fileUrl = null;
        Bundle bundle = Activator.getDefault().getBundle();
        Path path = new Path("album covers/empty_disk.jpg");
        URL localUrl = FileLocator.find(bundle, path, Collections.EMPTY_MAP);
        try {
            fileUrl = FileLocator.toFileURL(localUrl);
        } catch (IOException e) {
            e.printStackTrace();
        }
        try {
            InputStream is = url.openStream();
            String actualPath = fileUrl.getPath();
            actualPath = actualPath.substring(1);
            actualPath = actualPath.substring(0, actualPath.lastIndexOf("/"));
            fos = new FileOutputStream(actualPath + "/" + localFileName);
            int oneChar, count = 0;
            while ((oneChar = is.read()) != -1) {
                fos.write(oneChar);
                count++;
            }
            is.close();
            fos.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
public static String getURLContent(String urlToSearchString) throws IOException {
        URL url = new URL(urlToSearchString);
        URLConnection conn = url.openConnection();
        String encoding = conn.getContentEncoding();
        if (encoding == null) encoding = "ISO-8859-1";
        BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream(), encoding));
        StringBuilder sb = new StringBuilder(16384);
        try {
            String line;
            while ((line = br.readLine()) != null) {
                sb.append(line);
                sb.append('\n');
            }
        } finally {
            br.close();
        }
        return sb.toString();
    }
public static List<ReactomeBean> getUrlData(URL url) throws IOException {
        List<ReactomeBean> beans = new ArrayList<ReactomeBean>(256);
        log.debug("Retreiving content for: " + url);
        StringBuffer content = new StringBuffer(4096);
        BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
        String str;
        while ((str = in.readLine()) != null) {
            if (str.startsWith("#")) {
                continue;
            }
            StringTokenizer stringTokenizer = new StringTokenizer(str, "\t");
            String InteractionAc = stringTokenizer.nextToken();
            String reactomeId = stringTokenizer.nextToken();
            ReactomeBean reactomeBean = new ReactomeBean();
            reactomeBean.setReactomeID(reactomeId);
            reactomeBean.setInteractionAC(InteractionAc);
            beans.add(reactomeBean);
        }
        in.close();
        return beans;
    }
private void copyFile(String sourceFilename, String targetFilename) throws IOException {
        File source = new File(sourceFilename);
        File target = new File(targetFilename);
        InputStream in = new FileInputStream(source);
        OutputStream out = new FileOutputStream(target);
        byte[] buf = new byte[1024];
        int len;
        while ((len = in.read(buf)) > 0) out.write(buf, 0, len);
        in.close();
        out.close();
    }
void extractEnsemblCoords(String geneviewLink) {
        try {
            URL connectURL = new URL(geneviewLink);
            InputStream urlStream = connectURL.openStream();
            BufferedReader reader = new BufferedReader(new InputStreamReader(urlStream));
            String line;
            while ((line = reader.readLine()) != null) {
                if (line.indexOf("View gene in genomic location") != -1) {
                    line = line.substring(line.indexOf("contigview?"));
                    String chr, start, stop;
                    chr = line.substring(line.indexOf("chr=") + 4);
                    chr = chr.substring(0, chr.indexOf("&"));
                    start = line.substring(line.indexOf("vc_start=") + 9);
                    start = start.substring(0, start.indexOf("&"));
                    stop = line.substring(line.indexOf("vc_end=") + 7);
                    stop = stop.substring(0, stop.indexOf("\""));
                    String selString;
                    for (int s = 0; s < selPanel.chrField.getModel().getSize(); s++) {
                        if (chr.equals(selPanel.chrField.getModel().getElementAt(s))) {
                            selPanel.chrField.setSelectedIndex(s);
                            break;
                        }
                    }
                    selPanel.setStart(Integer.parseInt(start));
                    selPanel.setStop(Integer.parseInt(stop));
                    selPanel.refreshButton.doClick();
                    break;
                }
            }
        } catch (Exception e) {
            System.out.println("Problems retrieving Geneview from Ensembl");
            e.printStackTrace();
        }
    }
private String read(URL url) throws IOException {
        BufferedReader in = null;
        try {
            in = new BufferedReader(new InputStreamReader(url.openStream()));
            StringBuffer text = new StringBuffer();
            String line;
            while ((line = in.readLine()) != null) {
                text.append(line);
            }
            return text.toString();
        } finally {
            in.close();
        }
    }
public static void main(String[] args) throws IOException {
        if (args.length == 0) {
            System.out.println("Usage: \nGZIPcompress file\n" + "\tUses GZIP compression to compress " + "the file to test.gz");
            System.exit(1);
        }
        BufferedReader in = new BufferedReader(new FileReader(args[0]));
        BufferedOutputStream out = new BufferedOutputStream(new GZIPOutputStream(new FileOutputStream("test.gz")));
        System.out.println("Writing file");
        int c;
        while ((c = in.read()) != -1) out.write(c);
        in.close();
        out.close();
        System.out.println("Reading file");
        BufferedReader in2 = new BufferedReader(new InputStreamReader(new GZIPInputStream(new FileInputStream("test.gz"))));
        String s;
        while ((s = in2.readLine()) != null) System.out.println(s);
    }
public InputSource resolveEntity(String publicId, String systemId) {
        String resolved = null;
        if (systemId != null) {
            try {
                resolved = catalog.resolveSystem(systemId);
            } catch (MalformedURLException me) {
                debug(1, "Malformed URL exception trying to resolve", publicId);
                resolved = null;
            } catch (IOException ie) {
                debug(1, "I/O exception trying to resolve", publicId);
                resolved = null;
            }
        }
        if (resolved == null) {
            if (publicId != null) {
                try {
                    resolved = catalog.resolvePublic(publicId, systemId);
                } catch (MalformedURLException me) {
                    debug(1, "Malformed URL exception trying to resolve", publicId);
                } catch (IOException ie) {
                    debug(1, "I/O exception trying to resolve", publicId);
                }
            }
            if (resolved != null) {
                debug(2, "Resolved", publicId, resolved);
            }
        } else {
            debug(2, "Resolved", systemId, resolved);
        }
        if (resolved == null && retryBadSystemIds && publicId != null && systemId != null) {
            URL systemURL = null;
            try {
                systemURL = new URL(systemId);
            } catch (MalformedURLException e) {
                try {
                    systemURL = new URL("file:///" + systemId);
                } catch (MalformedURLException e2) {
                    systemURL = null;
                }
            }
            if (systemURL != null) {
                try {
                    InputStream iStream = systemURL.openStream();
                    InputSource iSource = new InputSource(systemId);
                    iSource.setPublicId(publicId);
                    iSource.setByteStream(iStream);
                    return iSource;
                } catch (Exception e) {
                }
            }
            debug(2, "Failed to open", systemId);
            debug(2, "\tAttempting catalog lookup without system identifier.");
            return resolveEntity(publicId, null);
        }
        if (resolved != null) {
            try {
                InputSource iSource = new InputSource(resolved);
                iSource.setPublicId(publicId);
                URL url = new URL(resolved);
                InputStream iStream = url.openStream();
                iSource.setByteStream(iStream);
                return iSource;
            } catch (Exception e) {
                debug(1, "Failed to create InputSource", resolved);
                return null;
            }
        }
        return null;
    }
public static FTPClient getClient(String serverAddress, String login, String password, boolean PASV) throws SocketException, IOException {
        FTPClient client = new FTPClient();
        client.connect(serverAddress);
        if (PASV) {
            client.enterLocalPassiveMode();
        }
        client.login(login, password);
        return client;
    }
protected Object unmarshallXml(final Unmarshaller unmarshaller, final String accessUrl, final String nameSpace, final String replace, final String with) throws Exception {
        final URL url = new URL(accessUrl);
        final BufferedReader inputStream = new BufferedReader(new InputStreamReader(url.openStream()));
        String xmlContent = readWithStringBuffer(inputStream);
        if (replace != null) {
            xmlContent = xmlContent.replace(replace, with);
        }
        LOGGER.info("Calls " + accessUrl);
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("\nXml:" + accessUrl + "\n" + xmlContent);
        }
        if (LOGGER.isDebugEnabled()) {
            final BufferedWriter out = new BufferedWriter(new FileWriter("target/XmlAgentLog" + xmlRequestNumber++ + ".txt"));
            out.write(xmlContent);
            out.close();
        }
        final ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xmlContent.getBytes());
        Source source;
        if (nameSpace != null) {
            source = setNameSpaceOnXmlStream(byteArrayInputStream, nameSpace);
        } else {
            source = new StreamSource(byteArrayInputStream);
        }
        return unmarshaller.unmarshal(source);
    }
public QDataSet doRead(URL url, URLConnection connect) throws IOException, ParserConfigurationException, SAXException {
        codebase = url;
        InputStream in;
        if (connect != null) {
            in = connect.getInputStream();
        } else {
            in = url.openStream();
        }
        DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        InputSource source = new InputSource(in);
        Document document = builder.parse(source);
        in.close();
        QDataSet result = null;
        NodeList kids = document.getChildNodes();
        for (int i = 0; i < kids.getLength(); i++) {
            Node n = kids.item(i);
            if (n.getNodeName().equals("netcdf")) {
                result = netcdf(n);
            }
        }
        return result;
    }
public boolean loadURL(URL url) {
        try {
            propertyBundle.load(url.openStream());
            LOG.info("Configuration loaded from " + url + "\n");
            return true;
        } catch (Exception e) {
            if (canComplain) {
                LOG.warn("Unable to load configuration " + url + "\n");
            }
            canComplain = false;
            return false;
        }
    }
@Override
    protected PermissionCollection getPermissions(CodeSource _codeSource) {
        PermissionCollection perms = super.getPermissions(_codeSource);
        URL url = _codeSource.getLocation();
        Permission perm = null;
        URLConnection urlConnection = null;
        try {
            urlConnection = url.openConnection();
            urlConnection.connect();
            perm = urlConnection.getPermission();
        } catch (IOException excp) {
            perm = null;
            urlConnection = null;
        }
        if (perm == null) {
            perm = new ModulePermission(url.getHost(), "read");
        }
        if (perm != null) {
            final SecurityManager sm = System.getSecurityManager();
            if (sm != null) {
                final Permission fp = perm;
                AccessController.doPrivileged(new PrivilegedAction<Object>() {

                    public Object run() throws SecurityException {
                        sm.checkPermission(fp);
                        return null;
                    }
                }, this.controlContext);
            }
            perms.add(perm);
        }
        return perms;
    }
public void testPreparedStatementRollback1() throws Exception {
        Connection localCon = getConnection();
        Statement stmt = localCon.createStatement();
        stmt.execute("CREATE TABLE #psr1 (data BIT)");
        localCon.setAutoCommit(false);
        PreparedStatement pstmt = localCon.prepareStatement("INSERT INTO #psr1 (data) VALUES (?)");
        pstmt.setBoolean(1, true);
        assertEquals(1, pstmt.executeUpdate());
        pstmt.close();
        localCon.rollback();
        ResultSet rs = stmt.executeQuery("SELECT data FROM #psr1");
        assertFalse(rs.next());
        rs.close();
        stmt.close();
        localCon.close();
        try {
            localCon.commit();
            fail("Expecting commit to fail, connection was closed");
        } catch (SQLException ex) {
            assertEquals("HY010", ex.getSQLState());
        }
        try {
            localCon.rollback();
            fail("Expecting rollback to fail, connection was closed");
        } catch (SQLException ex) {
            assertEquals("HY010", ex.getSQLState());
        }
    }
public static String getWebPage(URL urlObj) {
        try {
            String content = "";
            InputStreamReader is = new InputStreamReader(urlObj.openStream());
            BufferedReader reader = new BufferedReader(is);
            String line;
            while ((line = reader.readLine()) != null) {
                content += line;
            }
            return content;
        } catch (IOException e) {
            throw new Error("The page " + quote(urlObj.toString()) + "could not be retrieved." + "\nThis is could be caused by a number of things:" + "\n" + "\n  - the computer hosting the web page you want is down, or has returned an error" + "\n  - your computer does not have Internet access" + "\n  - the heat death of the universe has occurred, taking down all web servers with it");
        }
    }