semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public void register(MinecraftSession session, String username, String verificationKey) {
        if (Configuration.getConfiguration().isVerifyingNames()) {
            long salt = HeartbeatManager.getHeartbeatManager().getSalt();
            String hash = new StringBuilder().append(String.valueOf(salt)).append(username).toString();
            MessageDigest digest;
            try {
                digest = MessageDigest.getInstance("MD5");
            } catch (NoSuchAlgorithmException e) {
                throw new RuntimeException("No MD5 algorithm!");
            }
            digest.update(hash.getBytes());
            if (!verificationKey.equals(new BigInteger(1, digest.digest()).toString(16))) {
                session.getActionSender().sendLoginFailure("Illegal name.");
                return;
            }
        }
        char[] nameChars = username.toCharArray();
        for (char nameChar : nameChars) {
            if (nameChar < ' ' || nameChar > '\177') {
                session.getActionSender().sendLoginFailure("Invalid name!");
                return;
            }
        }
        for (Player p : playerList.getPlayers()) {
            if (p.getName().equalsIgnoreCase(username)) {
                p.getSession().getActionSender().sendLoginFailure("Logged in from another computer.");
                break;
            }
        }
        final Player player = new Player(session, username);
        if (!playerList.add(player)) {
            player.getSession().getActionSender().sendLoginFailure("Too many players online!");
            return;
        }
        session.setPlayer(player);
        final Configuration c = Configuration.getConfiguration();
        session.getActionSender().sendLoginResponse(Constants.PROTOCOL_VERSION, c.getName(), c.getMessage(), false);
        LevelGzipper.getLevelGzipper().gzipLevel(session);
    }
public static void zipDirectory(String dir, String zipfile) throws IOException, IllegalArgumentException {
        File d = new File(dir);
        if (!d.isDirectory()) throw new IllegalArgumentException("Not a directory:  " + dir);
        String[] entries = d.list();
        byte[] buffer = new byte[4096];
        int bytesRead;
        ZipOutputStream out = new ZipOutputStream(new FileOutputStream(zipfile));
        for (int i = 0; i < entries.length; i++) {
            File f = new File(d, entries[i]);
            if (f.isDirectory()) continue;
            FileInputStream in = new FileInputStream(f);
            ZipEntry entry = new ZipEntry(f.getPath());
            out.putNextEntry(entry);
            while ((bytesRead = in.read(buffer)) != -1) out.write(buffer, 0, bytesRead);
            in.close();
        }
        out.close();
    }
private RemoteObject createRemoteObject(final VideoEntry videoEntry, final RemoteContainer container) throws RemoteException {
        MessageDigest instance;
        try {
            instance = MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException e) {
            throw new RemoteException(StatusCreator.newStatus("Error creating MD5", e));
        }
        StringWriter sw = new StringWriter();
        YouTubeMediaGroup mediaGroup = videoEntry.getMediaGroup();
        if (mediaGroup != null) {
            if (mediaGroup.getDescription() != null) {
                sw.append(mediaGroup.getDescription().getPlainTextContent());
            }
            List<MediaCategory> keywordsGroup = mediaGroup.getCategories();
            StringBuilder sb = new StringBuilder();
            if (keywordsGroup != null) {
                for (MediaCategory mediaCategory : keywordsGroup) {
                    sb.append(mediaCategory.getContent());
                }
            }
        }
        instance.update(sw.toString().getBytes());
        RemoteObject remoteVideo = InfomngmntFactory.eINSTANCE.createRemoteObject();
        remoteVideo.setHash(asHex(instance.digest()));
        remoteVideo.setId(SiteInspector.getId(videoEntry.getHtmlLink().getHref()));
        remoteVideo.setName(videoEntry.getTitle().getPlainText());
        remoteVideo.setRepositoryTypeObjectId(KEY_VIDEO);
        remoteVideo.setWrappedObject(videoEntry);
        setInternalUrl(remoteVideo, container);
        return remoteVideo;
    }
public static boolean copyTextFile(File src, File dst) {
        try {
            BufferedInputStream bis = new BufferedInputStream(new FileInputStream(src));
            BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(dst));
            byte[] buf = new byte[1024];
            int readsize = 0;
            while ((readsize = bis.read(buf)) != -1) {
                bos.write(buf, 0, readsize);
            }
            bos.flush();
            bos.close();
            bis.close();
        } catch (IOException e) {
            ServerConsoleServlet.printSystemLog(e.toString() + " " + e.getMessage(), ServerConsoleServlet.LOG_ERROR);
            return false;
        }
        return true;
    }
public void openJadFile(URL url) {
        try {
            setStatusBar("Loading...");
            jad.clear();
            jad.load(url.openStream());
            loadFromJad(url);
        } catch (FileNotFoundException ex) {
            System.err.println("Cannot found " + url.getPath());
        } catch (NullPointerException ex) {
            ex.printStackTrace();
            System.err.println("Cannot open jad " + url.getPath());
        } catch (IllegalArgumentException ex) {
            ex.printStackTrace();
            System.err.println("Cannot open jad " + url.getPath());
        } catch (IOException ex) {
            ex.printStackTrace();
            System.err.println("Cannot open jad " + url.getPath());
        }
    }
public static String fromHtml(URL url, String defaultEncoding, boolean overrideEncoding) throws IOException, BadDocumentException {
        URLConnection conn = url.openConnection();
        String contentType = conn.getContentType();
        String encoding = conn.getContentEncoding();
        if (encoding == null) {
            int i = contentType.indexOf("charset");
            if (i >= 0) {
                String s = contentType.substring(i);
                i = s.indexOf('=');
                if (i >= 0) {
                    s = contentType.substring(i + 1).trim();
                    encoding = s.replace("\'", "").replace("\"", "").trim();
                    if (encoding.equals("")) {
                        encoding = defaultEncoding;
                    }
                }
            } else {
                encoding = defaultEncoding;
            }
        }
        String expected = "text/html";
        if (contentType == null) {
            DefaultXMLNoteErrorHandler.warning(null, 90190, "Returned content type for url.openConnection() is null");
            contentType = expected;
        }
        int index = contentType.indexOf(';');
        if (index >= 0) {
            contentType = contentType.substring(0, index).trim();
        }
        if (!contentType.equals(expected)) {
            String msg = translator.translate("The content type of url '%s' is not '%s', it is '%s'");
            throw new BadDocumentException(String.format(msg, url.toString(), expected, contentType));
        }
        BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream(), encoding));
        return fromHtml(in, encoding);
    }
private MapProperties readProperties(URL url) {
        @SuppressWarnings("unchecked") MapProperties properties = new MapProperties(new LinkedHashMap());
        InputStream is = null;
        try {
            is = url.openStream();
            properties.load(is);
        } catch (IOException ex) {
            throw new RuntimeException(ex);
        } finally {
            StreamUtils.close(is);
        }
        return properties;
    }
private String processFileUploadOperation(boolean isH264File) {
        String fileType = this.uploadFileFileName.substring(this.uploadFileFileName.lastIndexOf('.'));
        int uniqueHashCode = UUID.randomUUID().toString().hashCode();
        if (uniqueHashCode < 0) {
            uniqueHashCode *= -1;
        }
        String randomFileName = uniqueHashCode + fileType;
        String fileName = (isH264File) ? getproperty("videoDraftPath") : getproperty("videoDraftPathForNonH264") + randomFileName;
        File targetVideoPath = new File(fileName + randomFileName);
        System.out.println("Path: " + targetVideoPath.getAbsolutePath());
        try {
            targetVideoPath.createNewFile();
            FileChannel outStreamChannel = new FileOutputStream(targetVideoPath).getChannel();
            FileChannel inStreamChannel = new FileInputStream(this.uploadFile).getChannel();
            inStreamChannel.transferTo(0, inStreamChannel.size(), outStreamChannel);
            outStreamChannel.close();
            inStreamChannel.close();
            return randomFileName;
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
protected URL[][] getImageLinks(final URL url) {
        Lexer lexer;
        URL[][] ret;
        if (null != url) {
            try {
                lexer = new Lexer(url.openConnection());
                ret = extractImageLinks(lexer, url);
            } catch (Throwable t) {
                System.out.println(t.getMessage());
                ret = NONE;
            }
        } else ret = NONE;
        return (ret);
    }
@Test
    public void testLoadSource() throws IOException {
        ArticleMetadata metadata = new ArticleMetadata();
        metadata.setId("http://arxiv.org/abs/math/0205003v1");
        InputStream inputStream = arxivDAOFacade.loadSource(metadata);
        Assert.assertNotNull(inputStream);
        StringWriter writer = new StringWriter();
        IOUtils.copy(inputStream, writer, "utf8");
        String contents = writer.toString();
        Assert.assertTrue(contents.contains("A strengthening of the Nyman"));
        inputStream.close();
    }
@Override
    protected void initializeGraphicalViewer() {
        super.initializeGraphicalViewer();
        getGraphicalViewer().setEditPartFactory(fact);
        ITypeRoot tr = sourceEditor.getInputElement();
        try {
            getGraphicalViewer().setContents(tr);
            ((DesignTimeComponent) fact.getTopPart().getModelChildren().get(0)).addListener(new DesignTimeListener() {

                public void handleUpdate(DesignTimeComponent comp) {
                    updateSourceWithComponent(comp.getTopLevel());
                }
            });
        } catch (Throwable e) {
            e.printStackTrace();
        }
        getGraphicalViewer().addSelectionChangedListener(new ISelectionChangedListener() {

            public void selectionChanged(SelectionChangedEvent arg0) {
                if (getSelectedComponent() == null) {
                    return;
                }
                PropertySheetPage propertySheet = ((PropertySheetPage) getAdapter(IPropertySheetPage.class));
                propertySheet.selectionChanged(getSite().getPart(), new StructuredSelection(getSelectedComponent()));
                try {
                } catch (Throwable e) {
                    e.printStackTrace();
                }
            }
        });
        getGraphicalViewer().setContextMenu(contextMenu);
        contextMenu.addMenuListener(this);
    }
public static String generateToken(ClientInfo clientInfo) {
        try {
            MessageDigest md5 = MessageDigest.getInstance("MD5");
            Random rand = new Random();
            String random = clientInfo.getIpAddress() + ":" + clientInfo.getPort() + ":" + rand.nextInt();
            md5.update(random.getBytes());
            String token = toHexString(md5.digest((new Date()).toString().getBytes()));
            clientInfo.setToken(token);
            return token;
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return null;
    }
private ByteArrayInputStream fetchUrl(String urlString, Exception[] outException) {
        URL url;
        try {
            url = new URL(urlString);
            InputStream is = null;
            int inc = 65536;
            int curr = 0;
            byte[] result = new byte[inc];
            try {
                is = url.openStream();
                int n;
                while ((n = is.read(result, curr, result.length - curr)) != -1) {
                    curr += n;
                    if (curr == result.length) {
                        byte[] temp = new byte[curr + inc];
                        System.arraycopy(result, 0, temp, 0, curr);
                        result = temp;
                    }
                }
                return new ByteArrayInputStream(result, 0, curr);
            } finally {
                if (is != null) {
                    try {
                        is.close();
                    } catch (IOException e) {
                    }
                }
            }
        } catch (Exception e) {
            outException[0] = e;
        }
        return null;
    }
@SuppressWarnings("unchecked")
    private List<String> getWordList() {
        IConfiguration config = Configurator.getDefaultConfigurator().getConfig(CONFIG_ID);
        List<String> wList = (List<String>) config.getObject("word_list");
        if (wList == null) {
            wList = new ArrayList<String>();
            InputStream resrc = null;
            try {
                resrc = new URL(list_url).openStream();
            } catch (Exception e) {
                e.printStackTrace();
            }
            if (resrc != null) {
                BufferedReader br = new BufferedReader(new InputStreamReader(resrc));
                String line;
                try {
                    while ((line = br.readLine()) != null) {
                        line = line.trim();
                        if (line.length() != 0) {
                            wList.add(line);
                        }
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                } finally {
                    if (br != null) {
                        try {
                            br.close();
                        } catch (IOException e) {
                        }
                    }
                }
            }
        }
        return wList;
    }
public InputStream getResource(FCValue name) throws FCException {
        Element el = _factory.getElementWithID(name.getAsString());
        if (el == null) {
            throw new FCException("Could not find resource \"" + name + "\"");
        }
        String urlString = el.getTextTrim();
        if (!urlString.startsWith("http")) {
            try {
                log.debug("Get resource: " + urlString);
                URL url;
                if (urlString.startsWith("file:")) {
                    url = new URL(urlString);
                } else {
                    url = getClass().getResource(urlString);
                }
                return url.openStream();
            } catch (Exception e) {
                throw new FCException("Failed to load resource.", e);
            }
        } else {
            try {
                FCService http = getRuntime().getServiceFor(FCService.HTTP_DOWNLOAD);
                return http.perform(new FCValue[] { name }).getAsInputStream();
            } catch (Exception e) {
                throw new FCException("Failed to load resource.", e);
            }
        }
    }
public static void copyFile(File source, File destination) throws IOException {
        destination.getParentFile().mkdirs();
        BufferedInputStream in = new BufferedInputStream(new FileInputStream(source));
        BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(destination));
        byte[] buffer = new byte[4096];
        int read = -1;
        while ((read = in.read(buffer)) != -1) {
            out.write(buffer, 0, read);
        }
        out.flush();
        out.close();
        in.close();
    }
public boolean downloadFTP(String ipFTP, String loginFTP, String senhaFTP, String diretorioFTP, String diretorioAndroid, String arquivoFTP) throws SocketException, IOException {
        boolean retorno = false;
        FileOutputStream arqReceber = null;
        try {
            ftp.connect(ipFTP);
            Log.i("DownloadFTP", "Connected: " + ipFTP);
            ftp.login(loginFTP, senhaFTP);
            Log.i("DownloadFTP", "Logged on");
            ftp.enterLocalPassiveMode();
            ftp.setFileType(FTPClient.BINARY_FILE_TYPE);
            arqReceber = new FileOutputStream(file.toString());
            ftp.retrieveFile("/tablet_ftp/Novo/socialAlimenta.xml", arqReceber);
            retorno = true;
            ftp.disconnect();
            Log.i("DownloadFTP", "retorno:" + retorno);
        } catch (Exception e) {
            ftp.disconnect();
            Log.e("DownloadFTP", "Erro:" + e.getMessage());
        } finally {
            Log.e("DownloadFTP", "Finally");
        }
        return retorno;
    }
public boolean uploadFTP(String ipFTP, String loginFTP, String senhaFTP, String diretorioFTP, String diretorioAndroid, String arquivoFTP) {
        try {
            dialogHandler.sendEmptyMessage(0);
            File file = new File(diretorioAndroid);
            File file2 = new File(diretorioAndroid + arquivoFTP);
            Log.v("uploadFTP", "Atribuidas as vari�veis");
            String status = "";
            if (file.isDirectory()) {
                Log.v("uploadFTP", "� diret�rio");
                if (file.list().length > 0) {
                    Log.v("uploadFTP", "file.list().length > 0");
                    ftp.connect(ipFTP);
                    ftp.login(loginFTP, senhaFTP);
                    ftp.enterLocalPassiveMode();
                    ftp.setFileTransferMode(FTPClient.ASCII_FILE_TYPE);
                    ftp.setFileType(FTPClient.ASCII_FILE_TYPE);
                    ftp.changeWorkingDirectory(diretorioFTP);
                    FileInputStream arqEnviar = new FileInputStream(diretorioAndroid + arquivoFTP);
                    Log.v("uploadFTP", "FileInputStream declarado");
                    if (ftp.storeFile(arquivoFTP, arqEnviar)) {
                        Log.v("uploadFTP", "ftp.storeFile(arquivoFTP, arqEnviar)");
                        status = ftp.getStatus().toString();
                        Log.v("uploadFTP", "getStatus(): " + status);
                        if (file2.delete()) {
                            Log.i("uploadFTP", "Arquivo " + arquivoFTP + " exclu�do com sucesso");
                            retorno = true;
                        } else {
                            Log.e("uploadFTP", "Erro ao excluir o arquivo " + arquivoFTP);
                            retorno = false;
                        }
                    } else {
                        Log.e("uploadFTP", "ERRO: arquivo " + arquivoFTP + "n�o foi enviado!");
                        retorno = false;
                    }
                } else {
                    Log.e("uploadFTP", "N�o existe o arquivo " + arquivoFTP + "neste diret�rio!");
                    retorno = false;
                }
            } else {
                Log.e("uploadFTP", "N�o � diret�rio");
                retorno = false;
            }
            if (ftp.isConnected()) {
                Log.v("uploadFTP", "isConnected ");
                ftp.abort();
                status = ftp.getStatus().toString();
                Log.v("uploadFTP", "quit " + retorno);
            }
            return retorno;
        } catch (IOException e) {
            Log.e("uploadFTP", "ERRO FTP: " + e);
            retorno = false;
            return retorno;
        } finally {
            handler.sendEmptyMessage(0);
            Log.v("uploadFTP", "finally executado");
        }
    }
public static String sha1(String input) throws Exception {
        MessageDigest md = MessageDigest.getInstance("SHA-1");
        byte[] sha1hash = new byte[40];
        md.update(input.getBytes("UTF-8"), 0, input.length());
        sha1hash = md.digest();
        return convertToHex(sha1hash);
    }
private void uploadConfiguration(URL url, IUser iUser) throws IOException, ContributionServiceException {
        StringBuilder sb = new StringBuilder();
        BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream(), "UTF-8"));
        String line;
        while ((line = reader.readLine()) != null) {
            sb.append(line).append(System.getProperty("line.separator"));
        }
        SYSTEM_SETTINGS_SVC.setElementMetadata(sb.toString(), iUser);
        GetSystemScriptServlet.resetScript();
    }
public static File getClassLoaderFile(String filename) throws IOException {
        Resource resource = new ClassPathResource(filename);
        try {
            return resource.getFile();
        } catch (IOException e) {
        }
        InputStream is = null;
        FileOutputStream os = null;
        try {
            String tempFilename = RandomStringUtils.randomAlphanumeric(20);
            File file = File.createTempFile(tempFilename, null);
            is = resource.getInputStream();
            os = new FileOutputStream(file);
            IOUtils.copy(is, os);
            return file;
        } finally {
            IOUtils.closeQuietly(is);
            IOUtils.closeQuietly(os);
        }
    }