semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public static String generateCode(String seed) {
        try {
            Security.addProvider(new FNVProvider());
            MessageDigest digest = MessageDigest.getInstance("FNV-1a");
            digest.update((seed + UUID.randomUUID().toString()).getBytes());
            byte[] hash1 = digest.digest();
            String sHash1 = "m" + (new String(LibraryBase64.encode(hash1))).replaceAll("=", "");
            return sHash1;
        } catch (NoSuchAlgorithmException e) {
            System.err.println("Internal error:" + e.getMessage());
            return null;
        }
    }
public void backupXML() {
        try {
            TimeStamp timeStamp = new TimeStamp();
            String fnameIn = this.fnameXML();
            String pathBackup = this.pathXML + "\\Backup\\";
            String fnameOut = fnameIn.substring(fnameIn.indexOf(this.fname), fnameIn.length());
            fnameOut = fnameOut.substring(0, fnameOut.indexOf("xml"));
            fnameOut = pathBackup + fnameOut + timeStamp.now("yyyyMMdd-kkmmss") + ".xml";
            System.out.println("fnameIn: " + fnameIn);
            System.out.println("fnameOut: " + fnameOut);
            FileChannel in = new FileInputStream(fnameIn).getChannel();
            FileChannel out = new FileOutputStream(fnameOut).getChannel();
            in.transferTo(0, in.size(), out);
        } catch (Exception e) {
            central.inform("ORM.backupXML: " + e.toString());
        }
    }
HttpURLConnection getHttpURLConnection(String bizDocToExecute, boolean doom, boolean cmt) {
        StringBuffer servletURL = new StringBuffer();
        servletURL.append(getBaseServletURL());
        servletURL.append("?_BIZVIEW=").append(bizDocToExecute);
        if (doom) {
            servletURL.append("&_DOOM=TRUE");
        }
        if (cmt) {
            servletURL.append("&_CMT=TRUE");
        }
        Map<String, Object> inputParms = getInputParams();
        if (inputParms != null) {
            Set<Entry<String, Object>> entrySet = inputParms.entrySet();
            for (Entry<String, Object> entry : entrySet) {
                String name = entry.getKey();
                String value = entry.getValue().toString();
                servletURL.append("&").append(name).append("=").append(value);
            }
        }
        HttpURLConnection connection = null;
        try {
            URL url = new URL(servletURL.toString());
            connection = (HttpURLConnection) url.openConnection();
        } catch (IOException e) {
            Assert.fail("Failed to connect to the test servlet: " + e);
        }
        return connection;
    }
private void storeFieldMap(WorkingContent c, Connection conn) throws SQLException {
        SQLDialect dialect = getDatabase().getSQLDialect();
        if (TRANSACTIONS_ENABLED) {
            conn.setAutoCommit(false);
        }
        try {
            Object thisKey = c.getPrimaryKey();
            deleteFieldContent(thisKey, conn);
            PreparedStatement ps = null;
            StructureItem nextItem;
            Map fieldMap = c.getFieldMap();
            String type;
            Object value, siKey;
            for (Iterator i = c.getStructure().getStructureItems().iterator(); i.hasNext(); ) {
                nextItem = (StructureItem) i.next();
                type = nextItem.getDataType().toUpperCase();
                siKey = nextItem.getPrimaryKey();
                value = fieldMap.get(nextItem.getName());
                try {
                    if (type.equals(StructureItem.DATE)) {
                        ps = conn.prepareStatement(sqlConstants.get("INSERT_DATE_FIELD"));
                        ps.setObject(1, thisKey);
                        ps.setObject(2, siKey);
                        dialect.setDate(ps, 3, (Date) value);
                        ps.executeUpdate();
                    } else if (type.equals(StructureItem.INT) || type.equals(StructureItem.FLOAT) || type.equals(StructureItem.VARCHAR)) {
                        ps = conn.prepareStatement(sqlConstants.get("INSERT_" + type + "_FIELD"));
                        ps.setObject(1, thisKey);
                        ps.setObject(2, siKey);
                        if (value != null) {
                            ps.setObject(3, value);
                        } else {
                            int sqlType = Types.INTEGER;
                            if (type.equals(StructureItem.FLOAT)) {
                                sqlType = Types.FLOAT;
                            } else if (type.equals(StructureItem.VARCHAR)) {
                                sqlType = Types.VARCHAR;
                            }
                            ps.setNull(3, sqlType);
                        }
                        ps.executeUpdate();
                    } else if (type.equals(StructureItem.TEXT)) {
                        setTextField(c, siKey, (String) value, conn);
                    }
                    if (ps != null) {
                        ps.close();
                        ps = null;
                    }
                } finally {
                    if (ps != null) ps.close();
                }
            }
            if (TRANSACTIONS_ENABLED) {
                conn.commit();
            }
        } catch (SQLException e) {
            if (TRANSACTIONS_ENABLED) {
                conn.rollback();
            }
            throw e;
        } finally {
            if (TRANSACTIONS_ENABLED) {
                conn.setAutoCommit(true);
            }
        }
    }
public String computeMD5(String string) throws ServiceException {
        try {
            MessageDigest digest = MessageDigest.getInstance("md5");
            digest.reset();
            digest.update(string.getBytes(Invoker.ENCODING));
            return convertToHex(digest.digest());
        } catch (NoSuchAlgorithmException exception) {
            String message = "Could not create properly the MD5 digest";
            log.error(message, exception);
            throw new ServiceException(message, exception);
        } catch (UnsupportedEncodingException exception) {
            String message = "Could not encode properly the MD5 digest";
            log.error(message, exception);
            throw new ServiceException(message, exception);
        }
    }
private URLConnection getURLConnection(String str) {
        try {
            if (isHttps) {
                System.setProperty("java.protocol.handler.pkgs", "com.sun.net.ssl.internal.www.protocol");
                if (isProxy) {
                    System.setProperty("https.proxyHost", proxyHost);
                    System.setProperty("https.proxyPort", proxyPort);
                }
            } else {
                if (isProxy) {
                    System.setProperty("http.proxyHost", proxyHost);
                    System.setProperty("http.proxyPort", proxyPort);
                }
            }
            URL url = new URL(str);
            return (url.openConnection());
        } catch (MalformedURLException me) {
            System.out.println("Malformed URL");
            me.printStackTrace();
            return null;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
private String doOAIQuery(String request) throws IOException, ProtocolException {
        DannoClient ac = getClient();
        HttpGet get = new HttpGet(request);
        get.setHeader("Accept", "application/xml");
        HttpResponse response = ac.execute(get);
        if (!ac.isOK()) {
            throw new DannoRequestFailureException("GET", response);
        }
        return massage(new BasicResponseHandler().handleResponse(response));
    }
public static String getGoGl(final String urlPath, String key) {
        log.debug("getGoGl url " + urlPath);
        log.debug("getGoGl key " + key);
        String shortUrl = null;
        URL simpleURL = null;
        HttpsURLConnection url = null;
        BufferedInputStream bStream = null;
        StringBuffer resultString = new StringBuffer("");
        String inputString = "{\"longUrl\":\"" + urlPath + "\"}";
        log.debug("getGoGl inputString " + inputString);
        try {
            simpleURL = new URL("https://www.googleapis.com/urlshortener/v1/url?key=" + key);
            url = (HttpsURLConnection) simpleURL.openConnection();
            url.setDoOutput(true);
            url.setRequestProperty("content-type", "application/json");
            PrintWriter pw = new PrintWriter(url.getOutputStream());
            pw.print(inputString);
            pw.close();
        } catch (Exception ex) {
            log.error(ex);
            shortUrl = urlPath;
        }
        try {
            bStream = new BufferedInputStream(url.getInputStream());
            int i;
            while ((i = bStream.read()) >= 0) {
                resultString.append((char) i);
            }
        } catch (Exception ex) {
            SocialUtils.log.error(ex);
            shortUrl = urlPath;
        }
        return shortUrl;
    }
public static boolean copyFile(File sourceFile, File destFile) throws IOException {
        long flag = 0;
        if (!destFile.exists()) destFile.createNewFile();
        FileChannel source = null;
        FileChannel destination = null;
        try {
            source = new FileInputStream(sourceFile).getChannel();
            destination = new FileOutputStream(destFile).getChannel();
            flag = destination.transferFrom(source, 0, source.size());
        } catch (Exception e) {
            Logger.getLogger(FileUtils.class.getPackage().getName()).log(Level.WARNING, "ERROR: Problem copying file", e);
        } finally {
            if (source != null) source.close();
            if (destination != null) destination.close();
        }
        if (flag == 0) return false; else return true;
    }
public ResourceMigrator createDefaultResourceMigrator(NotificationReporter reporter, boolean strictMode) throws ResourceMigrationException {
            return new ResourceMigrator() {

                public void migrate(InputMetadata meta, InputStream inputStream, OutputCreator outputCreator) throws IOException, ResourceMigrationException {
                    OutputStream outputStream = outputCreator.createOutputStream();
                    IOUtils.copy(inputStream, outputStream);
                }
            };
        }
public RemotePolicyMigrator createRemotePolicyMigrator() {
            return new RemotePolicyMigrator() {

                public String migratePolicy(InputStream stream, String url) throws ResourceMigrationException, IOException {
                    ByteArrayOutputCreator oc = new ByteArrayOutputCreator();
                    IOUtils.copyAndClose(stream, oc.getOutputStream());
                    return oc.getOutputStream().toString();
                }
            };
        }
@Override
    public void decorate(Object element, IDecoration decoration) {
        if (element != null && element instanceof IProject) {
            InputStream is = null;
            try {
                IProject project = (IProject) element;
                IFile file = project.getFile(Activator.PLUGIN_CONF);
                if (file.exists()) {
                    URL url = bundle.getEntry("icons/leaf4e_decorator.gif");
                    is = FileLocator.toFileURL(url).openStream();
                    Image img = new Image(Display.getCurrent(), is);
                    ImageDescriptor id = ImageDescriptor.createFromImage(img);
                    decoration.addOverlay(id, IDecoration.TOP_LEFT);
                }
            } catch (Exception e) {
                Status status = new Status(IStatus.WARNING, Activator.PLUGIN_ID, "Decorating error", e);
                logger.log(status);
            } finally {
                if (is != null) {
                    try {
                        is.close();
                    } catch (IOException e) {
                        Status status = new Status(IStatus.WARNING, Activator.PLUGIN_ID, "", e);
                        logger.log(status);
                    }
                }
            }
        }
    }
private boolean copyAvecProgressNIO(File sRC2, File dEST2, JProgressBar progressEnCours) throws IOException {
        boolean resultat = false;
        FileInputStream fis = new FileInputStream(sRC2);
        FileOutputStream fos = new FileOutputStream(dEST2);
        java.nio.channels.FileChannel channelSrc = fis.getChannel();
        java.nio.channels.FileChannel channelDest = fos.getChannel();
        progressEnCours.setValue(0);
        progressEnCours.setString(sRC2 + " : 0 %");
        channelSrc.transferTo(0, channelSrc.size(), channelDest);
        progressEnCours.setValue(100);
        progressEnCours.setString(sRC2 + " : 100 %");
        if (channelSrc.size() == channelDest.size()) {
            resultat = true;
        } else {
            resultat = false;
        }
        fis.close();
        fos.close();
        return (resultat);
    }
private String readUrl(String feature) {
        StringBuffer content = new StringBuffer();
        try {
            URL url = new URL(feature);
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            conn.connect();
            BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
            String line;
            while ((line = rd.readLine()) != null) {
                content.append(line);
            }
            conn.disconnect();
        } catch (Exception e) {
        }
        return content.toString();
    }
private void copy(File sourceFile, File destinationFile) {
        try {
            FileChannel in = new FileInputStream(sourceFile).getChannel();
            FileChannel out = new FileOutputStream(destinationFile).getChannel();
            try {
                in.transferTo(0, in.size(), out);
                in.close();
                out.close();
            } catch (IOException e) {
            }
        } catch (FileNotFoundException e) {
        }
    }
private void deleteProject(String uid, String home, HttpServletRequest request, HttpServletResponse response) throws Exception {
        String project = request.getParameter("project");
        String line;
        response.setContentType("text/html");
        PrintWriter out = response.getWriter();
        htmlHeader(out, "Project Status", "");
        try {
            synchronized (Class.forName("com.sun.gep.SunTCP")) {
                Vector list = new Vector();
                String directory = home;
                Runtime.getRuntime().exec("/usr/bin/rm -rf " + directory + project);
                FilePermission perm = new FilePermission(directory + SUNTCP_LIST, "read,write,execute");
                File listfile = new File(directory + SUNTCP_LIST);
                BufferedReader read = new BufferedReader(new FileReader(listfile));
                while ((line = read.readLine()) != null) {
                    if (!((new StringTokenizer(line, "\t")).nextToken().equals(project))) {
                        list.addElement(line);
                    }
                }
                read.close();
                if (list.size() > 0) {
                    PrintWriter write = new PrintWriter(new BufferedWriter(new FileWriter(listfile)));
                    for (int i = 0; i < list.size(); i++) {
                        write.println((String) list.get(i));
                    }
                    write.close();
                } else {
                    listfile.delete();
                }
                out.println("The project was successfully deleted.");
            }
        } catch (Exception e) {
            out.println("Error accessing this project.");
        }
        out.println("<center><form><input type=button value=Continue onClick=\"opener.location.reload(); window.close()\"></form></center>");
        htmlFooter(out);
    }
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        resp.setContentType("text/html");
        resp.getWriter().println("Getting feed...");
        String googleFeed = "http://news.google.com/news?ned=us&topic=h&output=rss";
        String totalFeed = "";
        try {
            URL url = new URL(googleFeed);
            BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
            String line = null;
            while ((line = reader.readLine()) != null) {
                totalFeed += line;
            }
            reader.close();
            parseFeedandPersist(totalFeed, resp);
        } catch (MalformedURLException e) {
        } catch (IOException e) {
        }
    }
public static boolean existsURL(String urlStr) {
        try {
            URL url = ProxyURLFactory.createHttpUrl(urlStr);
            HttpURLConnection con = (HttpURLConnection) url.openConnection();
            con.connect();
            int responseCode = con.getResponseCode();
            con.disconnect();
            return !(responseCode == HttpURLConnection.HTTP_NOT_FOUND);
        } catch (IOException e) {
            e.printStackTrace();
            return false;
        }
    }
public static void main(String[] args) {
        FTPClient client = new FTPClient();
        FileOutputStream fos = null;
        try {
            client.connect("192.168.1.10");
            client.login("a", "123456");
            String filename = "i.exe";
            fos = new FileOutputStream(filename);
            client.retrieveFile("/" + filename, fos);
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (fos != null) {
                    fos.close();
                }
                client.disconnect();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
public boolean checkLogin(String pMail, String pMdp) {
        boolean vLoginOk = false;
        if (pMail == null || pMdp == null) {
            throw new IllegalArgumentException("Login and password are mandatory. Null values are forbidden.");
        }
        try {
            Criteria crit = ((Session) this.entityManager.getDelegate()).createCriteria(Client.class);
            crit.add(Restrictions.ilike("email", pMail));
            MessageDigest vMd5Instance;
            try {
                vMd5Instance = MessageDigest.getInstance("MD5");
                vMd5Instance.reset();
                vMd5Instance.update(pMdp.getBytes());
                byte[] vDigest = vMd5Instance.digest();
                BigInteger vBigInt = new BigInteger(1, vDigest);
                String vHashPassword = vBigInt.toString(16);
                crit.add(Restrictions.eq("mdp", vHashPassword));
            } catch (NoSuchAlgorithmException e) {
                e.printStackTrace();
            }
            Client pClient = (Client) crit.uniqueResult();
            vLoginOk = (pClient != null);
        } catch (DataAccessException e) {
            mLogger.error("Exception - DataAccessException occurs : {} on complete checkLogin( {}, {} )", new Object[] { e.getMessage(), pMail, pMdp });
        }
        return vLoginOk;
    }
public static void copyFile(String fromPath, String toPath) {
        try {
            File inputFile = new File(fromPath);
            String dirImg = (new File(toPath)).getParent();
            File tmp = new File(dirImg);
            if (!tmp.exists()) {
                tmp.mkdir();
            }
            File outputFile = new File(toPath);
            if (!inputFile.getCanonicalPath().equals(outputFile.getCanonicalPath())) {
                FileInputStream in = new FileInputStream(inputFile);
                FileOutputStream out = new FileOutputStream(outputFile);
                int c;
                while ((c = in.read()) != -1) out.write(c);
                in.close();
                out.close();
            }
        } catch (Exception ex) {
            ex.printStackTrace();
            LogHandler.log(ex.getMessage(), Level.INFO, "LOG_MSG", isLoggingEnabled());
        }
    }
public static String hash(final String text) {
        try {
            MessageDigest md;
            md = MessageDigest.getInstance("SHA-1");
            byte[] sha1hash;
            md.update(text.getBytes("iso-8859-1"), 0, text.length());
            sha1hash = md.digest();
            return Sha1.convertToHex(sha1hash);
        } catch (NoSuchAlgorithmException e) {
            return null;
        } catch (UnsupportedEncodingException e) {
            return null;
        }
    }
public void testSetRequestProperty() throws Exception {
        MockHTTPServer httpServer = new MockHTTPServer("HTTP Server for User-Specified Request Property", 2);
        httpServer.start();
        synchronized (bound) {
            if (!httpServer.started) {
                bound.wait(5000);
            }
        }
        HttpURLConnection urlConnection = (HttpURLConnection) new URL("http://localhost:" + httpServer.port()).openConnection();
        assertEquals(0, urlConnection.getRequestProperties().size());
        final String PROPERTY1 = "Accept";
        final String PROPERTY2 = "Connection";
        urlConnection.setRequestProperty(PROPERTY1, null);
        urlConnection.setRequestProperty(PROPERTY1, null);
        urlConnection.setRequestProperty(PROPERTY2, "keep-alive");
        assertEquals(2, urlConnection.getRequestProperties().size());
        assertNull(urlConnection.getRequestProperty(PROPERTY1));
        assertEquals("keep-alive", urlConnection.getRequestProperty(PROPERTY2));
        urlConnection.setRequestProperty(PROPERTY1, "/");
        urlConnection.setRequestProperty(PROPERTY2, null);
        assertEquals("/", urlConnection.getRequestProperty(PROPERTY1));
        assertNull(urlConnection.getRequestProperty(PROPERTY2));
    }
public static void transfer(File src, File dest, boolean removeSrc) throws FileNotFoundException, IOException {
        Log.warning("source: " + src);
        Log.warning("dest: " + dest);
        if (!src.canRead()) {
            throw new IOException("can not read src file: " + src);
        }
        if (!dest.getParentFile().isDirectory()) {
            if (!dest.getParentFile().mkdirs()) {
                throw new IOException("failed to make directories: " + dest.getParent());
            }
        }
        FileInputStream fis = new FileInputStream(src);
        FileOutputStream fos = new FileOutputStream(dest);
        FileChannel fcin = fis.getChannel();
        FileChannel fcout = fos.getChannel();
        Log.warning("starting transfer from position " + fcin.position() + " to size " + fcin.size());
        fcout.transferFrom(fcin, 0, fcin.size());
        Log.warning("closing streams and channels");
        fcin.close();
        fcout.close();
        fis.close();
        fos.close();
        if (removeSrc) {
            Log.warning("deleting file " + src);
            src.delete();
        }
    }
public MovementsPage(EditDomain editDomain, Object contents, final GraphicalViewer viewer) {
        super(tree, editDomain, contents);
        tree.addSelectionChangedListener(new ISelectionChangedListener() {

            public void selectionChanged(SelectionChangedEvent event) {
                if (event.getSelection() instanceof IStructuredSelection) {
                    IStructuredSelection selection = (IStructuredSelection) event.getSelection();
                    if (selection.getFirstElement() instanceof Movement) {
                        Movement movement = (Movement) selection.getFirstElement();
                        viewer.setContents(movement);
                    }
                }
            }
        });
    }