semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
private String getAuthCookie(boolean invalidate) {
        if (resources.getBoolean(R.bool.dev)) {
            return "dev_appserver_login=get_view@localhost.devel:false:18580476422013912411";
        } else {
            try {
                Account[] accounts = accountsManager.getAccountsByType("com.google");
                Account account = null;
                while (!(accounts.length > 0)) {
                    accountsManager.addAccount("com.google", "ah", null, null, act, null, null).getResult();
                    accounts = accountsManager.getAccountsByType("com.google");
                }
                if (account == null) {
                    account = accounts[0];
                }
                String authToken = accountsManager.getAuthToken(account, "ah", null, act, null, null).getResult().get(AccountManager.KEY_AUTHTOKEN).toString();
                if (invalidate || authToken == null) {
                    Logger.getLogger(JSBridge.class.getName()).log(Level.INFO, "Invalidating auth token.");
                    accountsManager.invalidateAuthToken("com.google", authToken);
                    return getAuthCookie(false);
                }
                HttpGet httpget = new HttpGet("http://" + resources.getString(R.string.host) + "/_ah/login?auth=" + authToken);
                HttpResponse response = httpclient.execute(httpget);
                for (Header c : response.getHeaders("Set-Cookie")) {
                    if (c.getValue().startsWith("ACSID=")) {
                        return c.getValue();
                    }
                }
                return getAuthCookie(false);
            } catch (ClientProtocolException e) {
                Logger.getLogger(JSBridge.class.getName()).log(Level.SEVERE, "HTTP protocol violated.", e);
            } catch (OperationCanceledException e) {
                Logger.getLogger(JSBridge.class.getName()).log(Level.WARNING, "Login canceled.", e);
            } catch (AuthenticatorException e) {
                Logger.getLogger(JSBridge.class.getName()).log(Level.WARNING, "Authentication failed.", e);
            } catch (IOException e) {
                Logger.getLogger(JSBridge.class.getName()).log(Level.SEVERE, "Login failed.", e);
            }
            return getAuthCookie(true);
        }
    }
public static void copyFileNIO(File in, File out) throws IOException {
        FileInputStream fis = null;
        FileOutputStream fos = null;
        try {
            fis = new FileInputStream(in);
            fos = new FileOutputStream(out);
            FileChannel sourceChannel = fis.getChannel();
            FileChannel targetChannel = fos.getChannel();
            sourceChannel.transferTo(0, sourceChannel.size(), targetChannel);
            sourceChannel.close();
            targetChannel.close();
        } catch (IOException e) {
            throw e;
        } finally {
            try {
                if (fos != null) {
                    fos.close();
                }
            } catch (Exception e) {
                e.printStackTrace(System.out);
            }
            try {
                if (fis != null) {
                    fis.close();
                }
            } catch (Exception e) {
                e.printStackTrace(System.out);
            }
        }
    }
public static boolean unzip_and_merge(String infile, String outfile) {
        try {
            BufferedOutputStream dest = null;
            FileInputStream fis = new FileInputStream(infile);
            ZipInputStream zis = new ZipInputStream(new BufferedInputStream(fis));
            FileOutputStream fos = new FileOutputStream(outfile);
            dest = new BufferedOutputStream(fos, BUFFER);
            while (zis.getNextEntry() != null) {
                int count;
                byte data[] = new byte[BUFFER];
                while ((count = zis.read(data, 0, BUFFER)) != -1) dest.write(data, 0, count);
                dest.flush();
            }
            dest.close();
            zis.close();
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
        return true;
    }
public static synchronized String toMD5(String str) {
        Nulls.failIfNull(str, "Cannot create an MD5 encryption form a NULL string");
        String hashword = null;
        try {
            MessageDigest md5 = MessageDigest.getInstance(MD5);
            md5.update(str.getBytes());
            BigInteger hash = new BigInteger(1, md5.digest());
            hashword = hash.toString(16);
            return Strings.padLeft(hashword, 32, "0");
        } catch (NoSuchAlgorithmException ex) {
            ex.printStackTrace();
        }
        return hashword;
    }
public static synchronized String toSHA1(String str) {
        Nulls.failIfNull(str, "Cannot create an SHA1 encryption form a NULL string");
        try {
            MessageDigest md;
            md = MessageDigest.getInstance(SHA1);
            byte[] sha1hash = new byte[40];
            md.update(str.getBytes(ISO_CHARSET), 0, str.length());
            sha1hash = md.digest();
            return convertToHex(sha1hash);
        } catch (NoSuchAlgorithmException ex) {
            ex.printStackTrace();
        } catch (UnsupportedEncodingException ex) {
            ex.printStackTrace();
        }
        return null;
    }
public void update() {
        if (url == null) {
            throw new IllegalArgumentException("URL cannot be null!");
        }
        try {
            URLConnection urlConnection = url.openConnection();
            urlConnection.setRequestProperty("User-Agent", Settings.INSTANCE.getUserAgent());
            SyndFeedInput input = new SyndFeedInput();
            SyndFeed syndFeed = input.build(new XmlReader(url));
            Channel channel = (Channel) syndFeed.createWireFeed(syndFeed.getFeedType());
            long lastModified = urlConnection.getLastModified();
            if (feed.getLastModified() != lastModified) {
                Server.print("Updating: " + feed.getName());
                feed.setLastModified(lastModified);
                ArrayList<String> cachedItems = getCachedItems();
                List<Item> items = channel.getItems();
                if (items.isEmpty()) {
                    return;
                }
                if (cachedItems.isEmpty()) {
                    Database.INSTANCE.addItems(feed, items);
                } else {
                    for (Item item : items) {
                        if (!cachedItems.contains(item.getTitle())) {
                            Database.INSTANCE.addItem(feed, item);
                        }
                    }
                }
                cacheItems(items);
                Settings.INSTANCE.persist();
                Server.print("Done updating: " + feed.getName());
            }
        } catch (ConnectException e) {
            Server.print("Could not connect to \"" + feed.getName() + "\"");
        } catch (SocketException e) {
            Server.print("Could not connect to \"" + feed.getName() + "\"");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
public String connect(String host, int port, String init) {
        HttpURLConnection c = null;
        String ret = "";
        int response;
        URL url = null;
        try {
            url = new URL("http://" + gwhost + ":" + gwport + "/connect?host=" + Utils.URLEncode(host.getBytes()) + "&port=" + Utils.URLEncode(("" + port).getBytes()) + "&passwd=" + Utils.URLEncode(gwpasswd.getBytes()) + "&data=" + Utils.URLEncode(stringToByteArray(init, encoding, utf8output)));
        } catch (MalformedURLException me) {
            ret += "Exception: " + me.getMessage();
        }
        try {
            c = (HttpURLConnection) url.openConnection();
            response = c.getResponseCode();
            identifier = c.getHeaderField("X-Identifier");
            if (c != null) c.disconnect();
        } catch (Exception e) {
            ret += "Error trying to connect to HTTP proxy server, aborting... ";
            ret += "Exception: " + e.getMessage();
            return ret;
        }
        if (response != HttpStatus.SC_OK) {
            ret += "Error trying to connect to IRC server, reason: ";
            switch(response) {
                case HttpStatus.SC_FORBIDDEN:
                    ret += "Wrong password";
                    break;
                case HttpStatus.SC_BAD_GATEWAY:
                    ret += "Bad gateway";
                    break;
                case HttpStatus.SC_NOT_FOUND:
                    ret += "IRC connection not found";
                    break;
                default:
                    ret += "HTTP response code: " + response;
                    break;
            }
            return ret;
        } else {
            connected = true;
            return null;
        }
    }
private String handleRequest(String url, boolean get) {
        HttpURLConnection c = null;
        InputStream is = null;
        ByteArrayInputStream bais;
        byte[] buf;
        String temp, ret = "";
        int response, len, i;
        try {
            c = (HttpURLConnection) new URL(url).openConnection();
            if (get) c.setRequestMethod("GET"); else c.setRequestMethod("HEAD");
            response = c.getResponseCode();
            if (get) {
                is = c.getInputStream();
                len = (int) c.getContentLength();
                if (len > 0) {
                    byte[] data = new byte[len];
                    for (i = 0; i < len; i++) {
                        data[i] = (byte) is.read();
                    }
                    bytein += data.length;
                    bais = new ByteArrayInputStream(data);
                    while (bais.available() > 0) {
                        buf = Utils.readLine(bais);
                        if (buf != null) {
                            temp = byteArrayToString(buf, encoding, utf8detect);
                            inqueue.addElement(temp);
                        }
                    }
                }
            }
            if (is != null) is.close();
            if (c != null) c.disconnect();
        } catch (Exception e) {
            ret += "Request failed, continuing...";
            return ret;
        }
        if (response != HttpStatus.SC_OK) {
            if (response != HttpStatus.SC_NOT_FOUND) {
                ret += "Error in connection to IRC server, aborting... ";
                ret += "Error: HTTP response code: " + response;
            }
            connected = false;
            return ret;
        } else return null;
    }
protected Context getResource3ServerInitialContext() throws Exception {
        if (resource3ServerJndiProps == null) {
            URL url = ClassLoader.getSystemResource("jndi.properties");
            resource3ServerJndiProps = new java.util.Properties();
            resource3ServerJndiProps.load(url.openStream());
            String jndiHost = System.getProperty("jbosstest.resource3.server.host", "localhost");
            String jndiUrl = "jnp://" + jndiHost + ":1099";
            resource3ServerJndiProps.setProperty("java.naming.provider.url", jndiUrl);
        }
        return new InitialContext(resource3ServerJndiProps);
    }
private byte[] scramble411(String password, String seed) {
        MessageDigest md;
        try {
            md = MessageDigest.getInstance("SHA-1");
            byte[] passwordHashStage1 = md.digest(password.getBytes());
            md.reset();
            byte[] passwordHashStage2 = md.digest(passwordHashStage1);
            md.reset();
            md.update(seed.getBytes());
            md.update(passwordHashStage2);
            byte[] toBeXord = md.digest();
            int numToXor = toBeXord.length;
            for (int i = 0; i < numToXor; i++) {
                toBeXord[i] = (byte) (toBeXord[i] ^ passwordHashStage1[i]);
            }
            return toBeXord;
        } catch (NoSuchAlgorithmException e) {
            if (logger.isLoggable(Level.SEVERE)) {
                logger.log(Level.SEVERE, e.getMessage(), e);
            }
        }
        return null;
    }
public HttpURLConnection getTileUrlConnection(int zoom, int tilex, int tiley) throws IOException {
        String url = getTileUrl(zoom, tilex, tiley);
        if (url == null) return null;
        return (HttpURLConnection) new URL(url).openConnection();
    }
public static byte[] getBytes(URL url) throws IOException {
        URLConnection connection = url.openConnection();
        InputStream in = connection.getInputStream();
        int contentLength = connection.getContentLength();
        ByteArrayOutputStream tmpOut;
        if (contentLength != -1) {
            tmpOut = new ByteArrayOutputStream(contentLength);
        } else {
            tmpOut = new ByteArrayOutputStream(16384);
        }
        byte[] buf = new byte[512];
        while (true) {
            int len = in.read(buf);
            if (len == -1) {
                break;
            }
            tmpOut.write(buf, 0, len);
        }
        in.close();
        tmpOut.close();
        byte[] array = tmpOut.toByteArray();
        return array;
    }
public static String md5(String string) {
        MessageDigest md = null;
        try {
            md = MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException exception) {
            LOGGER.warn(exception.getMessage());
        }
        byte[] md5hash = new byte[32];
        try {
            md.update(string.getBytes("iso-8859-1"), 0, string.length());
        } catch (UnsupportedEncodingException exception) {
            LOGGER.warn(exception.getMessage());
        }
        md5hash = md.digest();
        return convertToHex(md5hash);
    }
private PropertiesLoader(String masterFileLocation, String extraFileLocation) throws IOException {
        List propertiesList = new ArrayList();
        ClassLoader classLoader = this.getClass().getClassLoader();
        try {
            InputStream is = classLoader.getResourceAsStream(masterFileLocation);
            Properties p = new Properties();
            p.load(is);
            is.close();
            propertiesList.add(p);
        } catch (IOException ioex) {
            IOException ex = new IOException("could not load ROME master plugins file [" + masterFileLocation + "], " + ioex.getMessage());
            ex.setStackTrace(ioex.getStackTrace());
            throw ex;
        }
        Enumeration urls = classLoader.getResources(extraFileLocation);
        while (urls.hasMoreElements()) {
            URL url = (URL) urls.nextElement();
            Properties p = new Properties();
            try {
                InputStream is = url.openStream();
                p.load(is);
                is.close();
            } catch (IOException ioex) {
                IOException ex = new IOException("could not load ROME extensions plugins file [" + url.toString() + "], " + ioex.getMessage());
                ex.setStackTrace(ioex.getStackTrace());
                throw ex;
            }
            propertiesList.add(p);
        }
        _properties = new Properties[propertiesList.size()];
        propertiesList.toArray(_properties);
    }
public static String MD5(String text) throws Exception {
        MessageDigest md = MessageDigest.getInstance("MD5");
        md.update(text.getBytes());
        byte[] md5hash = md.digest();
        return convertToHex(md5hash);
    }
public static Document send(String address, Document request) throws MalformedURLException, IOException {
        if (logger.isDebugEnabled()) {
            logger.debug("Sending request to " + address);
            String requestString = XMLUtil.transformToString(request);
            logger.debug("Sending Request " + requestString);
        }
        URL url = new URL(address);
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setRequestProperty("Content-Type", "text/xml");
        connection.setDoOutput(true);
        connection.setDefaultUseCaches(false);
        connection.setRequestMethod("POST");
        connection.connect();
        OutputStream os = connection.getOutputStream();
        XMLUtil.transformToStream(request, os);
        os.flush();
        os.close();
        if (connection.getResponseCode() != connection.HTTP_OK) {
            logger.error("Was expecting HTTP_OK (200) but received response code: " + connection.getResponseCode());
            logger.error("Message: " + connection.getResponseMessage());
            throw new LibraryException(LibraryException.Code.REQUEST_FAILURE, connection.getResponseCode() + " - " + connection.getResponseMessage());
        }
        BufferedReader rd = new BufferedReader(new InputStreamReader(connection.getInputStream()));
        StringBuilder sb = new StringBuilder();
        String line;
        while ((line = rd.readLine()) != null) {
            sb.append(line);
        }
        rd.close();
        if (logger.isDebugEnabled()) {
            logger.debug("Received Response" + sb.toString());
        }
        try {
            return XMLUtil.parseString(sb.toString());
        } catch (SAXException ex) {
            logger.error("Error parsing XML Response", ex);
            throw new LibraryException(LibraryException.Code.INVALID_XML, ex);
        }
    }
public static URL getIconURLForUser(String id) {
        try {
            URL url = new URL("http://profiles.yahoo.com/" + id);
            BufferedReader r = new BufferedReader(new InputStreamReader(url.openStream()));
            String input = null;
            while ((input = r.readLine()) != null) {
                if (input.indexOf("<a href=\"") < 0) continue;
                if (input.indexOf("<img src=\"") < 0) continue;
                if (input.indexOf("<a href=\"") > input.indexOf("<img src=\"")) continue;
                String href = input.substring(input.indexOf("<a href=\"") + 9);
                String src = input.substring(input.indexOf("<img src=\"") + 10);
                if (href.indexOf("\"") < 0) continue;
                if (src.indexOf("\"") < 0) continue;
                href = href.substring(0, href.indexOf("\""));
                src = src.substring(0, src.indexOf("\""));
                if (href.equals(src)) {
                    return new URL(href);
                }
            }
        } catch (IOException e) {
        }
        URL toReturn = null;
        try {
            toReturn = new URL("http://us.i1.yimg.com/us.yimg.com/i/ppl/no_photo.gif");
        } catch (MalformedURLException e) {
            Debug.assrt(false);
        }
        return toReturn;
    }
public void delete(String name) throws FidoDatabaseException, CannotDeleteSystemLinkException, ClassLinkTypeNotFoundException {
        try {
            Connection conn = null;
            Statement stmt = null;
            try {
                conn = fido.util.FidoDataSource.getConnection();
                conn.setAutoCommit(false);
                stmt = conn.createStatement();
                if (isSystemLink(stmt, name) == true) throw new CannotDeleteSystemLinkException(name);
                AdjectivePrepositionTable prepTable = new AdjectivePrepositionTable();
                prepTable.deleteLinkType(stmt, name);
                ObjectLinkTable objectLinkTable = new ObjectLinkTable();
                objectLinkTable.deleteLinkType(stmt, name);
                String sql = "delete from ClassLinkTypes where LinkName = '" + name + "'";
                stmt.executeUpdate(sql);
                conn.commit();
            } catch (SQLException e) {
                if (conn != null) conn.rollback();
                throw e;
            } finally {
                if (stmt != null) stmt.close();
                if (conn != null) conn.close();
            }
        } catch (SQLException e) {
            throw new FidoDatabaseException(e);
        }
    }
public String plainStringToMD5(String input) {
        MessageDigest md = null;
        byte[] byteHash = null;
        StringBuffer resultString = new StringBuffer();
        try {
            md = MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException e) {
            logger.throwing(getClass().getName(), "plainStringToMD5", e);
        }
        md.reset();
        try {
            md.update(input.getBytes("UTF-8"));
        } catch (UnsupportedEncodingException e) {
        }
        byteHash = md.digest();
        for (int i = 0; i < byteHash.length; i++) {
            resultString.append(Integer.toHexString(0xF0 & byteHash[i]).charAt(0));
            resultString.append(Integer.toHexString(0x0F & byteHash[i]));
        }
        return (resultString.toString());
    }
public AudioInputStream getAudioInputStream(URL url, String userAgent) throws UnsupportedAudioFileException, IOException {
        if (TDebug.TraceAudioFileReader) {
            TDebug.out("MpegAudioFileReaderWorkaround.getAudioInputStream(URL,String): begin");
        }
        long lFileLengthInBytes = AudioSystem.NOT_SPECIFIED;
        URLConnection conn = url.openConnection();
        boolean isShout = false;
        int toRead = 4;
        byte[] head = new byte[toRead];
        if (userAgent != null) conn.setRequestProperty("User-Agent", userAgent);
        conn.setRequestProperty("Accept", "*/*");
        conn.setRequestProperty("Icy-Metadata", "1");
        conn.setRequestProperty("Connection", "close");
        BufferedInputStream bInputStream = new BufferedInputStream(conn.getInputStream());
        bInputStream.mark(toRead);
        int read = bInputStream.read(head, 0, toRead);
        if ((read > 2) && (((head[0] == 'I') | (head[0] == 'i')) && ((head[1] == 'C') | (head[1] == 'c')) && ((head[2] == 'Y') | (head[2] == 'y')))) {
            isShout = true;
        }
        bInputStream.reset();
        InputStream inputStream = null;
        if (isShout == true) {
            IcyInputStream icyStream = new IcyInputStream(bInputStream);
            icyStream.addTagParseListener(IcyListener.getInstance());
            inputStream = icyStream;
        } else {
            String metaint = conn.getHeaderField("icy-metaint");
            if (metaint != null) {
                IcyInputStream icyStream = new IcyInputStream(bInputStream, metaint);
                icyStream.addTagParseListener(IcyListener.getInstance());
                inputStream = icyStream;
            } else {
                inputStream = bInputStream;
            }
        }
        AudioInputStream audioInputStream = null;
        try {
            audioInputStream = getAudioInputStream(inputStream, lFileLengthInBytes);
        } catch (UnsupportedAudioFileException e) {
            inputStream.close();
            throw e;
        } catch (IOException e) {
            inputStream.close();
            throw e;
        }
        if (TDebug.TraceAudioFileReader) {
            TDebug.out("MpegAudioFileReaderWorkaround.getAudioInputStream(URL,String): end");
        }
        return audioInputStream;
    }