semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
void setURLString(String path, boolean forceLoad) {
        if (path != null) {
            if (this.url != null || inputStream != null) throw new IllegalArgumentException(Ding3dI18N.getString("MediaContainer5"));
            try {
                URL url = new URL(path);
                InputStream stream;
                stream = url.openStream();
                stream.close();
            } catch (Exception e) {
                throw new SoundException(javax.media.ding3d.Ding3dI18N.getString("MediaContainer0"));
            }
        }
        this.urlString = path;
        if (forceLoad) dispatchMessage();
    }
@Override
    protected String doIt() throws Exception {
        PreparedStatement insertStmt = null;
        try {
            insertStmt = DB.prepareStatement("INSERT INTO AD_Sequence_No(AD_SEQUENCE_ID, CALENDARYEAR, " + "AD_CLIENT_ID, AD_ORG_ID, ISACTIVE, CREATED, CREATEDBY, " + "UPDATED, UPDATEDBY, CURRENTNEXT) " + "(SELECT AD_Sequence_ID, '" + year + "', " + "AD_Client_ID, AD_Org_ID, IsActive, Created, CreatedBy, " + "Updated, UpdatedBy, StartNo " + "FROM AD_Sequence a " + "WHERE StartNewYear = 'Y' AND NOT EXISTS ( " + "SELECT AD_Sequence_ID " + "FROM AD_Sequence_No b " + "WHERE a.AD_Sequence_ID = b.AD_Sequence_ID " + "AND CalendarYear = ?)) ", get_TrxName());
            insertStmt.setString(1, year);
            insertStmt.executeUpdate();
            commit();
        } catch (Exception ex) {
            rollback();
            throw ex;
        } finally {
            DB.close(insertStmt);
        }
        return "Sequence No updated successfully";
    }
public void updateUser(User portalUserBean, AuthSession authSession) {
        DatabaseAdapter dbDyn = null;
        PreparedStatement ps = null;
        try {
            dbDyn = DatabaseAdapter.getInstance();
            String sql = "update WM_LIST_USER " + "set    FIRST_NAME=?,MIDDLE_NAME=?,LAST_NAME=?, " + "       ADDRESS=?,TELEPHONE=?,EMAIL=? " + "where  ID_USER=? and is_deleted=0 and  ID_FIRM in ";
            switch(dbDyn.getFamaly()) {
                case DatabaseManager.MYSQL_FAMALY:
                    String idList = authSession.getGrantedCompanyId();
                    sql += " (" + idList + ") ";
                    break;
                default:
                    sql += "(select z1.ID_FIRM from v$_read_list_firm z1 where z1.user_login = ?)";
                    break;
            }
            ps = dbDyn.prepareStatement(sql);
            int num = 1;
            ps.setString(num++, portalUserBean.getFirstName());
            ps.setString(num++, portalUserBean.getMiddleName());
            ps.setString(num++, portalUserBean.getLastName());
            ps.setString(num++, portalUserBean.getAddress());
            ps.setString(num++, portalUserBean.getPhone());
            ps.setString(num++, portalUserBean.getEmail());
            ps.setLong(num++, portalUserBean.getUserId());
            switch(dbDyn.getFamaly()) {
                case DatabaseManager.MYSQL_FAMALY:
                    break;
                default:
                    ps.setString(num++, authSession.getUserLogin());
                    break;
            }
            int i1 = ps.executeUpdate();
            if (log.isDebugEnabled()) log.debug("Count of updated record - " + i1);
            dbDyn.commit();
        } catch (Exception e) {
            try {
                if (dbDyn != null) {
                    dbDyn.rollback();
                }
            } catch (Exception e001) {
            }
            String es = "Error update of portal user";
            log.error(es, e);
            throw new IllegalStateException(es, e);
        } finally {
            DatabaseManager.close(dbDyn, ps);
            dbDyn = null;
            ps = null;
        }
    }
public void deleteUser(User portalUserBean, AuthSession authSession) {
        DatabaseAdapter dbDyn = null;
        PreparedStatement ps = null;
        try {
            dbDyn = DatabaseAdapter.getInstance();
            if (portalUserBean.getUserId() == null) throw new IllegalArgumentException("id of portal user is null");
            String sql = "update WM_LIST_USER " + "set    is_deleted=1 " + "where  ID_USER=? and is_deleted = 0 and ID_FIRM in ";
            switch(dbDyn.getFamaly()) {
                case DatabaseManager.MYSQL_FAMALY:
                    String idList = authSession.getGrantedCompanyId();
                    sql += " (" + idList + ") ";
                    break;
                default:
                    sql += "(select z1.ID_FIRM from v$_read_list_firm z1 where z1.user_login = ?)";
                    break;
            }
            ps = dbDyn.prepareStatement(sql);
            int num = 1;
            ps.setLong(num++, portalUserBean.getUserId());
            switch(dbDyn.getFamaly()) {
                case DatabaseManager.MYSQL_FAMALY:
                    break;
                default:
                    ps.setString(num++, authSession.getUserLogin());
                    break;
            }
            int i1 = ps.executeUpdate();
            if (log.isDebugEnabled()) log.debug("Count of deleted records - " + i1);
            dbDyn.commit();
        } catch (Exception e) {
            try {
                if (dbDyn != null) {
                    dbDyn.rollback();
                }
            } catch (Exception e001) {
            }
            String es = "Error delete of portal user";
            log.error(es, e);
            throw new IllegalStateException(es, e);
        } finally {
            DatabaseManager.close(dbDyn, ps);
            dbDyn = null;
            ps = null;
        }
    }
private static int ejecutaUpdate(String database, String SQL) throws Exception {
        int i = 0;
        DBConnectionManager dbm = null;
        Connection bd = null;
        try {
            dbm = DBConnectionManager.getInstance();
            bd = dbm.getConnection(database);
            Statement st = bd.createStatement();
            i = st.executeUpdate(SQL);
            bd.commit();
            st.close();
            dbm.freeConnection(database, bd);
        } catch (Exception e) {
            log.error("SQL error: " + SQL, e);
            Exception excep;
            if (dbm == null) excep = new Exception("Could not obtain pool object DbConnectionManager"); else if (bd == null) excep = new Exception("The Db connection pool could not obtain a database connection"); else {
                bd.rollback();
                excep = new Exception("SQL Error: " + SQL + " error: " + e);
                dbm.freeConnection(database, bd);
            }
            throw excep;
        }
        return i;
    }
public void init(ConnectionManager mgr, Hashtable cfg, Socket sock) throws RemoteException {
        _cman = mgr;
        _sock = sock;
        for (int i = 0; i < 256; i++) {
            String key = Integer.toHexString(i);
            if (key.length() < 2) key = "0" + key;
            availcmd.push(key);
            commands.put(key, null);
        }
        try {
            _sout = new PrintWriter(_sock.getOutputStream(), true);
            _sinp = new BufferedReader(new InputStreamReader(_sock.getInputStream()));
            String seed = "";
            Random rand = new Random();
            for (int i = 0; i < 16; i++) {
                String hex = Integer.toHexString(rand.nextInt(256));
                if (hex.length() < 2) hex = "0" + hex;
                seed += hex.substring(hex.length() - 2);
            }
            String pass = _mpsw + seed + _spsw;
            MessageDigest md5 = MessageDigest.getInstance("MD5");
            md5.reset();
            md5.update(pass.getBytes());
            String hash = hash2hex(md5.digest()).toLowerCase();
            String banner = "INIT " + "servername" + " " + hash + " " + seed;
            sendLine(banner);
            String txt = readLine(5);
            if (txt == null) {
                throw new IOException("Slave did not send banner !!");
            }
            String sname = "";
            String spass = "";
            String sseed = "";
            try {
                String[] items = txt.split(" ");
                sname = items[1].trim();
                spass = items[2].trim();
                sseed = items[3].trim();
            } catch (Exception e) {
                AsyncSlaveListener.invalidSlave("INITFAIL BadKey", _sock);
            }
            pass = _spsw + sseed + _mpsw;
            md5 = MessageDigest.getInstance("MD5");
            md5.reset();
            md5.update(pass.getBytes());
            hash = hash2hex(md5.digest()).toLowerCase();
            if (!sname.equals(_name)) {
                AsyncSlaveListener.invalidSlave("INITFAIL Unknown", _sock);
            }
            if (!spass.toLowerCase().equals(hash.toLowerCase())) {
                AsyncSlaveListener.invalidSlave("INITFAIL BadKey", _sock);
            }
            _cman.getSlaveManager().addSlave(_name, this, getSlaveStatus(), -1);
            start();
        } catch (IOException e) {
            if (e instanceof ConnectIOException && e.getCause() instanceof EOFException) {
                logger.info("Check slaves.xml on the master that you are allowed to connect.");
            }
            logger.info("IOException: " + e.toString());
            try {
                sock.close();
            } catch (Exception e1) {
            }
        } catch (Exception e) {
            logger.warn("Exception: " + e.toString());
            try {
                sock.close();
            } catch (Exception e2) {
            }
        }
        System.gc();
    }
public static boolean copyFile(String fileIn, String fileOut) {
        FileChannel in = null;
        FileChannel out = null;
        boolean retour = false;
        try {
            in = new FileInputStream(fileIn).getChannel();
            out = new FileOutputStream(fileOut).getChannel();
            in.transferTo(0, in.size(), out);
            in.close();
            out.close();
            retour = true;
        } catch (IOException e) {
            System.err.println("File : " + fileIn);
            e.printStackTrace();
        }
        return retour;
    }
public String getSource(String urlAdd) throws Exception {
        HttpURLConnection urlConnection = null;
        URL url = new URL(urlAdd);
        urlConnection = (HttpURLConnection) url.openConnection();
        urlConnection.setConnectTimeout(timeout);
        if (!urlConnection.getContentType().contains("text/html")) {
            throw new Exception();
        }
        if (urlConnection.getResponseCode() != 200) {
            throw new Exception();
        }
        encoding = getPageEncoding(urlConnection);
        if (encoding == null) {
            encoding = defaultEncoding;
        }
        InputStream in = url.openStream();
        byte[] buffer = new byte[12288];
        StringBuffer sb = new StringBuffer();
        int bytesRead = 0;
        while ((bytesRead = in.read(buffer)) != -1) {
            String reads = new String(buffer, 0, bytesRead, encoding);
            sb.append(reads);
        }
        in.close();
        return sb.toString();
    }
public void sendContent(OutputStream out, Range range, Map map, String string) throws IOException, NotAuthorizedException, BadRequestException {
        System.out.println("sendContent " + file);
        RFileInputStream in = new RFileInputStream(file);
        try {
            IOUtils.copyLarge(in, out);
        } finally {
            in.close();
        }
    }
String runScript(String scriptName) {
        String data = "";
        try {
            URL url = new URL(getCodeBase().toString() + scriptName);
            InputStream in = url.openStream();
            BufferedInputStream buffIn = new BufferedInputStream(in);
            do {
                int temp = buffIn.read();
                if (temp == -1) break;
                data = data + (char) temp;
            } while (true);
        } catch (Exception e) {
            data = "error!";
        }
        return data;
    }
public void newGuidSeed(boolean secure) {
        SecureRandom sr = new SecureRandom();
        long secureInitializer = sr.nextLong();
        Random rand = new Random(secureInitializer);
        String host_ip = "";
        try {
            host_ip = InetAddress.getLocalHost().toString();
        } catch (UnknownHostException err) {
            err.printStackTrace();
        }
        MessageDigest md5 = null;
        try {
            md5 = MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException err) {
            err.printStackTrace();
        }
        try {
            long time = System.currentTimeMillis();
            long randNumber = 0;
            if (secure) {
                randNumber = sr.nextLong();
            } else {
                randNumber = rand.nextLong();
            }
            sbBeforeMd5.append(host_ip);
            sbBeforeMd5.append(":");
            sbBeforeMd5.append(Long.toString(time));
            sbBeforeMd5.append(":");
            sbBeforeMd5.append(Long.toString(randNumber));
            seed = sbBeforeMd5.toString();
            md5.update(seed.getBytes());
            byte[] array = md5.digest();
            StringBuffer temp_sb = new StringBuffer();
            for (int i = 0; i < array.length; i++) {
                int b = array[i] & 0xFF;
                if (b < 0x10) temp_sb.append('0');
                temp_sb.append(Integer.toHexString(b));
            }
            rawGUID = temp_sb.toString();
        } catch (Exception err) {
            err.printStackTrace();
        }
    }
public String getDataAsString(String url) throws RuntimeException {
        try {
            String responseBody = "";
            URLConnection urlc;
            if (!url.toUpperCase().startsWith("HTTP://") && !url.toUpperCase().startsWith("HTTPS://")) {
                urlc = tryOpenConnection(url);
            } else {
                urlc = new URL(url).openConnection();
            }
            urlc.setUseCaches(false);
            urlc.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
            urlc.setRequestProperty("User-Agent", "Mozilla/5.0 (X11; U; Linux x86_64; en-GB; rv:1.9.1.9) Gecko/20100414 Iceweasel/3.5.9 (like Firefox/3.5.9)");
            urlc.setRequestProperty("Accept-Encoding", "gzip");
            InputStreamReader re = new InputStreamReader(urlc.getInputStream());
            BufferedReader rd = new BufferedReader(re);
            String line = "";
            while ((line = rd.readLine()) != null) {
                responseBody += line;
                responseBody += "\n";
                line = null;
            }
            rd.close();
            re.close();
            return responseBody;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
private URLConnection tryOpenConnection(String url) throws RuntimeException {
        URLConnection connection = null;
        try {
            connection = new URL("https://" + url).openConnection();
            connection.getInputStream();
            connection = new URL("https://" + url).openConnection();
            return connection;
        } catch (Exception e) {
            Log.w("ERROR", " " + e.getStackTrace()[0]);
        }
        try {
            connection = new URL("http://" + url).openConnection();
            connection.getInputStream();
            connection = new URL("http://" + url).openConnection();
            return connection;
        } catch (Exception e) {
            Log.w("ERROR", " " + e.getStackTrace()[0]);
        }
        return null;
    }
public byte[] getDataAsByteArray(String url) {
        try {
            byte[] dat = null;
            URLConnection urlc;
            if (!url.toUpperCase().startsWith("HTTP://") && !url.toUpperCase().startsWith("HTTPS://")) {
                urlc = tryOpenConnection(url);
            } else {
                urlc = new URL(url).openConnection();
            }
            urlc.setUseCaches(false);
            urlc.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
            urlc.setRequestProperty("User-Agent", "Mozilla/5.0 (X11; U; Linux x86_64; en-GB; rv:1.9.1.9) Gecko/20100414 Iceweasel/3.5.9 (like Firefox/3.5.9)");
            urlc.setRequestProperty("Accept-Encoding", "gzip");
            InputStream is = urlc.getInputStream();
            int len = urlc.getContentLength();
            if (len < 0) {
                ByteArrayOutputStream bao = new ByteArrayOutputStream();
                byte[] buf = new byte[4096];
                for (; ; ) {
                    int nb = is.read(buf);
                    if (nb <= 0) break;
                    bao.write(buf, 0, nb);
                }
                dat = bao.toByteArray();
                bao.close();
            } else {
                dat = new byte[len];
                int i = 0;
                while (i < len) {
                    int n = is.read(dat, i, len - i);
                    if (n <= 0) break;
                    i += n;
                }
            }
            is.close();
            return dat;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
public char[] getDataAsCharArray(String url) {
        try {
            char[] dat = null;
            URLConnection urlc;
            if (!url.toUpperCase().startsWith("HTTP://") && !url.toUpperCase().startsWith("HTTPS://")) {
                urlc = tryOpenConnection(url);
            } else {
                urlc = new URL(url).openConnection();
            }
            urlc.setUseCaches(false);
            urlc.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
            urlc.setRequestProperty("User-Agent", "Mozilla/5.0 (X11; U; Linux x86_64; en-GB; rv:1.9.1.9) Gecko/20100414 Iceweasel/3.5.9 (like Firefox/3.5.9)");
            urlc.setRequestProperty("Accept-Encoding", "gzip");
            InputStream is = urlc.getInputStream();
            BufferedReader reader = new BufferedReader(new InputStreamReader(is, Charset.defaultCharset()));
            int len = urlc.getContentLength();
            dat = new char[len];
            int i = 0;
            int c;
            while ((c = reader.read()) != -1) {
                char character = (char) c;
                dat[i] = character;
                i++;
            }
            is.close();
            return dat;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
public static Map<String, String> getInstanceMetadata() {
        HashMap<String, String> result = new HashMap<String, String>();
        int retries = 0;
        while (true) {
            try {
                URL url = new URL("http://169.254.169.254/latest/meta-data/");
                BufferedReader rdr = new BufferedReader(new InputStreamReader(url.openStream()));
                String line = rdr.readLine();
                while (line != null) {
                    try {
                        String val = getInstanceMetadata(line);
                        result.put(line, val);
                    } catch (IOException ex) {
                        logger.error("Problem fetching piece of instance metadata!", ex);
                    }
                    line = rdr.readLine();
                }
                return result;
            } catch (IOException ex) {
                if (retries == 5) {
                    logger.debug("Problem getting instance data, retries exhausted...");
                    return result;
                } else {
                    logger.debug("Problem getting instance data, retrying...");
                    try {
                        Thread.sleep((int) Math.pow(2.0, retries) * 1000);
                    } catch (InterruptedException e) {
                    }
                    retries++;
                }
            }
        }
    }
public static String getInstanceUserdata() throws IOException {
        int retries = 0;
        while (true) {
            try {
                URL url = new URL("http://169.254.169.254/latest/user-data/");
                InputStreamReader rdr = new InputStreamReader(url.openStream());
                StringWriter wtr = new StringWriter();
                char[] buf = new char[1024];
                int bytes;
                while ((bytes = rdr.read(buf)) > -1) {
                    if (bytes > 0) {
                        wtr.write(buf, 0, bytes);
                    }
                }
                rdr.close();
                return wtr.toString();
            } catch (IOException ex) {
                if (retries == 5) {
                    logger.debug("Problem getting user data, retries exhausted...");
                    return null;
                } else {
                    logger.debug("Problem getting user data, retrying...");
                    try {
                        Thread.sleep((int) Math.pow(2.0, retries) * 1000);
                    } catch (InterruptedException e) {
                    }
                    retries++;
                }
            }
        }
    }
public static synchronized String getSequenceNumber(String SequenceName) {
        String result = "";
        Connection conn = null;
        Statement ps = null;
        ResultSet rs = null;
        try {
            conn = TPCW_Database.getConnection();
            conn.setAutoCommit(false);
            String sql = "select num from sequence where name='" + SequenceName + "'";
            ps = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
            rs = ps.executeQuery(sql);
            long num = 0;
            while (rs.next()) {
                num = rs.getLong(1);
                result = new Long(num).toString();
            }
            num++;
            sql = "update sequence set num=" + num + " where name='" + SequenceName + "'";
            int res = ps.executeUpdate(sql);
            if (res == 1) {
                conn.commit();
            } else conn.rollback();
        } catch (Exception e) {
            System.out.println("Error Happens when trying to obtain the senquence number");
            e.printStackTrace();
        } finally {
            try {
                if (conn != null) conn.close();
                if (rs != null) rs.close();
                if (ps != null) ps.close();
            } catch (SQLException se) {
                se.printStackTrace();
            }
        }
        return result;
    }
public MemoryBinaryBody(InputStream is) throws IOException {
        TempPath tempPath = TempStorage.getInstance().getRootTempPath();
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        IOUtils.copy(is, out);
        out.close();
        tempFile = out.toByteArray();
    }
public void write(OutputStream out, String className, InputStream classDefStream) throws IOException {
        ByteArrayOutputStream a = new ByteArrayOutputStream();
        IOUtils.copy(classDefStream, a);
        a.close();
        DataOutputStream da = new DataOutputStream(out);
        da.writeUTF(className);
        da.writeUTF(new String(base64.cipher(a.toByteArray())));
    }
public static String generateStackHashKey() {
        Exception e = null;
        try {
            throw new Exception();
        } catch (Exception ex) {
            e = ex;
        }
        MessageDigest digest;
        try {
            digest = java.security.MessageDigest.getInstance("MD5");
            digest.update(getStackTrace(e).getBytes());
            byte[] hash = digest.digest();
            String rtn = Base64.encode(new String(hash));
            if (keys.contains(rtn)) {
                return generatedIterStackHashKey(rtn);
            }
            keys.add(rtn);
            return rtn;
        } catch (NoSuchAlgorithmException ex) {
            throw new RuntimeException(ex);
        }
    }
public static Object loadXmlFromUrl(URL url, int timeout, XML_TYPE xmlType) throws IOException {
        URLConnection connection = url.openConnection();
        connection.setConnectTimeout(timeout);
        connection.setReadTimeout(timeout);
        BufferedInputStream buffInputStream = new BufferedInputStream(connection.getInputStream());
        return loadXml(buffInputStream, xmlType);
    }