semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public static InputStream getResourceInputStream(final URL url) throws IOException {
        File file = url2file(url);
        if (file != null) {
            return new BufferedInputStream(new FileInputStream(file));
        }
        if (!"jar".equalsIgnoreCase(url.getProtocol())) {
            return url.openStream();
        }
        String urlStr = url.toExternalForm();
        if (urlStr.endsWith("!/")) {
            throw new FileNotFoundException(url.toExternalForm());
        }
        int p = urlStr.indexOf("!/");
        if (p == -1) {
            throw new MalformedURLException(url.toExternalForm());
        }
        String path = urlStr.substring(p + 2);
        file = url2file(new URL(urlStr.substring(4, p)));
        if (file == null) {
            return url.openStream();
        }
        JarFile jarFile = new JarFile(file);
        try {
            ZipEntry entry = jarFile.getEntry(path);
            if (entry == null) {
                throw new FileNotFoundException(url.toExternalForm());
            }
            InputStream in = jarFile.getInputStream(entry);
            try {
                ByteArrayOutputStream out = new ByteArrayOutputStream();
                copyStream(in, out, 1024);
                return new ByteArrayInputStream(out.toByteArray());
            } finally {
                in.close();
            }
        } finally {
            jarFile.close();
        }
    }
public static AudioInputStream getWavFromURL(String urlstr) {
        URL url;
        AudioInputStream ais = null;
        try {
            url = new URL(urlstr);
            URLConnection c = url.openConnection();
            c.connect();
            InputStream stream = c.getInputStream();
            ais = new AudioInputStream(stream, playFormat, AudioSystem.NOT_SPECIFIED);
            LOG.debug("[getWavFromURL]Getting audio from URL: {}", url);
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return ais;
    }
public void open(String openStr) throws IOException {
        String commProtocol = "comm:";
        String rxtxProtocol = "rxtx:";
        String netProtocol = "net:";
        if (openStr.startsWith(commProtocol)) {
            CommConnection commConnection = CommConnection.open(openStr.substring(commProtocol.length()));
            this.setInputStream(commConnection.getInputStream());
            this.setOutputStream(commConnection.getOutputStream());
        } else if (openStr.startsWith(rxtxProtocol)) {
            RXTXConnection rxtxConnection = RXTXConnection.open(openStr.substring(commProtocol.length()));
            this.setInputStream(rxtxConnection.getInputStream());
            this.setOutputStream(rxtxConnection.getOutputStream());
        } else if (openStr.startsWith(netProtocol)) {
            SocketConnection socketConn = SocketConnection.open(openStr.substring(netProtocol.length()));
            this.setInputStream(socketConn.getInputStream());
            this.setOutputStream(socketConn.getOutputStream());
        } else {
            URL url = new URL(openStr);
            URLConnection urlConn = url.openConnection();
            this.setInputStream(urlConn.getInputStream());
            try {
                this.setOutputStream(urlConn.getOutputStream());
            } catch (UnknownServiceException e) {
            }
        }
    }
public void init(ServletContext context) throws ScratchException {
        try {
            log.debug("Attempting to load Controllers from file: " + REGISTRY_FILENAME);
            ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
            Enumeration<URL> urls = classLoader.getResources(REGISTRY_FILENAME);
            while (urls.hasMoreElements()) {
                URL url = urls.nextElement();
                log.debug("Found: " + url);
                BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
                String className = null;
                while ((className = reader.readLine()) != null) {
                    className = className.trim();
                    if (!"".equals(className) && !className.startsWith("#")) {
                        log.debug("Found class: " + className);
                        Class<?> clazz = classLoader.loadClass(className);
                        addClass(clazz);
                    }
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
            log.error(e);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
            log.error(e);
        }
    }
public synchronized void checkout() throws SQLException, InterruptedException {
        Connection con = this.session.open();
        con.setAutoCommit(false);
        String sql_stmt = DB2SQLStatements.shopping_cart_getAll(this.customer_id);
        Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        ResultSet res = stmt.executeQuery(sql_stmt);
        res.last();
        int rowcount = res.getRow();
        res.beforeFirst();
        ShoppingCartItem[] resArray = new ShoppingCartItem[rowcount];
        int i = 0;
        while (res.next()) {
            resArray[i] = new ShoppingCartItem();
            resArray[i].setCustomer_id(res.getInt("customer_id"));
            resArray[i].setDate_start(res.getDate("date_start"));
            resArray[i].setDate_stop(res.getDate("date_stop"));
            resArray[i].setRoom_type_id(res.getInt("room_type_id"));
            resArray[i].setNumtaken(res.getInt("numtaken"));
            resArray[i].setTotal_price(res.getInt("total_price"));
            i++;
        }
        this.wait(4000);
        try {
            for (int j = 0; j < rowcount; j++) {
                sql_stmt = DB2SQLStatements.room_date_update(resArray[j]);
                stmt = con.createStatement();
                stmt.executeUpdate(sql_stmt);
            }
        } catch (SQLException e) {
            e.printStackTrace();
            con.rollback();
        }
        for (int j = 0; j < rowcount; j++) {
            System.out.println(j);
            sql_stmt = DB2SQLStatements.booked_insert(resArray[j], 2);
            stmt = con.createStatement();
            stmt.executeUpdate(sql_stmt);
        }
        sql_stmt = DB2SQLStatements.shopping_cart_deleteAll(this.customer_id);
        stmt = con.createStatement();
        stmt.executeUpdate(sql_stmt);
        con.commit();
        this.session.close(con);
    }
public void downloadClicked() {
        String s_url;
        try {
            double minlat = Double.parseDouble(minLat.text());
            double maxlat = Double.parseDouble(maxLat.text());
            double minlong = Double.parseDouble(minLong.text());
            double maxlong = Double.parseDouble(maxLong.text());
            s_url = "http://www.openstreetmap.org/api/0.5/map?bbox=" + minlong + "," + minlat + "," + maxlong + "," + maxlat;
        } catch (Exception e) {
            QMessageBox.critical(this, "Coordinates Error", "Please check the coordinates entered. Make sure to use proper float values.");
            return;
        }
        try {
            mylayout.removeWidget(dataWidget);
            dataWidget.hide();
            mylayout.addWidget(downloadWidget, 0, 0, 1, 4);
            downloadWidget.show();
            repaint();
            update();
            URL url = new URL(s_url);
            HttpURLConnection con = (HttpURLConnection) url.openConnection();
            new Osm2Model(con.getInputStream());
            mainapp.setStatusbarText("OSM data successful imported", 1000);
            mainapp.activateMapDisplay();
            hide();
        } catch (MalformedURLException e) {
            QMessageBox.critical(this, "OSM import failed", "Data could not be retrieved as download URL is erroneos.");
        } catch (IOException e) {
            QMessageBox.critical(this, "OSM import failed", "I/O error, aborting.");
        }
        mylayout.removeWidget(downloadWidget);
        downloadWidget.hide();
        mylayout.addWidget(dataWidget, 0, 0, 1, 4);
        dataWidget.show();
    }
public TextureData newTextureData(URL url, int internalFormat, int pixelFormat, boolean mipmap, String fileSuffix) throws IOException {
            InputStream stream = new BufferedInputStream(url.openStream());
            try {
                return newTextureData(stream, internalFormat, pixelFormat, mipmap, fileSuffix);
            } finally {
                stream.close();
            }
        }
protected void copy(File source, File destination) throws IOException {
        final FileChannel inChannel = new FileInputStream(source).getChannel();
        final FileChannel outChannel = new FileOutputStream(destination).getChannel();
        try {
            inChannel.transferTo(0, inChannel.size(), outChannel);
        } finally {
            if (inChannel != null) {
                inChannel.close();
            }
            if (outChannel != null) {
                outChannel.close();
            }
        }
    }
public static boolean isMatchingAsPassword(final String password, final String amd5Password) {
        boolean response = false;
        try {
            final MessageDigest algorithm = MessageDigest.getInstance("MD5");
            algorithm.reset();
            algorithm.update(password.getBytes());
            final byte[] md5Byte = algorithm.digest();
            final StringBuffer buffer = new StringBuffer();
            for (final byte b : md5Byte) {
                if ((b <= 15) && (b >= 0)) {
                    buffer.append("0");
                }
                buffer.append(Integer.toHexString(0xFF & b));
            }
            response = (amd5Password != null) && amd5Password.equals(buffer.toString());
        } catch (final NoSuchAlgorithmException e) {
            ProjektUtil.LOG.error("No digester MD5 found in classpath!", e);
        }
        return response;
    }
public static String getMd5Password(final String password) {
        String response = null;
        try {
            final MessageDigest algorithm = MessageDigest.getInstance("MD5");
            algorithm.reset();
            algorithm.update(password.getBytes());
            final byte[] md5Byte = algorithm.digest();
            final StringBuffer buffer = new StringBuffer();
            for (final byte b : md5Byte) {
                if ((b <= 15) && (b >= 0)) {
                    buffer.append("0");
                }
                buffer.append(Integer.toHexString(0xFF & b));
            }
            response = buffer.toString();
        } catch (final NoSuchAlgorithmException e) {
            ProjektUtil.LOG.error("No digester MD5 found in classpath!", e);
        }
        return response;
    }
public HashMap parseFile(File newfile) throws IOException {
        String s;
        String[] tokens;
        int nvalues = 0;
        double num1, num2, num3;
        boolean baddata = false;
        URL url = newfile.toURL();
        InputStream is = url.openStream();
        InputStreamReader isr = new InputStreamReader(is);
        BufferedReader br = new BufferedReader(isr);
        HashMap data = new HashMap();
        while ((s = br.readLine()) != null) {
            tokens = s.split("\\s+");
            nvalues = tokens.length;
            if (nvalues == 2) {
                data.put(new String(tokens[0]), new Double(Double.parseDouble(tokens[1])));
            } else {
                System.out.println("Sorry, trouble reading reference file.");
            }
        }
        return data;
    }
private PieceSet[] getPieceSets() {
        Resource[] resources = boardManager.getResources("pieces");
        PieceSet[] pieceSets = new PieceSet[resources.length];
        for (int i = 0; i < resources.length; i++) pieceSets[i] = (PieceSet) resources[i];
        for (int i = 0; i < resources.length; i++) {
            for (int j = 0; j < resources.length - (i + 1); j++) {
                String name1 = pieceSets[j].getName();
                String name2 = pieceSets[j + 1].getName();
                if (name1.compareTo(name2) > 0) {
                    PieceSet tmp = pieceSets[j];
                    pieceSets[j] = pieceSets[j + 1];
                    pieceSets[j + 1] = tmp;
                }
            }
        }
        return pieceSets;
    }
private BoardPattern[] getBoardPatterns() {
        Resource[] resources = boardManager.getResources("boards");
        BoardPattern[] boardPatterns = new BoardPattern[resources.length];
        for (int i = 0; i < resources.length; i++) boardPatterns[i] = (BoardPattern) resources[i];
        for (int i = 0; i < resources.length; i++) {
            for (int j = 0; j < resources.length - (i + 1); j++) {
                String name1 = boardPatterns[j].getName();
                String name2 = boardPatterns[j + 1].getName();
                if (name1.compareTo(name2) > 0) {
                    BoardPattern tmp = boardPatterns[j];
                    boardPatterns[j] = boardPatterns[j + 1];
                    boardPatterns[j + 1] = tmp;
                }
            }
        }
        return boardPatterns;
    }
private static String encode(String str, String method) {
        MessageDigest md = null;
        String dstr = null;
        try {
            md = MessageDigest.getInstance(method);
            md.update(str.getBytes());
            dstr = new BigInteger(1, md.digest()).toString(16);
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return dstr;
    }
public static String getHash(String password, String salt) throws NoSuchAlgorithmException, UnsupportedEncodingException {
        logger.debug("Entering getHash with password = " + password + "\n and salt = " + salt);
        MessageDigest digest = MessageDigest.getInstance("SHA-512");
        digest.reset();
        digest.update(salt.getBytes());
        byte[] input = digest.digest(password.getBytes("UTF-8"));
        String hashResult = String.valueOf(input);
        logger.debug("Exiting getHash with hasResult of " + hashResult);
        return hashResult;
    }
public static String md5(String str) {
        if (str == null) {
            System.err.println("Stringx.md5 (String) : null string.");
            return "";
        }
        String rt = "";
        try {
            MessageDigest md5 = MessageDigest.getInstance("MD5");
            md5.update(str.getBytes("gb2312"));
            byte[] bt = md5.digest();
            String s = null;
            int l = 0;
            for (int i = 0; i < bt.length; i++) {
                s = Integer.toHexString(bt[i]);
                l = s.length();
                if (l > 2) s = s.substring(l - 2, l); else if (l == 1) s = "0" + s;
                rt += s;
            }
        } catch (NoSuchAlgorithmException e1) {
            e1.printStackTrace();
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return rt;
    }
public static void copyFile(File source, File dest) throws Exception {
        log.warn("File names are " + source.toString() + "   and " + dest.toString());
        if (!dest.getParentFile().exists()) dest.getParentFile().mkdir();
        FileChannel sourceChannel = new FileInputStream(source).getChannel();
        FileChannel destinationChannel = new FileOutputStream(dest).getChannel();
        sourceChannel.transferTo(0, sourceChannel.size(), destinationChannel);
        sourceChannel.close();
        destinationChannel.close();
    }
@Override
    public List<SearchResult> search(String query, SortOrder order, int maxResults) throws Exception {
        if (query == null) {
            return null;
        }
        String encodedQuery = "";
        try {
            encodedQuery = URLEncoder.encode(query, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            throw e;
        }
        final int startAt = 0;
        final int pageNr = (startAt - 1) / 30;
        final String url = String.format(QUERYURL, encodedQuery, String.valueOf(pageNr), (order == SortOrder.BySeeders ? SORT_SEEDS : SORT_COMPOSITE));
        HttpParams httpparams = new BasicHttpParams();
        HttpConnectionParams.setConnectionTimeout(httpparams, CONNECTION_TIMEOUT);
        HttpConnectionParams.setSoTimeout(httpparams, CONNECTION_TIMEOUT);
        DefaultHttpClient httpclient = new DefaultHttpClient(httpparams);
        httpclient.getParams().setParameter("http.useragent", "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.2) Gecko/20100316 Firefox/3.6.2");
        HttpGet httpget = new HttpGet(url);
        HttpResponse response = httpclient.execute(httpget);
        InputStream instream = response.getEntity().getContent();
        String html = HttpHelper.ConvertStreamToString(instream);
        instream.close();
        return parseHtml(html);
    }
public static TerminatedInputStream find(URL url, String entryName) throws IOException {
        if (url.getProtocol().equals("file")) {
            return find(new File(url.getFile()), entryName);
        } else {
            return find(url.openStream(), entryName);
        }
    }
public static void copyFile(final File source, final File dest) throws IOException {
        FileChannel in = null, out = null;
        try {
            in = new FileInputStream(source).getChannel();
            out = new FileOutputStream(dest).getChannel();
            long size = in.size();
            MappedByteBuffer buf = in.map(FileChannel.MapMode.READ_ONLY, 0, size);
            out.write(buf);
        } finally {
            if (in != null) {
                in.close();
            }
            if (out != null) {
                out.close();
            }
        }
    }
public void run() {
        String s;
        s = "";
        try {
            URL url = new URL("http://www.askoxford.com/concise_oed/" + word.toLowerCase() + "?view=uk");
            BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
            String str;
            while (((str = in.readLine()) != null) && (!stopped)) {
                s = s + str;
            }
            in.close();
        } catch (MalformedURLException e) {
        } catch (IOException e) {
        }
        Pattern pattern = Pattern.compile("<h2>" + word.toLowerCase() + "(.+?)<p><a href", Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
        Matcher matcher = pattern.matcher(s);
        java.io.StringWriter wr = new java.io.StringWriter();
        HTMLDocument doc = null;
        HTMLEditorKit kit = (HTMLEditorKit) editor.getEditorKit();
        try {
            doc = (HTMLDocument) editor.getDocument();
        } catch (Exception e) {
        }
        System.out.println(wr);
        editor.setContentType("text/html");
        if (matcher.find()) try {
            kit.insertHTML(doc, editor.getCaretPosition(), "<HR>" + matcher.group(1) + "<HR>", 0, 0, null);
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
        } else try {
            kit.insertHTML(doc, editor.getCaretPosition(), "<HR><FONT COLOR='RED'>NOT FOUND!!</FONT><HR>", 0, 0, null);
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
        }
        button.setEnabled(true);
    }
public static void copy(String fromFileName, String toFileName) throws IOException {
        File fromFile = new File(fromFileName);
        File toFile = new File(toFileName);
        if (!fromFile.exists()) throw new IOException("FileCopy: " + "no such source file: " + fromFileName);
        if (!fromFile.isFile()) throw new IOException("FileCopy: " + "can't copy directory: " + fromFileName);
        if (!fromFile.canRead()) throw new IOException("FileCopy: " + "source file is unreadable: " + fromFileName);
        if (toFile.isDirectory()) toFile = new File(toFile, fromFile.getName());
        if (toFile.exists()) {
            if (!toFile.canWrite()) throw new IOException("FileCopy: " + "destination file is unwriteable: " + toFileName);
        } else {
            String parent = toFile.getParent();
            if (parent == null) parent = System.getProperty("user.dir");
            File dir = new File(parent);
            if (!dir.exists()) throw new IOException("FileCopy: " + "destination directory doesn't exist: " + parent);
            if (dir.isFile()) throw new IOException("FileCopy: " + "destination is not a directory: " + parent);
            if (!dir.canWrite()) throw new IOException("FileCopy: " + "destination directory is unwriteable: " + parent);
        }
        FileInputStream from = null;
        FileOutputStream to = null;
        try {
            from = new FileInputStream(fromFile);
            to = new FileOutputStream(toFile);
            byte[] buffer = new byte[4096];
            int bytesRead;
            while ((bytesRead = from.read(buffer)) != -1) to.write(buffer, 0, bytesRead);
        } finally {
            if (from != null) try {
                from.close();
            } catch (IOException e) {
                ;
            }
            if (to != null) try {
                to.close();
            } catch (IOException e) {
                ;
            }
        }
    }
public boolean isServerAlive(String pStrURL) {
        boolean isAlive;
        long t1 = System.currentTimeMillis();
        try {
            URL url = new URL(pStrURL);
            BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
            String inputLine;
            while ((inputLine = in.readLine()) != null) {
                logger.fine(inputLine);
            }
            logger.info("**  Connection successful..  **");
            in.close();
            isAlive = true;
        } catch (Exception e) {
            logger.info("**  Connection failed..  **");
            e.printStackTrace();
            isAlive = false;
        }
        long t2 = System.currentTimeMillis();
        logger.info("Time taken to check connection: " + (t2 - t1) + " ms.");
        return isAlive;
    }
private void doProcess(HttpServletRequest request, HttpServletResponse resp) throws IOException, InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException {
        Analyzer analyzer = new Analyzer();
        ServletContext context = getServletContext();
        String xml = context.getRealPath("data\\log.xml");
        String xsd = context.getRealPath("data\\log.xsd");
        String grs = context.getRealPath("reports\\" + request.getParameter("type") + ".grs");
        String pdf = context.getRealPath("html\\report.pdf");
        System.out.println("omg: " + request.getParameter("type"));
        System.out.println("omg: " + request.getParameter("pc"));
        int pcount = Integer.parseInt(request.getParameter("pc"));
        String[] params = new String[pcount];
        for (int i = 0; i < pcount; i++) {
            params[i] = request.getParameter("p" + i);
        }
        try {
            analyzer.generateReport(xml, xsd, grs, pdf, params);
        } catch (Exception e) {
            e.printStackTrace();
        }
        File file = new File(pdf);
        byte[] bs = tryLoadFile(pdf);
        if (bs == null) throw new NullPointerException();
        resp.setHeader("Content-Disposition", " filename=\"" + file.getName() + "\";");
        resp.setContentLength(bs.length);
        InputStream is = new ByteArrayInputStream(bs);
        IOUtils.copy(is, resp.getOutputStream());
    }
private static byte[] tryLoadFile(String path) throws IOException {
        InputStream in = new FileInputStream(path);
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        IOUtils.copy(in, out);
        in.close();
        out.close();
        return out.toByteArray();
    }