semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
private void onDhReply(final SshDhReply msg) throws GeneralSecurityException, IOException {
        if ((this.keyPair == null) || this.connection.isServer()) throw new SshException("%s: unexpected %s", this.connection.uri, msg.getType());
        final BigInteger k;
        {
            final DHPublicKeySpec remoteKeySpec = new DHPublicKeySpec(new BigInteger(msg.f), P1, G);
            final KeyFactory dhKeyFact = KeyFactory.getInstance("DH");
            final DHPublicKey remotePubKey = (DHPublicKey) dhKeyFact.generatePublic(remoteKeySpec);
            final KeyAgreement dhKex = KeyAgreement.getInstance("DH");
            dhKex.init(this.keyPair.getPrivate());
            dhKex.doPhase(remotePubKey, true);
            k = new BigInteger(dhKex.generateSecret());
        }
        final MessageDigest md = createMessageDigest();
        final byte[] h;
        {
            updateByteArray(md, SshVersion.LOCAL.toString().getBytes());
            updateByteArray(md, this.connection.getRemoteSshVersion().toString().getBytes());
            updateByteArray(md, this.keyExchangeInitLocal.getPayload());
            updateByteArray(md, this.keyExchangeInitRemote.getPayload());
            updateByteArray(md, msg.hostKey);
            updateByteArray(md, ((DHPublicKey) this.keyPair.getPublic()).getY().toByteArray());
            updateByteArray(md, msg.f);
            updateBigInt(md, k);
            h = md.digest();
        }
        if (this.sessionId == null) this.sessionId = h;
        this.keyExchangeInitLocal = null;
        this.keyExchangeInitRemote = null;
        this.h = h;
        this.k = k;
        this.connection.send(new SshKeyExchangeNewKeys());
    }
private void modifyProperty(String valueID, String value, Long userID) throws JspTagException {
        Property property = new Property(new Long(valueID), userID);
        String newValue = value;
        System.out.println(property.getName());
        if (property.getName().equals("Password")) {
            try {
                MessageDigest crypt = MessageDigest.getInstance("MD5");
                crypt.update(value.getBytes());
                byte digest[] = crypt.digest();
                StringBuffer hexString = new StringBuffer();
                for (int i = 0; i < digest.length; i++) {
                    hexString.append(hexDigit(digest[i]));
                }
                newValue = hexString.toString();
                crypt.reset();
            } catch (NoSuchAlgorithmException e) {
                System.err.println("jspShop: Could not get instance of MD5 algorithm. Please fix this!" + e.getMessage());
                e.printStackTrace();
                throw new JspTagException("Error crypting password!: " + e.getMessage());
            }
        }
        property.setValue(newValue);
    }
public CServletContextWrapper(final FileSystem fs, final String contextName) {
        this.fs = fs;
        this.name = contextName;
        CContext.getInstance().init(this);
        try {
            URL url = this.getResource("/WEB-INF/classes/log4j.properties");
            boolean ok = false;
            InputStream in = null;
            try {
                in = url.openStream();
                ok = true;
            } catch (Throwable e) {
            } finally {
                try {
                    if (in != null) in.close();
                } catch (Exception ignore) {
                }
            }
            if (ok) {
                PropertyConfigurator.configure(url);
            }
        } catch (final Throwable e) {
            if (!hasPrintedLog4JWarning) {
                hasPrintedLog4JWarning = true;
                System.err.println("!!! WARNING: /WEB-INF/classes/log4j.properties missing.");
            }
        }
        this.init();
        this.loadServletContextListener();
        this.log = LOGGERHelper.getLogger(this.getClass());
        CJNDIContextSetup.init(this);
        JDBCPooler.init(this);
        CResourceBundle.registerBundles(this);
        this.fireInitEvent();
    }
public FlashExObj get(String s, int page) {
        FlashExObj retVal = new FlashExObj();
        s = s.replaceAll("[^a-z0-9_]", "");
        ArrayList list = new ArrayList();
        retVal.list = list;
        try {
            String result = null;
            URL url = new URL("http://www.flashcardexchange.com/flashcards/list/" + URLEncoder.encode(s, "UTF-8") + "?page=" + page);
            URLConnection connection = url.openConnection();
            connection.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
            connection.setDoOutput(false);
            BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8"));
            String inputLine;
            int state = 2;
            StringBuilder sb = new StringBuilder();
            while ((inputLine = in.readLine()) != null) {
                if (state == 0) {
                    int textPos = inputLine.indexOf("Number of Card");
                    if (textPos >= 0) {
                        state = 1;
                    }
                } else if (state == 1) {
                    int s1 = inputLine.indexOf(">");
                    int s2 = inputLine.indexOf("<", 1);
                    if (s1 >= 0 && s1 < s2) {
                        String numOfCardStr = inputLine.substring(s1 + 1, s2);
                        try {
                        } catch (Exception e) {
                        }
                        state = 2;
                    }
                } else if (state == 2) {
                    int textPos = inputLine.indexOf("tbody class=\"shaded\"");
                    if (textPos >= 0) {
                        state = 3;
                    }
                } else if (state == 3) {
                    int textPos = inputLine.indexOf("tbody");
                    if (textPos >= 0) {
                        break;
                    }
                    sb.append(inputLine);
                    sb.append(" ");
                }
            }
            in.close();
            Pattern myPattern = Pattern.compile("<td>(.*?)</td>");
            Matcher myMatcher = myPattern.matcher(sb);
            String str;
            int counter = 0;
            String buff[] = new String[4];
            while (myMatcher.find()) {
                int tt = counter % 4;
                buff[tt] = myMatcher.group(1);
                if (tt == 3) {
                    String toAdd[] = new String[2];
                    toAdd[0] = buff[1];
                    toAdd[1] = buff[2];
                    list.add(toAdd);
                }
                counter++;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return retVal;
    }
protected void handleUrl(URL url) throws Exception {
        File file = new File(dir.getAbsolutePath() + "/" + new Date().getTime() + "." + this.ext);
        FileWriter writer = new FileWriter(file);
        BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
        String s;
        while ((s = in.readLine()) != null) {
            writer.write(s + "\n");
        }
        in.close();
        writer.close();
    }
public static void contentTrans(String contents, String urlString, String urlString2, String serverIp, int port) {
        try {
            URL url = new URL(urlString);
            url.openStream();
        } catch (Exception e) {
            e.printStackTrace();
        }
        try {
            Socket server = new Socket(InetAddress.getByName(serverIp), port);
            OutputStream outputStream = server.getOutputStream();
            BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(outputStream, "UTF-8"));
            bufferedWriter.write(contents);
            bufferedWriter.flush();
            bufferedWriter.close();
            server.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        try {
            URL url2 = new URL(urlString2);
            url2.openStream();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
public static void fileTrans(String filePath, String urlString, String urlString2, String serverIp, int port) {
        try {
            URL url = new URL(urlString);
            url.openStream();
        } catch (Exception e) {
            e.printStackTrace();
        }
        File file = new File(filePath);
        try {
            FileInputStream fis = new FileInputStream(file);
            Socket server = new Socket(InetAddress.getByName(serverIp), port);
            OutputStream outputStream = server.getOutputStream();
            DataOutputStream dataOutputStream = new DataOutputStream(new BufferedOutputStream(outputStream));
            byte[] buffer = new byte[2048];
            int num = fis.read(buffer);
            while (num != -1) {
                dataOutputStream.write(buffer, 0, num);
                dataOutputStream.flush();
                num = fis.read(buffer);
            }
            fis.close();
            dataOutputStream.close();
            server.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        try {
            URL url2 = new URL(urlString2);
            url2.openStream();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
public static boolean copy(String source, String dest) {
        int bytes;
        byte array[] = new byte[BUFFER_LEN];
        try {
            InputStream is = new FileInputStream(source);
            OutputStream os = new FileOutputStream(dest);
            while ((bytes = is.read(array, 0, BUFFER_LEN)) > 0) os.write(array, 0, bytes);
            is.close();
            os.close();
            return true;
        } catch (IOException e) {
            return false;
        }
    }
@Override
    public void run() {
        try {
            FileChannel in = new FileInputStream(inputfile).getChannel();
            long pos = 0;
            for (int i = 1; i <= noofparts; i++) {
                FileChannel out = new FileOutputStream(outputfile.getAbsolutePath() + "." + "v" + i).getChannel();
                status.setText("Rozdělovač: Rozděluji část " + i + "..");
                if (remainingsize >= splitsize) {
                    in.transferTo(pos, splitsize, out);
                    pos += splitsize;
                    remainingsize -= splitsize;
                } else {
                    in.transferTo(pos, remainingsize, out);
                }
                pb.setValue(100 * i / noofparts);
                out.close();
            }
            in.close();
            if (deleteOnFinish) new File(inputfile + "").delete();
            status.setText("Rozdělovač: Hotovo..");
            JOptionPane.showMessageDialog(null, "Rozděleno!", "Rozdělovač", JOptionPane.INFORMATION_MESSAGE);
        } catch (IOException ex) {
        }
    }
public IStatus runInUIThread(IProgressMonitor monitor) {
            monitor.beginTask(Strings.MSG_CONNECT_SERVER, 3);
            InputStream in = null;
            try {
                URL url = createOpenUrl(resource, pref);
                if (url != null) {
                    URLConnection con = url.openConnection();
                    monitor.worked(1);
                    monitor.setTaskName(Strings.MSG_WAIT_FOR_SERVER);
                    con.connect();
                    in = con.getInputStream();
                    in.read();
                    monitor.worked(1);
                    monitor.setTaskName(NLS.bind(Strings.MSG_OPEN_URL, url));
                    open(url, resource.getProject(), pref);
                    monitor.worked(1);
                }
            } catch (ConnectException con) {
                if (count < 3) {
                    ConnectAndOpenJob job = new ConnectAndOpenJob(resource, pref, ++count);
                    job.schedule(1000L);
                } else {
                    Activator.log(con);
                }
            } catch (Exception e) {
                Activator.log(e);
            } finally {
                Streams.close(in);
                monitor.done();
            }
            return Status.OK_STATUS;
        }
private String fetchHtml(URL url) throws IOException {
        URLConnection connection;
        if (StringUtils.isNotBlank(proxyHost) && proxyPort != null) {
            Proxy proxy = new Proxy(Proxy.Type.HTTP, InetSocketAddress.createUnresolved(proxyHost, proxyPort));
            connection = url.openConnection(proxy);
        } else {
            connection = url.openConnection();
        }
        Object content = connection.getContent();
        if (content instanceof InputStream) {
            return IOUtils.toString(InputStream.class.cast(content));
        } else {
            String msg = "Bad content type! " + content.getClass();
            log.error(msg);
            throw new IOException(msg);
        }
    }
public static final String Digest(String credentials, String algorithm, String encoding) {
        try {
            MessageDigest md = (MessageDigest) MessageDigest.getInstance(algorithm).clone();
            if (encoding == null) {
                md.update(credentials.getBytes());
            } else {
                md.update(credentials.getBytes(encoding));
            }
            return (HexUtils.convert(md.digest()));
        } catch (Exception ex) {
            log.error(ex);
            return credentials;
        }
    }
public static String getDigest(String input) throws NoSuchAlgorithmException {
        MessageDigest md5 = MessageDigest.getInstance("MD5");
        md5.update(input.getBytes());
        byte[] outDigest = md5.digest();
        StringBuffer outBuf = new StringBuffer(33);
        for (int i = 0; i < outDigest.length; i++) {
            byte b = outDigest[i];
            int hi = (b >> 4) & 0x0f;
            outBuf.append(MD5Digest.hexTab[hi]);
            int lo = b & 0x0f;
            outBuf.append(MD5Digest.hexTab[lo]);
        }
        return outBuf.toString();
    }
public static void s_copy(FileInputStream fis, FileOutputStream fos) throws Exception {
        FileChannel in = fis.getChannel();
        FileChannel out = fos.getChannel();
        in.transferTo(0, in.size(), out);
        if (in != null) in.close();
        if (out != null) out.close();
    }
private void pack() {
        String szImageDir = m_szBasePath + "Images";
        File fImageDir = new File(szImageDir);
        fImageDir.mkdirs();
        String ljIcon = System.getProperty("user.home");
        ljIcon += System.getProperty("file.separator") + "MochaJournal" + System.getProperty("file.separator") + m_szUsername + System.getProperty("file.separator") + "Cache";
        File fUserDir = new File(ljIcon);
        File[] fIcons = fUserDir.listFiles();
        int iSize = fIcons.length;
        for (int i = 0; i < iSize; i++) {
            try {
                File fOutput = new File(fImageDir, fIcons[i].getName());
                if (!fOutput.exists()) {
                    fOutput.createNewFile();
                    FileOutputStream fOut = new FileOutputStream(fOutput);
                    FileInputStream fIn = new FileInputStream(fIcons[i]);
                    while (fIn.available() > 0) fOut.write(fIn.read());
                }
            } catch (IOException e) {
                System.err.println(e);
            }
        }
        try {
            FileOutputStream fOut;
            InputStream fLJIcon = getClass().getResourceAsStream("/org/homedns/krolain/MochaJournal/Images/userinfo.gif");
            File fLJOut = new File(fImageDir, "user.gif");
            if (!fLJOut.exists()) {
                fOut = new FileOutputStream(fLJOut);
                while (fLJIcon.available() > 0) fOut.write(fLJIcon.read());
            }
            fLJIcon = getClass().getResourceAsStream("/org/homedns/krolain/MochaJournal/Images/communitynfo.gif");
            fLJOut = new File(fImageDir, "comm.gif");
            if (!fLJOut.exists()) {
                fOut = new FileOutputStream(fLJOut);
                while (fLJIcon.available() > 0) fOut.write(fLJIcon.read());
            }
            fLJIcon = getClass().getResourceAsStream("/org/homedns/krolain/MochaJournal/Images/icon_private.gif");
            fLJOut = new File(fImageDir, "icon_private.gif");
            if (!fLJOut.exists()) {
                fOut = new FileOutputStream(fLJOut);
                while (fLJIcon.available() > 0) fOut.write(fLJIcon.read());
            }
            fLJIcon = getClass().getResourceAsStream("/org/homedns/krolain/MochaJournal/Images/icon_protected.gif");
            fLJOut = new File(fImageDir, "icon_protected.gif");
            if (!fLJOut.exists()) {
                fOut = new FileOutputStream(fLJOut);
                while (fLJIcon.available() > 0) fOut.write(fLJIcon.read());
            }
        } catch (IOException e) {
            System.err.println(e);
        }
    }
public static File downloadFile(Proxy proxy, URL url, File path) throws IOException {
        URLConnection conn = null;
        if (null == proxy) {
            conn = url.openConnection();
        } else {
            conn = url.openConnection(proxy);
        }
        conn.connect();
        File destFile = null;
        if (conn instanceof HttpURLConnection) {
            HttpURLConnection hc = (HttpURLConnection) conn;
            String filename = null;
            String hv = hc.getHeaderField("Content-Disposition");
            if (null == hv) {
                String str = url.toString();
                int index = str.lastIndexOf("/");
                filename = str.substring(index + 1);
            } else {
                int index = hv.indexOf("filename=");
                filename = hv.substring(index).replace("\"", "").trim();
            }
            destFile = new File(path, filename);
        } else {
            destFile = new File(path, "downloadfile" + url.toString().hashCode());
        }
        if (destFile.exists()) {
            return destFile;
        }
        FileOutputStream fos = new FileOutputStream(destFile);
        byte[] buffer = new byte[2048];
        try {
            while (true) {
                int len = conn.getInputStream().read(buffer);
                if (len < 0) {
                    break;
                } else {
                    fos.write(buffer, 0, len);
                }
            }
            fos.close();
        } catch (IOException e) {
            destFile.delete();
            throw e;
        }
        return destFile;
    }
@SuppressWarnings("unused")
    private GraphicalViewer createGraphicalViewer(Composite parent) {
        GraphicalViewer viewer = new ScrollingGraphicalViewer();
        viewer.createControl(parent);
        viewer.getControl().setBackground(parent.getBackground());
        viewer.setRootEditPart(new ScalableFreeformRootEditPart());
        viewer.setKeyHandler(new GraphicalViewerKeyHandler(viewer));
        getEditDomain().addViewer(viewer);
        getSite().setSelectionProvider(viewer);
        viewer.setEditPartFactory(getEditPartFactory());
        viewer.setContents(getContent());
        return viewer;
    }
public static String generate(String username, String password) throws PersistenceException {
        String output = null;
        try {
            MessageDigest md = MessageDigest.getInstance("SHA-256");
            md.reset();
            md.update(username.getBytes());
            md.update(password.getBytes());
            byte[] rawhash = md.digest();
            output = byteToBase64(rawhash);
        } catch (Exception e) {
            throw new PersistenceException("error, could not generate password");
        }
        return output;
    }
private static String getData(String myurl) throws Exception {
        URL url = new URL(myurl);
        uc = (HttpURLConnection) url.openConnection();
        if (login) {
            uc.setRequestProperty("Cookie", logincookie + ";" + xfsscookie);
        }
        br = new BufferedReader(new InputStreamReader(uc.getInputStream()));
        String temp = "", k = "";
        while ((temp = br.readLine()) != null) {
            k += temp;
        }
        br.close();
        return k;
    }
private static void fileUpload() throws IOException {
        HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost(postURL);
        file = new File("h:/UploadingdotcomUploaderPlugin.java");
        MultipartEntity mpEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
        ContentBody cbFile = new FileBody(file);
        mpEntity.addPart("upload_type", new StringBody("file"));
        mpEntity.addPart("sess_id", new StringBody(sessid));
        mpEntity.addPart("srv_tmp_url", new StringBody(servertmpurl));
        mpEntity.addPart("file_0", cbFile);
        mpEntity.addPart("submit_btn", new StringBody(" Upload!"));
        httppost.setEntity(mpEntity);
        System.out.println("executing request " + httppost.getRequestLine());
        System.out.println("Now uploading your file into enterupload.com");
        HttpResponse response = httpclient.execute(httppost);
        HttpEntity resEntity = response.getEntity();
        System.out.println(response.getStatusLine());
        if (resEntity != null) {
            uploadresponse = EntityUtils.toString(resEntity);
        }
        downloadid = parseResponse(uploadresponse, "<textarea name='fn'>", "<");
        httpclient.getConnectionManager().shutdown();
    }
private static void copy(String sourceName, String destName) throws IOException {
        File source = new File(sourceName);
        File dest = new File(destName);
        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 NodeId generateTopicId(String topicName) {
        MessageDigest md = null;
        try {
            md = MessageDigest.getInstance("SHA");
        } catch (NoSuchAlgorithmException e) {
            System.err.println("No SHA support!");
        }
        md.update(topicName.getBytes());
        byte[] digest = md.digest();
        NodeId newId = new NodeId(digest);
        return newId;
    }