semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
private void sendToFtp(String outputText) {
        String uid = this.properties.get(PROPERTY_OUTPUT_FTP_USERNAME);
        String pwd = this.properties.get(PROPERTY_OUTPUT_FTP_PASSWORD);
        String address = this.properties.get(PROPERTY_OUTPUT_FTP_ADDRESS);
        int port = 21;
        try {
            port = Integer.valueOf(this.properties.get(PROPERTY_OUTPUT_FTP_PORT));
        } catch (Exception ex) {
            LOG.log(Level.WARNING, "Could not read FTP port from properties. Using port 21");
        }
        String location = this.properties.get(PROPERTY_OUTPUT_FTP_LOCATION);
        String filename = this.properties.get(PROPERTY_OUTPUT_FTP_FILENAME);
        LOG.log(Level.INFO, "Uploading text output to {0}:{1}/{2}/{3}", new Object[] { address, port, location, filename });
        FTPClient ftpClient = new FTPClient();
        try {
            ftpClient.connect(address, port);
            int reply = ftpClient.getReplyCode();
            if (!FTPReply.isPositiveCompletion(reply)) {
                ftpClient.disconnect();
                LOG.log(Level.SEVERE, "Could not connect to FTP server: {0}", reply);
                return;
            }
            if (!ftpClient.login(uid, pwd)) {
                LOG.log(Level.SEVERE, "Could not login to FTP server ({0}) with given credentials.", address);
                return;
            }
            ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
            ftpClient.enterLocalPassiveMode();
            if (ftpClient.storeFile(location + "/" + filename, new ByteArrayInputStream(outputText.getBytes()))) {
                LOG.log(Level.INFO, "Transfer complete");
            } else {
                LOG.log(Level.WARNING, "Transfer incomplete");
            }
        } catch (SocketException ex) {
            LOG.log(Level.SEVERE, "Could not transfer file.", ex.getMessage());
            LOG.log(Level.FINE, "", ex);
        } catch (IOException ex) {
            LOG.log(Level.SEVERE, "Could not transfer file.", ex.getMessage());
            LOG.log(Level.FINE, "", ex);
        }
        if (ftpClient.isConnected()) {
            try {
                ftpClient.disconnect();
            } catch (IOException ex) {
                LOG.log(Level.SEVERE, "Could not disconnect from FTP.", ex.getMessage());
                LOG.log(Level.FINE, "", ex);
            }
        }
    }
public static boolean copy(File source, File target, boolean owrite) {
        if (!source.exists()) {
            log.error("Invalid input to copy: source " + source + "doesn't exist");
            return false;
        } else if (!source.isFile()) {
            log.error("Invalid input to copy: source " + source + "isn't a file.");
            return false;
        } else if (target.exists() && !owrite) {
            log.error("Invalid input to copy: target " + target + " exists.");
            return false;
        }
        try {
            BufferedInputStream in = new BufferedInputStream(new FileInputStream(source));
            BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(target));
            byte buffer[] = new byte[1024];
            int read = -1;
            while ((read = in.read(buffer, 0, 1024)) != -1) out.write(buffer, 0, read);
            out.flush();
            out.close();
            in.close();
            return true;
        } catch (IOException e) {
            log.error("Copy failed: ", e);
            return false;
        }
    }
public synchronized String encrypt(String text) throws Exception {
        MessageDigest md = null;
        try {
            md = MessageDigest.getInstance("SHA-512");
        } catch (NoSuchAlgorithmException e) {
            throw new Exception(e.getMessage());
        }
        md.update(text.getBytes());
        byte raw[] = md.digest();
        String hash = "";
        for (int i = 0; i < raw.length; i++) {
            byte temp = raw[i];
            String s = Integer.toHexString(new Byte(temp));
            while (s.length() < 2) {
                s = "0" + s;
            }
            s = s.substring(s.length() - 2);
            hash += s;
        }
        return hash;
    }
public static void main(String[] args) throws IOException {
        PostParameter a1 = new PostParameter("v", Utils.encode("1.0"));
        PostParameter a2 = new PostParameter("api_key", Utils.encode(RenRenConstant.apiKey));
        PostParameter a3 = new PostParameter("method", Utils.encode("notifications.send"));
        PostParameter a4 = new PostParameter("call_id", System.nanoTime());
        PostParameter a5 = new PostParameter("session_key", Utils.encode("5.22af9ee9ad842c7eb52004ece6e96b10.86400.1298646000-350727914"));
        PostParameter a6 = new PostParameter("to_ids", Utils.encode("350727914"));
        PostParameter a7 = new PostParameter("notification", "又到了要睡觉的时间了。");
        PostParameter a8 = new PostParameter("format", Utils.encode("JSON"));
        RenRenPostParameters ps = new RenRenPostParameters(Utils.encode(RenRenConstant.secret));
        ps.addParameter(a1);
        ps.addParameter(a2);
        ps.addParameter(a3);
        ps.addParameter(a4);
        ps.addParameter(a5);
        ps.addParameter(a6);
        ps.addParameter(a7);
        ps.addParameter(a8);
        System.out.println(RenRenConstant.apiUrl + "?" + ps.generateUrl());
        URL url = new URL(RenRenConstant.apiUrl + "?" + ps.generateUrl());
        HttpURLConnection request = (HttpURLConnection) url.openConnection();
        request.setDoOutput(true);
        request.setRequestMethod("POST");
        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);
        }
    }
public static String checksum(URL url, String algorithm) {
        MessageDigest messageDigest;
        try {
            messageDigest = MessageDigest.getInstance(algorithm);
        } catch (Exception ex) {
            throw new RuntimeException("Could not create an instance of MessageDigest", ex);
        }
        byte[] bytes = new byte[4 * 1024];
        try {
            InputStream in = null;
            try {
                in = url.openStream();
                int nBytesRead = 0;
                while ((nBytesRead = in.read(bytes)) > 0) {
                    messageDigest.update(bytes, 0, nBytesRead);
                }
            } finally {
                if (in != null) {
                    in.close();
                }
            }
        } catch (Exception e) {
            throw new RuntimeException("Could not read message digest for: " + url.toExternalForm() + " using algorithm: " + algorithm);
        }
        byte[] checksumValue = messageDigest.digest();
        return digestAsString(checksumValue);
    }
public static String hashString(String pwd) {
        StringBuffer hex = new StringBuffer();
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(pwd.getBytes());
            byte[] d = md.digest();
            String plaintxt;
            for (int i = 0; i < d.length; i++) {
                plaintxt = Integer.toHexString(0xFF & d[i]);
                if (plaintxt.length() < 2) {
                    plaintxt = "0" + plaintxt;
                }
                hex.append(plaintxt);
            }
        } catch (NoSuchAlgorithmException nsae) {
        }
        return hex.toString();
    }
public void testDecode1000BinaryStore() throws Exception {
        EXISchema corpus = EXISchemaFactoryTestUtil.getEXISchema("/DataStore/DataStore.xsd", getClass(), m_compilerErrors);
        Assert.assertEquals(0, m_compilerErrors.getTotalCount());
        GrammarCache grammarCache = new GrammarCache(corpus, GrammarOptions.STRICT_OPTIONS);
        String[] base64Values100 = { "R0lGODdhWALCov////T09M7Ozqampn19fVZWVi0tLQUFBSxYAsJAA/8Iutz+MMpJq7046827/2Ao\n", "/9j/4BBKRklGAQEBASwBLP/hGlZFeGlmTU0qF5ZOSUtPTiBDT1JQT1JBVElPTk5J", "R0lGODlhHh73KSkpOTk5QkJCSkpKUlJSWlpaY2Nja2trc3Nze3t7hISEjIyMlJSUnJycpaWlra2t\n" + "tbW1vb29xsbGzs7O1tbW3t7e5+fn7+/v//////////8=", "/9j/4BBKRklGAQEBAf/bQwYEBQYFBAYGBQYHBwYIChAKCgkJChQODwwQFxQYGBc=", "R0lGODlhHh73M2aZzP8zMzNmM5kzzDP/M2YzZmZmmWbM", "/9j/4BBKRklGAQEBAf/bQwYEBQYFBAYGBQYHBwYIChAKCgkJChQODwwQFxQYGBcUFhYaHSUfGhsj\n" + "HBYWICwgIyYnKSopGR8tMC0oMCUoKSj/20M=", "R0lGODdhWAK+ov////j4+NTU1JOTk0tLSx8fHwkJCSxYAr5AA/8IMkzjrEEmahy23SpC", "R0lGODdh4QIpAncJIf4aU29mdHdhcmU6IE1pY3Jvc29mdCBPZmZpY2Us4QIpAof//////8z//5n/\n", "R0lGODdhWAK+ov////v7++fn58DAwI6Ojl5eXjExMQMDAyxYAr5AA/8Iutz+MMpJq7046827/2Ao\n" + "jmRpnmiqPsKxvg==", "R0lGODdh4QIpAncJIf4aU29mdHdhcmU6IE1pY3Jvc29mdCBPZmZpY2Us4QIpAob//////8z//5n/\nzP//zMw=" };
        AlignmentType alignment = AlignmentType.bitPacked;
        Transmogrifier encoder = new Transmogrifier();
        encoder.setEXISchema(grammarCache);
        encoder.setAlignmentType(alignment);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        encoder.setOutputStream(baos);
        URL url = resolveSystemIdAsURL("/DataStore/instance/1000BinaryStore.xml");
        encoder.encode(new InputSource(url.openStream()));
        byte[] bts = baos.toByteArray();
        Scanner scanner;
        int n_texts;
        EXIDecoder decoder = new EXIDecoder(999);
        decoder.setEXISchema(grammarCache);
        decoder.setAlignmentType(alignment);
        decoder.setInputStream(new ByteArrayInputStream(bts));
        scanner = decoder.processHeader();
        EXIEvent exiEvent;
        n_texts = 0;
        while ((exiEvent = scanner.nextEvent()) != null) {
            if (exiEvent.getEventVariety() == EXIEvent.EVENT_CH) {
                if (++n_texts % 100 == 0) {
                    String expected = base64Values100[(n_texts / 100) - 1];
                    String val = exiEvent.getCharacters().makeString();
                    Assert.assertEquals(expected, val);
                }
            }
        }
        Assert.assertEquals(1000, n_texts);
    }
public Ftp(Resource resource, String basePath) throws Exception {
        super(resource, basePath);
        client = new FTPClient();
        client.addProtocolCommandListener(new CommandLogger());
        client.connect(resource.getString("host"), Integer.parseInt(resource.getString("port")));
        client.login(resource.getString("user"), resource.getString("pw"));
        client.setFileType(FTPClient.BINARY_FILE_TYPE);
        client.enterLocalPassiveMode();
    }
public String get(String s) {
        s = s.replaceAll("[^a-z0-9_]", "");
        StringBuilder sb = new StringBuilder();
        try {
            String result = null;
            URL url = new URL("http://docs.google.com/Doc?id=" + URLEncoder.encode(s, "UTF-8"));
            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 = 0;
            while ((inputLine = in.readLine()) != null) {
                if (state == 0) {
                    int textPos = inputLine.indexOf("id=\"doc-contents");
                    if (textPos >= 0) {
                        state = 1;
                    }
                } else if (state == 1) {
                    int textPos = inputLine.indexOf("</div>");
                    if (textPos >= 0) break;
                    inputLine = inputLine.replaceAll("[\\u0000-\\u001F]", "");
                    sb.append(inputLine);
                }
            }
            in.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return sb.toString();
    }
public void create() {
        Connection conn = OrmHandler.getInstance().getSession().getConnection(this);
        Statement stat = null;
        StringBuilder sql = new StringBuilder(256);
        try {
            getRenderer().printCreateDatabase(this, sql);
            conn = createConnection();
            stat = conn.createStatement();
            stat.executeUpdate(sql.toString());
            conn.commit();
            if (LOGGER.isLoggable(Level.INFO)) {
                LOGGER.info(sql.toString());
            }
        } catch (Throwable e) {
            if (conn != null) {
                try {
                    conn.rollback();
                } catch (SQLException ex) {
                    LOGGER.log(Level.WARNING, "Can't rollback DB" + toString(), ex);
                }
            }
            throw new IllegalArgumentException("Statement error:\n" + sql, e);
        } finally {
            try {
                close(conn, stat, null, true);
            } catch (IllegalStateException ex) {
                LOGGER.log(Level.WARNING, "Can't rollback DB" + toString(), ex);
            }
        }
    }
public boolean renameTo(Folder f) throws MessagingException, StoreClosedException, NullPointerException {
        String[] aLabels = new String[] { "en", "es", "fr", "de", "it", "pt", "ca", "ja", "cn", "tw", "fi", "ru", "pl", "nl", "xx" };
        PreparedStatement oUpdt = null;
        if (!((DBStore) getStore()).isConnected()) throw new StoreClosedException(getStore(), "Store is not connected");
        if (oCatg.isNull(DB.gu_category)) throw new NullPointerException("Folder is closed");
        try {
            oUpdt = getConnection().prepareStatement("DELETE FROM " + DB.k_cat_labels + " WHERE " + DB.gu_category + "=?");
            oUpdt.setString(1, oCatg.getString(DB.gu_category));
            oUpdt.executeUpdate();
            oUpdt.close();
            oUpdt.getConnection().prepareStatement("INSERT INTO " + DB.k_cat_labels + " (" + DB.gu_category + "," + DB.id_language + "," + DB.tr_category + "," + DB.url_category + ") VALUES (?,?,?,NULL)");
            oUpdt.setString(1, oCatg.getString(DB.gu_category));
            for (int l = 0; l < aLabels.length; l++) {
                oUpdt.setString(2, aLabels[l]);
                oUpdt.setString(3, f.getName().substring(0, 1).toUpperCase() + f.getName().substring(1).toLowerCase());
                oUpdt.executeUpdate();
            }
            oUpdt.close();
            oUpdt = null;
            getConnection().commit();
        } catch (SQLException sqle) {
            try {
                if (null != oUpdt) oUpdt.close();
            } catch (SQLException ignore) {
            }
            try {
                getConnection().rollback();
            } catch (SQLException ignore) {
            }
            throw new MessagingException(sqle.getMessage(), sqle);
        }
        return true;
    }
private void openConnection() throws IOException {
        connection = (HttpURLConnection) url.openConnection();
        connection.setDoInput(true);
        connection.setDoOutput(true);
        connection.setRequestMethod("POST");
        connection.setRequestProperty("Content-Type", "text/xml");
    }
public static void downloadJars(IProject project, String repositoryUrl, String jarDirectory, String[] jars) {
        try {
            File tmpFile = null;
            for (String jar : jars) {
                try {
                    tmpFile = File.createTempFile("tmpPlugin_", ".zip");
                    URL url = new URL(repositoryUrl + jarDirectory + jar);
                    String destFilename = new File(url.getFile()).getName();
                    File destFile = new File(project.getLocation().append("lib").append(jarDirectory).toFile(), destFilename);
                    InputStream inputStream = null;
                    FileOutputStream outputStream = null;
                    try {
                        URLConnection urlConnection = url.openConnection();
                        inputStream = urlConnection.getInputStream();
                        outputStream = new FileOutputStream(tmpFile);
                        IOUtils.copy(inputStream, outputStream);
                    } finally {
                        if (outputStream != null) {
                            outputStream.close();
                        }
                        if (inputStream != null) {
                            inputStream.close();
                        }
                    }
                    FileUtils.copyFile(tmpFile, destFile);
                } finally {
                    if (tmpFile != null) {
                        tmpFile.delete();
                    }
                }
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
@Override
    public void setOntology1Document(URL url1) throws IllegalArgumentException {
        if (url1 == null) throw new IllegalArgumentException("Input parameter URL for ontology 1 is null.");
        try {
            ont1 = OWLManager.createOWLOntologyManager().loadOntologyFromOntologyDocument(url1.openStream());
        } catch (IOException e) {
            throw new IllegalArgumentException("Cannot open stream for ontology 1 from given URL.");
        } catch (OWLOntologyCreationException e) {
            throw new IllegalArgumentException("Cannot load ontology 1 from given URL.");
        }
    }
@Override
    public void setOntology2Document(URL url2) throws IllegalArgumentException {
        if (url2 == null) throw new IllegalArgumentException("Input parameter URL for ontology 2 is null.");
        try {
            ont2 = OWLManager.createOWLOntologyManager().loadOntologyFromOntologyDocument(url2.openStream());
        } catch (IOException e) {
            throw new IllegalArgumentException("Cannot open stream for ontology 2 from given URL.");
        } catch (OWLOntologyCreationException e) {
            throw new IllegalArgumentException("Cannot load ontology 2 from given URL.");
        }
    }
private void zip(File input, File output) {
        OutputStream os = null;
        InputStream is = null;
        try {
            os = new GZIPOutputStream(new FileOutputStream(output));
            is = new FileInputStream(input);
            byte[] buffer = new byte[8192];
            for (int length; (length = is.read(buffer)) != -1; ) os.write(buffer, 0, length);
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (is != null) {
                try {
                    is.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (os != null) {
                try {
                    os.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
public static final String md5(String name) {
        MessageDigest md;
        try {
            md = MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException(e.getMessage());
        }
        md.reset();
        md.update(name.getBytes());
        byte b[] = md.digest();
        String encoded = "";
        for (int i = 0; i < b.length; i++) {
            int b2 = (int) b[i] % 16;
            if (b2 < 0) b2 += 16;
            int b1 = (int) b[i];
            if (b1 < 0) b1 += 16 * 16;
            b1 -= b2;
            b1 /= 16;
            if (b1 <= 9) encoded += (char) ((int) '0' + (int) b1); else encoded += (char) ((int) 'a' + (int) b1 - (int) 10);
            if (b2 <= 9) encoded += (char) ((int) '0' + (int) b2); else encoded += (char) ((int) 'a' + (int) b2 - (int) 10);
        }
        return encoded;
    }
public ForDomainparReq(String urlstr, String domain) throws IOException {
        URL url = new URL(urlstr);
        URLConnection conn = url.openConnection();
        conn.setRequestProperty("domain", domain);
        try {
            BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF8"));
            StringBuffer response = new StringBuffer();
            String line = "";
            while ((line = reader.readLine()) != null) {
                response.append(line);
            }
            reader.close();
            jsonContectResult = response.toString();
        } catch (SocketTimeoutException e) {
            log.severe("SoketTimeout NO!! RC  try again !!" + e.getMessage());
            jsonContectResult = null;
        } catch (Exception e) {
            log.severe("Except Rescue Start !! RC try again!! " + e.getMessage());
            jsonContectResult = null;
        }
    }
private void copyOutResource(String dstPath, InputStream in) throws FileNotFoundException, IOException {
        FileOutputStream out = null;
        try {
            dstPath = this.outputDir + dstPath;
            File file = new File(dstPath);
            file.getParentFile().mkdirs();
            out = new FileOutputStream(file);
            IOUtils.copy(in, out);
        } finally {
            if (out != null) {
                out.close();
            }
        }
    }
protected String getRequestContent(String urlText, String method) throws Exception {
        URL url = new URL(urlText);
        HttpURLConnection urlcon = (HttpURLConnection) url.openConnection();
        urlcon.setRequestProperty("Referer", REFERER_STR);
        urlcon.setRequestMethod(method);
        urlcon.setUseCaches(false);
        urlcon.connect();
        BufferedReader reader = new BufferedReader(new InputStreamReader(urlcon.getInputStream()));
        String line = reader.readLine();
        reader.close();
        urlcon.disconnect();
        return line;
    }
@Override
        protected File doInBackground(String... params) {
            try {
                String urlString = params[0];
                final String fileName = params[1];
                if (!urlString.endsWith("/")) {
                    urlString += "/";
                }
                urlString += "apk/" + fileName;
                URL url = new URL(urlString);
                URLConnection connection = url.openConnection();
                connection.connect();
                File dir = new File(Environment.getExternalStorageDirectory(), "imogenemarket");
                dir.mkdirs();
                File file = new File(dir, fileName);
                if (file.exists()) {
                    file.delete();
                }
                file.createNewFile();
                InputStream input = new BufferedInputStream(url.openStream());
                OutputStream output = new FileOutputStream(file);
                byte data[] = new byte[1024];
                int count;
                int bigCount = 0;
                while ((count = input.read(data)) != -1) {
                    if (isCancelled()) {
                        break;
                    }
                    bigCount += count;
                    if (!mLocker.isLocked()) {
                        publishProgress(bigCount);
                        bigCount = 0;
                        mLocker.lock();
                    }
                    output.write(data, 0, count);
                }
                mLocker.cancel();
                publishProgress(bigCount);
                output.flush();
                output.close();
                input.close();
                if (isCancelled()) {
                    file.delete();
                    return null;
                }
                return file;
            } catch (Exception e) {
                e.printStackTrace();
            }
            return null;
        }