semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public boolean send(String number, String message) throws IOException {
        init();
        message = message.substring(0, Math.min(MAX_PAYLOAD, message.length()));
        message = message.replace('\r', ' ');
        message = message.replace('\n', ' ');
        ActualFormParameters params = new ActualFormParameters();
        String strippedNumber = strip(number);
        ActualFormParameter number1Param;
        ActualFormParameter number2Param;
        if (strippedNumber.startsWith("00")) strippedNumber = "+" + strippedNumber.substring(2); else if (strippedNumber.startsWith("0")) strippedNumber = "+49" + strippedNumber.substring(1);
        number1Param = new ActualFormParameter(number1InputElement.getName(), strippedNumber.substring(0, 6));
        number2Param = new ActualFormParameter(number2InputElement.getName(), strippedNumber.substring(6));
        params.add(number1Param);
        params.add(number2Param);
        ActualFormParameter messageParam = new ActualFormParameter(messageInputElement.getName(), message);
        params.add(messageParam);
        ActualFormParameter letterCountParam = new ActualFormParameter(letterCountInputElement.getName(), "" + (MAX_PAYLOAD - message.length()));
        params.add(letterCountParam);
        form.addDefaultParametersTo(params);
        Reader r = form.submitForm(params, form.getNetscapeRequestProperties());
        String result = getStringFromReader(r);
        String pattern = "<meta http-equiv = \"refresh\" content=\"1; url=";
        int patternIndex = result.indexOf(pattern);
        if (patternIndex < 0) return false;
        int end = result.lastIndexOf("\">");
        if (end < 0) return false;
        String url = result.substring(patternIndex + pattern.length(), end);
        result = getStringFromReader(new InputStreamReader(new URL(url).openStream()));
        return result.indexOf("wurde erfolgreich verschickt") >= 0;
    }
@Digester(forField = "password")
    public static String encriptPassword(String passwd) {
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(passwd.getBytes());
            BigInteger hash = new BigInteger(1, md.digest());
            return hash.toString(16);
        } catch (Exception e) {
            return null;
        }
    }
public static void unzip(File zipInFile, File outputDir) throws Exception {
        Enumeration<? extends ZipEntry> entries;
        ZipFile zipFile = new ZipFile(zipInFile);
        ZipInputStream zipInputStream = new ZipInputStream(new FileInputStream(zipInFile));
        ZipEntry entry = (ZipEntry) zipInputStream.getNextEntry();
        File curOutDir = outputDir;
        while (entry != null) {
            if (entry.isDirectory()) {
                curOutDir = new File(curOutDir, entry.getName());
                curOutDir.mkdirs();
                continue;
            }
            File outFile = new File(curOutDir, entry.getName());
            File tempDir = outFile.getParentFile();
            if (!tempDir.exists()) tempDir.mkdirs();
            outFile.createNewFile();
            BufferedOutputStream outstream = new BufferedOutputStream(new FileOutputStream(outFile));
            int n;
            byte[] buf = new byte[1024];
            while ((n = zipInputStream.read(buf, 0, 1024)) > -1) outstream.write(buf, 0, n);
            outstream.flush();
            outstream.close();
            zipInputStream.closeEntry();
            entry = zipInputStream.getNextEntry();
        }
        zipInputStream.close();
        zipFile.close();
    }
public static String download(String address, String outputFolder) {
        URL url = null;
        String fileName = "";
        try {
            url = new URL(address);
            System.err.println("Indirizzo valido!");
        } catch (MalformedURLException ex) {
            System.err.println("Indirizzo non valido!");
        }
        try {
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            connection.setRequestProperty("Range", "bytes=0-");
            connection.connect();
            int contentLength = connection.getContentLength();
            if (contentLength < 1) {
                System.err.println("Errore, c'e' qualcosa che non va!");
                return "";
            }
            fileName = url.getFile();
            fileName = fileName.substring(url.getFile().lastIndexOf('/') + 1);
            RandomAccessFile file = new RandomAccessFile(outputFolder + fileName, "rw");
            file.seek(0);
            InputStream stream = connection.getInputStream();
            byte[] buffer = new byte[1024];
            while (true) {
                int read = stream.read(buffer);
                if (read == -1) {
                    break;
                }
                file.write(buffer, 0, read);
            }
            file.close();
        } catch (IOException ioe) {
            System.err.println("I/O error!");
        }
        return outputFolder + fileName;
    }
public static long getFileSize(String address) {
        URL url = null;
        try {
            url = new URL(address);
            System.err.println("Indirizzo valido - " + url.toString().substring(0, 10) + "...");
        } catch (MalformedURLException ex) {
            System.err.println("Indirizzo non valido!");
        }
        try {
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            connection.setRequestProperty("Range", "bytes=0-");
            connection.connect();
            return connection.getContentLength();
        } catch (IOException ioe) {
            System.err.println("I/O error!");
            return 0;
        }
    }
public EVECalcControllerImpl(EVECalcView gui) {
        this.view = gui;
        properties = new Properties();
        try {
            InputStream resStream;
            resStream = getClass().getResourceAsStream(REGION_PROPERTIES);
            if (resStream == null) {
                System.out.println("Loading for needed Properties files failed.");
                URL url = new URL(REGIONS_URL);
                try {
                    resStream = url.openStream();
                    properties.load(resStream);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            } else {
                properties.load(resStream);
            }
        } catch (IOException e) {
        }
    }
private void createTree(DefaultMutableTreeNode top) throws MalformedURLException, ParserConfigurationException, SAXException, IOException {
        InputStream stream;
        URL url = new URL(SHIPS_URL + view.getBaseurl());
        try {
            stream = url.openStream();
        } catch (Exception e) {
            stream = getClass().getResourceAsStream("ships.xml");
        }
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder parser = factory.newDocumentBuilder();
        Document doc = parser.parse(stream);
        NodeList races = doc.getElementsByTagName("race");
        for (int i = 0; i < races.getLength(); i++) {
            Element race = (Element) races.item(i);
            top.add(buildRaceTree(race));
        }
        top.setUserObject("Ships");
        view.getShipTree().repaint();
        view.getShipTree().expandRow(0);
    }
public static InputStream getResourceAsStream(String resourceName) {
        try {
            URL url = getEmbeddedFileUrl(WS_SEP + resourceName);
            if (url != null) {
                return url.openStream();
            }
        } catch (MalformedURLException e) {
            GdtAndroidPlugin.getLogger().logError(e, "Failed to read stream '%s'", resourceName);
        } catch (IOException e) {
            GdtAndroidPlugin.getLogger().logError(e, "Failed to read stream '%s'", resourceName);
        }
        return null;
    }
@Override
    public int updateStatus(UserInfo userInfo, String status) throws Exception {
        OAuthConsumer consumer = SnsConstant.getOAuthConsumer(SnsConstant.SOHU);
        consumer.setTokenWithSecret(userInfo.getAccessToken(), userInfo.getAccessSecret());
        try {
            URL url = new URL(SnsConstant.SOHU_UPDATE_STATUS_URL);
            HttpURLConnection request = (HttpURLConnection) url.openConnection();
            request.setDoOutput(true);
            request.setRequestMethod("POST");
            HttpParameters para = new HttpParameters();
            para.put("status", StringUtils.utf8Encode(status).replaceAll("\\+", "%20"));
            consumer.setAdditionalParameters(para);
            consumer.sign(request);
            OutputStream ot = request.getOutputStream();
            ot.write(("status=" + URLEncoder.encode(status, "utf-8")).replaceAll("\\+", "%20").getBytes());
            ot.flush();
            ot.close();
            System.out.println("Sending request...");
            request.connect();
            System.out.println("Response: " + request.getResponseCode() + " " + request.getResponseMessage());
            BufferedReader reader = new BufferedReader(new InputStreamReader(request.getInputStream()));
            String b = null;
            while ((b = reader.readLine()) != null) {
                System.out.println(b);
            }
            return SnsConstant.SOHU_UPDATE_STATUS_SUCC_WHAT;
        } catch (Exception e) {
            SnsConstant.SOHU_OPERATOR_FAIL_REASON = processException(e.getMessage());
            return SnsConstant.SOHU_UPDATE_STATUS_FAIL_WHAT;
        }
    }
@Override
    public int updateStatus(UserInfo userInfo, String status, String picturePath) {
        HttpClient client = new DefaultHttpClient();
        HttpPost post = new HttpPost(SnsConstant.SOHU_UPDATE_STATUS_URL);
        List<NameValuePair> parameters = new ArrayList<NameValuePair>();
        parameters.add(new BasicNameValuePair("parameter1", "parameterValue1"));
        parameters.add(new BasicNameValuePair("parameter2", "parameterValue2"));
        try {
            post.setEntity(new UrlEncodedFormEntity(parameters));
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        try {
            HttpResponse response = client.execute(post);
        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return 0;
    }
public void save(File selectedFile) throws IOException {
        if (storeEntriesInFiles) {
            boolean moved = false;
            for (int i = 0; i < tempFiles.size(); i++) {
                File newFile = new File(selectedFile.getAbsolutePath() + "_" + Integer.toString(i) + ".zettmp");
                moved = tempFiles.get(i).renameTo(newFile);
                if (!moved) {
                    BufferedReader read = new BufferedReader(new FileReader(tempFiles.get(i)));
                    PrintWriter write = new PrintWriter(newFile);
                    String s;
                    while ((s = read.readLine()) != null) write.print(s);
                    read.close();
                    write.flush();
                    write.close();
                    tempFiles.get(i).delete();
                }
                tempFiles.set(i, newFile);
            }
        }
        GZIPOutputStream output = new GZIPOutputStream(new BufferedOutputStream(new FileOutputStream(selectedFile)));
        XStream xml_convert = new XStream();
        xml_convert.setMode(XStream.ID_REFERENCES);
        xml_convert.toXML(this, output);
        output.flush();
        output.close();
    }
public static String md5(final String text) throws NoSuchAlgorithmException, UnsupportedEncodingException {
        MessageDigest md = MessageDigest.getInstance("MD5");
        byte[] md5hash = new byte[FOUR_BYTES];
        md.update(text.getBytes("iso-8859-1"), 0, text.length());
        md5hash = md.digest();
        return convertToHex(md5hash);
    }
static byte[] getSystemEntropy() {
        byte[] ba;
        final MessageDigest md;
        try {
            md = MessageDigest.getInstance("SHA");
        } catch (NoSuchAlgorithmException nsae) {
            throw new InternalError("internal error: SHA-1 not available.");
        }
        byte b = (byte) System.currentTimeMillis();
        md.update(b);
        java.security.AccessController.doPrivileged(new java.security.PrivilegedAction() {

            public Object run() {
                try {
                    String s;
                    Properties p = System.getProperties();
                    Enumeration e = p.propertyNames();
                    while (e.hasMoreElements()) {
                        s = (String) e.nextElement();
                        md.update(s.getBytes());
                        md.update(p.getProperty(s).getBytes());
                    }
                    md.update(InetAddress.getLocalHost().toString().getBytes());
                    File f = new File(p.getProperty("java.io.tmpdir"));
                    String[] sa = f.list();
                    for (int i = 0; i < sa.length; i++) md.update(sa[i].getBytes());
                } catch (Exception ex) {
                    md.update((byte) ex.hashCode());
                }
                Runtime rt = Runtime.getRuntime();
                byte[] memBytes = longToByteArray(rt.totalMemory());
                md.update(memBytes, 0, memBytes.length);
                memBytes = longToByteArray(rt.freeMemory());
                md.update(memBytes, 0, memBytes.length);
                return null;
            }
        });
        return md.digest();
    }
private static void serveHTML() throws Exception {
        Bus bus = BusFactory.getDefaultBus();
        DestinationFactoryManager dfm = bus.getExtension(DestinationFactoryManager.class);
        DestinationFactory df = dfm.getDestinationFactory("http://cxf.apache.org/transports/http/configuration");
        EndpointInfo ei = new EndpointInfo();
        ei.setAddress("http://localhost:8080/test.html");
        Destination d = df.getDestination(ei);
        d.setMessageObserver(new MessageObserver() {

            public void onMessage(Message message) {
                try {
                    ExchangeImpl ex = new ExchangeImpl();
                    ex.setInMessage(message);
                    Conduit backChannel = message.getDestination().getBackChannel(message, null, null);
                    MessageImpl res = new MessageImpl();
                    res.put(Message.CONTENT_TYPE, "text/html");
                    backChannel.prepare(res);
                    OutputStream out = res.getContent(OutputStream.class);
                    FileInputStream is = new FileInputStream("test.html");
                    IOUtils.copy(is, out, 2048);
                    out.flush();
                    out.close();
                    is.close();
                    backChannel.close(res);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }
public void onMessage(Message message) {
                try {
                    ExchangeImpl ex = new ExchangeImpl();
                    ex.setInMessage(message);
                    Conduit backChannel = message.getDestination().getBackChannel(message, null, null);
                    MessageImpl res = new MessageImpl();
                    res.put(Message.CONTENT_TYPE, "text/html");
                    backChannel.prepare(res);
                    OutputStream out = res.getContent(OutputStream.class);
                    FileInputStream is = new FileInputStream("test.html");
                    IOUtils.copy(is, out, 2048);
                    out.flush();
                    out.close();
                    is.close();
                    backChannel.close(res);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
public String readRemoteFile() throws IOException {
        String response = "";
        boolean eof = false;
        URL url = new URL(StaticData.remoteFile);
        InputStream is = url.openStream();
        BufferedReader br = new BufferedReader(new InputStreamReader(is));
        String s;
        s = br.readLine();
        response = s;
        while (!eof) {
            try {
                s = br.readLine();
                if (s == null) {
                    eof = true;
                    br.close();
                } else response += s;
            } catch (EOFException eo) {
                eof = true;
            } catch (IOException e) {
                System.out.println("IO Error : " + e.getMessage());
            }
        }
        return response;
    }
public void copy(String pathFileIn, String pathFileOut) {
        try {
            File inputFile = new File(pathFileIn);
            File outputFile = new File(pathFileOut);
            FileReader in = new FileReader(inputFile);
            File outDir = new File(DirOut);
            if (!outDir.exists()) outDir.mkdirs();
            FileWriter out = new FileWriter(outputFile);
            int c;
            while ((c = in.read()) != -1) out.write(c);
            in.close();
            out.close();
            this.printColumn(inputFile.getName(), outputFile.getPath());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
private void getRandomGUID(boolean secure) {
        MessageDigest md5 = null;
        StringBuffer sbValueBeforeMD5 = new StringBuffer(128);
        try {
            md5 = MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException 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(32);
            for (int j = 0; j < array.length; ++j) {
                int b = array[j] & TWO_BYTES;
                if (b < PAD_BELOW) sb.append('0');
                sb.append(Integer.toHexString(b));
            }
            valueAfterMD5 = sb.toString();
        } catch (Exception e) {
        }
    }
public void setUp() {
        try {
            String excelFile = "result" + java.io.File.separator + "input" + java.io.File.separator + "conextech.xls";
            java.io.File f1 = new java.io.File(excelFile);
            URL url = new URL("file:test/result/input/checksun.xls");
            InputStream is = url.openStream();
            workbook = Workbook.getWorkbook(is);
        } catch (MalformedURLException urlEx) {
            urlEx.printStackTrace();
            fail();
        } catch (IOException ioEx) {
            ioEx.printStackTrace();
            fail();
        } catch (BiffException biffEx) {
            biffEx.printStackTrace();
            fail();
        }
    }
public void removeJarFiles() throws IOException {
        HashSet<GridNode> nodes = (HashSet) batchTask.returnNodeCollection();
        Iterator<GridNode> ic = nodes.iterator();
        InetAddress addLocal = InetAddress.getLocalHost();
        String hostnameLocal = addLocal.getHostName();
        while (ic.hasNext()) {
            GridNode node = ic.next();
            String address = node.getPhysicalAddress();
            InetAddress addr = InetAddress.getByName(address);
            byte[] rawAddr = addr.getAddress();
            Map<String, String> attributes = node.getAttributes();
            InetAddress hostname = InetAddress.getByAddress(rawAddr);
            if (hostname.getHostName().equals(hostnameLocal)) continue;
            String gridPath = attributes.get("GRIDGAIN_HOME");
            FTPClient ftp = new FTPClient();
            try {
                String[] usernamePass = inputNodes.get(hostname.getHostName());
                ftp.connect(hostname);
                ftp.login(usernamePass[0], usernamePass[1]);
                int reply = ftp.getReplyCode();
                if (!FTPReply.isPositiveCompletion(reply)) {
                    ftp.disconnect();
                    System.err.println("FTP server refused connection.");
                    continue;
                }
                ftp.login(usernamePass[0], usernamePass[1]);
                String directory = gridPath + "/libs/ext/";
                ftp.changeWorkingDirectory(directory);
                FTPFile[] fs = ftp.listFiles();
                for (FTPFile f : fs) {
                    if (f.isDirectory()) continue;
                    System.out.println(f.getName());
                    ftp.deleteFile(f.getName());
                }
                ftp.sendCommand("rm *");
                ftp.logout();
                ftp.disconnect();
            } catch (Exception e) {
                MessageCenter.getMessageCenter(BatchMainSetup.class).error("Problems with the FTP connection." + "A file has not been succesfully transfered", e);
                e.printStackTrace();
            }
        }
    }
public void transferOutputFiles() throws IOException {
        HashSet<GridNode> nodes = (HashSet) batchTask.returnNodeCollection();
        Iterator<GridNode> ic = nodes.iterator();
        InetAddress addLocal = InetAddress.getLocalHost();
        String hostnameLocal = addLocal.getHostName();
        while (ic.hasNext()) {
            GridNode node = ic.next();
            String address = node.getPhysicalAddress();
            InetAddress addr = InetAddress.getByName(address);
            byte[] rawAddr = addr.getAddress();
            Map<String, String> attributes = node.getAttributes();
            InetAddress hostname = InetAddress.getByAddress(rawAddr);
            if (hostname.getHostName().equals(hostnameLocal)) continue;
            String[] usernamePass = inputNodes.get(hostname.getHostName());
            String gridPath = attributes.get("GRIDGAIN_HOME");
            FTPClient ftp = new FTPClient();
            ftp.connect(hostname);
            ftp.login(usernamePass[0], usernamePass[1]);
            int reply = ftp.getReplyCode();
            if (!FTPReply.isPositiveCompletion(reply)) {
                ftp.disconnect();
                System.err.println("FTP server refused connection.");
                continue;
            }
            ftp.changeWorkingDirectory(gridPath + "/bin");
            ftp.setFileType(FTPClient.COMPRESSED_TRANSFER_MODE);
            ftp.setRemoteVerificationEnabled(false);
            ftp.setFileType(FTPClient.ASCII_FILE_TYPE);
            FTPFile[] fs = ftp.listFiles();
            for (FTPFile f : fs) {
                if (f.isDirectory()) continue;
                String fileName = f.getName();
                if (!fileName.endsWith(".txt")) continue;
                System.out.println(f.getName());
                FileOutputStream out = new FileOutputStream("../repast.simphony.distributedBatch/" + "remoteOutput/" + f.getName());
                try {
                    ftp.retrieveFile(fileName, out);
                } catch (Exception e) {
                    continue;
                } finally {
                    if (out != null) out.close();
                }
            }
            ftp.logout();
            ftp.disconnect();
        }
    }