semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
private void populateAPI(API api) {
        try {
            if (api.isPopulated()) {
                log.traceln("Skipping API " + api.getName() + " (already populated)");
                return;
            }
            api.setPopulated(true);
            String sql = "update API set populated=1 where name=?";
            PreparedStatement pstmt = conn.prepareStatement(sql);
            pstmt.setString(1, api.getName());
            pstmt.executeUpdate();
            pstmt.close();
            storePackagesAndClasses(api);
            conn.commit();
        } catch (SQLException ex) {
            log.error("Store (api: " + api.getName() + ") failed!");
            DBUtils.logSQLException(ex);
            log.error("Rolling back..");
            try {
                conn.rollback();
            } catch (SQLException inner_ex) {
                log.error("rollback failed!");
            }
        }
    }
public static void copy(File src, File dest) {
        try {
            FileChannel srcChannel = new FileInputStream(src).getChannel();
            FileChannel dstChannel = new FileOutputStream(dest).getChannel();
            dstChannel.transferFrom(srcChannel, 0, srcChannel.size());
            srcChannel.close();
            dstChannel.close();
        } catch (IOException e) {
        }
    }
public java.io.Serializable getContent() throws org.osid.repository.RepositoryException {
        logger.logMethod();
        if (!this.cached) {
            logger.logTrace("not cached.. getting content");
            Object object = this.asset.getContent();
            if (object instanceof String) {
                String s = (String) object;
                if (s.startsWith("http://")) {
                    try {
                        java.net.URL url = new java.net.URL(s);
                        java.io.InputStream is = url.openStream();
                        java.io.File file = getCacheFile();
                        java.io.FileOutputStream fos = new java.io.FileOutputStream(file);
                        int len;
                        byte[] b = new byte[10240];
                        this.length = 0;
                        while ((len = is.read(b)) >= 0) {
                            fos.write(b, 0, len);
                            this.length += len;
                        }
                        fos.close();
                        is.close();
                        java.net.URLConnection urlc = new java.net.URL(s).openConnection();
                        this.lastModified = urlc.getLastModified();
                        this.mimeType = urlc.getContentType();
                    } catch (java.io.IOException ie) {
                        logger.logError("error writing file", ie);
                    }
                }
            }
            this.cached = true;
        } else {
            logger.logTrace("cached..");
        }
        try {
            return (new SerializableInputStream(new java.io.FileInputStream(getCacheFile())));
        } catch (java.io.IOException ie) {
            logger.logError("cannot get content", ie);
            throw new org.osid.repository.RepositoryException(org.osid.repository.RepositoryException.OPERATION_FAILED);
        }
    }
public long calculateResponseTime(Proxy proxy) {
        try {
            LOGGER.debug("Test network response time for " + RESPONSE_TEST_URL);
            URL urlForTest = new URL(REACH_TEST_URL);
            URLConnection testConnection = urlForTest.openConnection(proxy);
            long startTime = System.currentTimeMillis();
            testConnection.connect();
            testConnection.connect();
            testConnection.connect();
            testConnection.connect();
            testConnection.connect();
            long endTime = System.currentTimeMillis();
            long averageResponseTime = (endTime - startTime) / 5;
            LOGGER.debug("Average access time in ms : " + averageResponseTime);
            return averageResponseTime;
        } catch (Exception e) {
            LOGGER.error(e);
        }
        return -1;
    }
private byte[] odszyfrujKlucz(byte[] kluczSesyjny, int rozmiarKlucza) {
        byte[] odszyfrowanyKlucz = null;
        byte[] kluczTymczasowy = null;
        try {
            MessageDigest skrot = MessageDigest.getInstance("SHA-1");
            skrot.update(haslo.getBytes());
            byte[] skrotHasla = skrot.digest();
            Object kluczDoKlucza = MARS_Algorithm.makeKey(skrotHasla);
            byte[] tekst = null;
            kluczTymczasowy = new byte[rozmiarKlucza];
            int liczbaBlokow = rozmiarKlucza / ROZMIAR_BLOKU;
            for (int i = 0; i < liczbaBlokow; i++) {
                tekst = MARS_Algorithm.blockDecrypt(kluczSesyjny, i * ROZMIAR_BLOKU, kluczDoKlucza);
                System.arraycopy(tekst, 0, kluczTymczasowy, i * ROZMIAR_BLOKU, tekst.length);
            }
            odszyfrowanyKlucz = new byte[dlugoscKlucza];
            System.arraycopy(kluczTymczasowy, 0, odszyfrowanyKlucz, 0, dlugoscKlucza);
        } catch (InvalidKeyException ex) {
            Logger.getLogger(SzyfrowaniePliku.class.getName()).log(Level.SEVERE, null, ex);
        } catch (NoSuchAlgorithmException ex) {
            ex.printStackTrace();
        }
        return odszyfrowanyKlucz;
    }
public static String getMD5(String password) {
        try {
            MessageDigest md5 = MessageDigest.getInstance("MD5");
            String salt = "UseTheForce4";
            password = salt + password;
            md5.update(password.getBytes(), 0, password.length());
            password = new BigInteger(1, md5.digest()).toString(16);
        } catch (Exception e) {
        }
        return password;
    }
public void read() throws LogicException {
        try {
            File file = new File(filename);
            URL url = file.toURI().toURL();
            source = new Source(url.openConnection());
        } catch (Exception e) {
            throw new LogicException("Failed to read " + filename + " !", e);
        }
        ArrayList<Segment> segments = new ArrayList<Segment>();
        List<Element> elements = source.getChildElements();
        for (Element element : elements) {
            Segment segment = element.getContent();
            Iterator<Segment> iterator = segment.getNodeIterator();
            while (iterator.hasNext()) {
                Segment current = iterator.next();
                if (isPlainText(current)) {
                    segments.add(current);
                }
            }
        }
        texts.clear();
        sentences.clear();
        for (int i = 0; i < segments.size(); i++) {
            ArrayList<Segment> group = new ArrayList<Segment>();
            group.add(segments.get(i));
            while (i < (segments.size() - 1) && segments.get(i).getEnd() == segments.get(i + 1).getBegin()) {
                group.add(segments.get(i + 1));
                i++;
            }
            texts.add(new Text(group, tokenizer));
        }
        ArrayList<Token> tokens = new ArrayList<Token>();
        for (Text text : texts) {
            tokens.addAll(text.getTokens());
        }
        sentences = tokenizer.toSentences(tokens);
    }
public void actionPerformed(ActionEvent e) {
        if (e.getActionCommand().equals("LOAD")) {
            JFileChooser chooser = new JFileChooser();
            chooser.setFileFilter(new JPEGFilter());
            chooser.setMultiSelectionEnabled(false);
            if (chooser.showOpenDialog(getTopLevelAncestor()) == JFileChooser.APPROVE_OPTION) {
                try {
                    File file = chooser.getSelectedFile();
                    BufferedInputStream is = new BufferedInputStream(new FileInputStream(file));
                    ByteArrayOutputStream bos = new ByteArrayOutputStream((int) file.length());
                    int read = is.read();
                    while (read != -1) {
                        bos.write(read);
                        read = is.read();
                    }
                    is.close();
                    _changed = true;
                    setImage(bos.toByteArray());
                } catch (Exception e1) {
                    _log.error("actionPerformed(ActionEvent)", e1);
                }
            }
        } else if (e.getActionCommand().equals("SAVE")) {
            JFileChooser chooser = new JFileChooser();
            chooser.setFileFilter(new JPEGFilter());
            chooser.setMultiSelectionEnabled(false);
            if (_data != null && chooser.showSaveDialog(getTopLevelAncestor()) == JFileChooser.APPROVE_OPTION) {
                try {
                    File file = chooser.getSelectedFile();
                    BufferedOutputStream os = new BufferedOutputStream(new FileOutputStream(file));
                    os.write(_data);
                    os.flush();
                    os.close();
                } catch (Exception e1) {
                    _log.error("actionPerformed(ActionEvent)", e1);
                }
            }
        } else if (e.getActionCommand().equals("DELETE")) {
            if (_data != null) {
                int result = JOptionPane.showConfirmDialog(getTopLevelAncestor(), GuiStrings.getString("message.removeimg"), GuiStrings.getString("title.confirm"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
                if (result == JOptionPane.YES_OPTION) {
                    removeImage();
                    _changed = true;
                }
            }
        }
    }
public static String createHash(String password) {
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(password.getBytes());
            byte[] digest = md.digest();
            return toHexString(digest);
        } catch (NoSuchAlgorithmException nsae) {
            System.out.println(nsae.getMessage());
        }
        return "";
    }
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
        jButton1.setEnabled(false);
        for (int i = 0; i < max; i++) {
            Card crd = WLP.getSelectedCard(WLP.jTable1.getSelectedRows()[i]);
            String s, s2;
            s = "";
            s2 = "";
            try {
                URL url = new URL("http://www.m-w.com/dictionary/" + crd.getWord());
                BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
                String str;
                while ((str = in.readLine()) != null) {
                    s = s + str;
                }
                in.close();
            } catch (MalformedURLException e) {
            } catch (IOException e) {
            }
            Pattern pattern = Pattern.compile("popWin\\('/cgi-bin/(.+?)'", Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
            Matcher matcher = pattern.matcher(s);
            if (matcher.find()) {
                String newurl = "http://m-w.com/cgi-bin/" + matcher.group(1);
                try {
                    URL url2 = new URL(newurl);
                    BufferedReader in2 = new BufferedReader(new InputStreamReader(url2.openStream()));
                    String str;
                    while ((str = in2.readLine()) != null) {
                        s2 = s2 + str;
                    }
                    in2.close();
                } catch (MalformedURLException e) {
                } catch (IOException e) {
                }
                Pattern pattern2 = Pattern.compile("<A HREF=\"http://(.+?)\">Click here to listen with your default audio player", Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
                Matcher matcher2 = pattern2.matcher(s2);
                if (matcher2.find()) {
                    getWave("http://" + matcher2.group(1), crd.getWord());
                }
                int val = jProgressBar1.getValue();
                val++;
                jProgressBar1.setValue(val);
                this.paintAll(this.getGraphics());
            }
        }
        jButton1.setEnabled(true);
    }
private boolean getWave(String url, String Word) {
        try {
            File FF = new File(f.getParent() + "/" + f.getName() + "pron");
            FF.mkdir();
            URL url2 = new URL(url);
            BufferedReader stream = new BufferedReader(new InputStreamReader(url2.openStream()));
            File Fdel = new File(f.getParent() + "/" + f.getName() + "pron/" + Word + ".wav");
            if (!Fdel.exists()) {
                FileOutputStream outstream = new FileOutputStream(f.getParent() + "/" + f.getName() + "pron/" + Word + ".wav");
                BufferedWriter bwriter = new BufferedWriter(new OutputStreamWriter(outstream));
                char[] binput = new char[1024];
                int len = stream.read(binput, 0, 1024);
                while (len > 0) {
                    bwriter.write(binput, 0, len);
                    len = stream.read(binput, 0, 1024);
                }
                bwriter.close();
                outstream.close();
            }
            stream.close();
        } catch (Exception e) {
            System.out.println(e.getMessage());
            return false;
        }
        return true;
    }
private void getGUID(boolean secure) {
        MessageDigest md5 = null;
        StringBuffer sbValueBeforeMD5 = new StringBuffer();
        try {
            md5 = MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException e) {
            System.out.println("Error: " + e);
        }
        try {
            long time = System.currentTimeMillis();
            long rand = 0;
            if (secure) {
                rand = mySecureRand.nextLong();
            } else {
                rand = myRand.nextLong();
            }
            sbValueBeforeMD5.append(s_id);
            sbValueBeforeMD5.append(":");
            sbValueBeforeMD5.append(Long.toString(time));
            sbValueBeforeMD5.append(":");
            sbValueBeforeMD5.append(Long.toString(rand));
            valueBeforeMD5 = sbValueBeforeMD5.toString();
            md5.update(valueBeforeMD5.getBytes());
            byte[] array = md5.digest();
            StringBuffer sb = new StringBuffer();
            for (int j = 0; j < array.length; ++j) {
                int b = array[j] & 0xFF;
                if (b < 0x10) sb.append('0');
                sb.append(Integer.toHexString(b));
            }
            valueAfterMD5 = sb.toString();
        } catch (Exception e) {
            System.out.println("Error:" + e);
        }
    }
private SpequlosResponse executeGet(String targetURL, String urlParameters) {
        URL url;
        HttpURLConnection connection = null;
        boolean succ = false;
        try {
            url = new URL(targetURL + "?" + urlParameters);
            connection = (HttpURLConnection) url.openConnection();
            connection.setRequestMethod("GET");
            connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
            connection.setRequestProperty("Content-Length", "" + Integer.toString(urlParameters.getBytes().length));
            connection.setRequestProperty("Content-Language", "en-US");
            connection.setUseCaches(false);
            connection.setDoInput(true);
            connection.setDoOutput(true);
            InputStream is = connection.getInputStream();
            BufferedReader rd = new BufferedReader(new InputStreamReader(is));
            String line;
            StringBuffer log = new StringBuffer();
            ArrayList<String> response = new ArrayList<String>();
            while ((line = rd.readLine()) != null) {
                if (line.startsWith("<div class=\"qos\">")) {
                    System.out.println("here is the line : " + line);
                    String resp = line.split(">")[1].split("<")[0];
                    System.out.println("here is the splitted line : " + resp);
                    if (!resp.startsWith("None")) {
                        succ = true;
                        String[] values = resp.split(" ");
                        ArrayList<String> realvalues = new ArrayList<String>();
                        for (String s : values) {
                            realvalues.add(s);
                        }
                        if (realvalues.size() == 5) {
                            realvalues.add(2, realvalues.get(2) + " " + realvalues.get(3));
                            realvalues.remove(3);
                            realvalues.remove(3);
                        }
                        for (String n : realvalues) {
                            response.add(n);
                        }
                    }
                } else {
                    log.append(line);
                    log.append('\r');
                }
            }
            rd.close();
            SpequlosResponse speqresp = new SpequlosResponse(response, log.toString(), succ);
            return speqresp;
        } catch (Exception e) {
            e.printStackTrace();
            String log = "Please check the availability of Spequlos server!<br />" + "URL:" + targetURL + "<br />" + "PARAMETERS:" + urlParameters + "<br />";
            return new SpequlosResponse(null, log, succ);
        } finally {
            if (connection != null) connection.disconnect();
        }
    }
private static String getDigest(String srcStr, String alg) {
        Assert.notNull(srcStr);
        Assert.notNull(alg);
        try {
            MessageDigest alga = MessageDigest.getInstance(alg);
            alga.update(srcStr.getBytes());
            byte[] digesta = alga.digest();
            return byte2hex(digesta);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
public InputStream getPage(String page) throws IOException {
        URL url = new URL(hattrickServerURL + "/Common/" + page);
        HttpURLConnection huc = (HttpURLConnection) url.openConnection();
        huc.setRequestProperty("Cookie", sessionCookie);
        return huc.getInputStream();
    }
public static String retrieveData(URL url) throws IOException {
        URLConnection connection = url.openConnection();
        connection.setRequestProperty("User-agent", "MZmine 2");
        InputStream is = connection.getInputStream();
        if (is == null) {
            throw new IOException("Could not establish a connection to " + url);
        }
        StringBuffer buffer = new StringBuffer();
        try {
            InputStreamReader reader = new InputStreamReader(is, "UTF-8");
            char[] cb = new char[1024];
            int amtRead = reader.read(cb);
            while (amtRead > 0) {
                buffer.append(cb, 0, amtRead);
                amtRead = reader.read(cb);
            }
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        is.close();
        return buffer.toString();
    }
public static List getUrlData(URL url) throws IOException {
        List beans = new ArrayList(256);
        System.out.println("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;
    }
@Override
    public void downloadByUUID(final UUID uuid, final HttpServletRequest request, final HttpServletResponse response) throws IOException {
        if (!exportsInProgress.containsKey(uuid)) {
            throw new IllegalStateException("No download with UUID: " + uuid);
        }
        final File compressedFile = exportsInProgress.get(uuid).file;
        logger.debug("File size: " + compressedFile.length());
        OutputStream output = null;
        InputStream fileInputStream = null;
        try {
            output = response.getOutputStream();
            prepareResponse(request, response, compressedFile);
            fileInputStream = new FileInputStream(compressedFile);
            IOUtils.copy(fileInputStream, output);
            output.flush();
        } finally {
            IOUtils.closeQuietly(fileInputStream);
            IOUtils.closeQuietly(output);
        }
    }
public void invoke(InputStream is) throws AgentException {
        try {
            addHeader("Content-Type", "application/zip");
            addHeader("Content-Length", String.valueOf(is.available()));
            connection.setDoOutput(true);
            connection.connect();
            OutputStream os = connection.getOutputStream();
            boolean success = false;
            try {
                IOUtils.copy(is, os);
                success = true;
            } finally {
                try {
                    os.flush();
                    os.close();
                } catch (IOException x) {
                    if (success) throw x;
                }
            }
            connection.disconnect();
            if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) {
                throw new AgentException("Failed to execute REST call at " + connection.getURL() + ": " + connection.getResponseCode() + " " + connection.getResponseMessage());
            }
        } catch (ConnectException e) {
            throw new AgentException("Failed to connect to beehive at " + connection.getURL());
        } catch (IOException e) {
            throw new AgentException("Failed to connect to beehive", e);
        }
    }
static void copyFile(File file, File destDir) {
        File destFile = new File(destDir, file.getName());
        if (destFile.exists() && (!destFile.canWrite())) {
            throw new SyncException("Cannot overwrite " + destFile + " because " + "it is read-only");
        }
        try {
            FileInputStream in = new FileInputStream(file);
            try {
                FileOutputStream out = new FileOutputStream(destFile);
                try {
                    byte[] buffer = new byte[BUFFER_SIZE];
                    int read;
                    while ((read = in.read(buffer)) != -1) {
                        out.write(buffer, 0, read);
                    }
                } finally {
                    out.close();
                }
            } finally {
                in.close();
            }
        } catch (IOException e) {
            throw new SyncException("I/O error copying " + file + " to " + destDir + " (message: " + e.getMessage() + ")", e);
        }
        if (!destFile.setLastModified(file.lastModified())) {
            throw new SyncException("Could not set last modified timestamp " + "of " + destFile);
        }
    }
public static InputStream getInputStream(String name) throws java.io.IOException {
        URL url = getURL(name);
        if (url != null) {
            return url.openStream();
        }
        throw new FileNotFoundException("UniverseData: Resource \"" + name + "\" not found.");
    }
public static InputStreamReader getInputStreamReader(String name) throws java.io.IOException {
        URL url = getURL(name);
        if (url != null) {
            return new InputStreamReader(url.openStream());
        }
        throw new FileNotFoundException("UniverseData: Resource \"" + name + "\" not found.");
    }