semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public void add(AddInterceptorChain chain, Entry entry, LDAPConstraints constraints) throws LDAPException {
        Connection con = (Connection) chain.getRequest().get(JdbcInsert.MYVD_DB_CON + "LDAPBaseServer");
        if (con == null) {
            throw new LDAPException("Operations Error", LDAPException.OPERATIONS_ERROR, "No Database Connection");
        }
        try {
            con.setAutoCommit(false);
            HashMap<String, String> db2ldap = (HashMap<String, String>) chain.getRequest().get(JdbcInsert.MYVD_DB_DB2LDAP + "LDAPBaseServer");
            PreparedStatement ps = con.prepareStatement("INSERT INTO USERS (id,firstname,lastname,username) VALUES (?,?,?,?)");
            ps.setInt(1, 5);
            ps.setString(2, entry.getEntry().getAttribute(db2ldap.get("firstname")).getStringValue());
            ps.setString(3, entry.getEntry().getAttribute(db2ldap.get("lastname")).getStringValue());
            ps.setString(4, entry.getEntry().getAttribute(db2ldap.get("username")).getStringValue());
            ps.executeUpdate();
            ps.close();
            ps = con.prepareStatement("SELECT id FROM LOCATIONS WHERE name=?");
            PreparedStatement inst = con.prepareStatement("INSERT INTO LOCATIONMAP (person,location) VALUES (?,?)");
            LDAPAttribute l = entry.getEntry().getAttribute(db2ldap.get("name"));
            if (l == null) {
                con.rollback();
                throw new LDAPException("Location is required", LDAPException.OBJECT_CLASS_VIOLATION, "Location is required");
            }
            String[] vals = l.getStringValueArray();
            for (int i = 0; i < vals.length; i++) {
                ps.setString(1, vals[i]);
                ResultSet rs = ps.executeQuery();
                if (!rs.next()) {
                    con.rollback();
                    throw new LDAPException("Location " + vals[i] + " does not exist", LDAPException.OBJECT_CLASS_VIOLATION, "Location " + vals[i] + " does not exist");
                }
                inst.setInt(1, 5);
                inst.setInt(2, rs.getInt("id"));
                inst.executeUpdate();
            }
            ps.close();
            inst.close();
            con.commit();
        } catch (SQLException e) {
            try {
                con.rollback();
            } catch (SQLException e1) {
                throw new LDAPException("Could not add entry or rollback transaction", LDAPException.OPERATIONS_ERROR, e.toString(), e);
            }
            throw new LDAPException("Could not add entry", LDAPException.OPERATIONS_ERROR, e.toString(), e);
        }
    }
public void delete(DeleteInterceptorChain chain, DistinguishedName dn, LDAPConstraints constraints) throws LDAPException {
        Connection con = (Connection) chain.getRequest().get(JdbcInsert.MYVD_DB_CON + "LDAPBaseServer");
        if (con == null) {
            throw new LDAPException("Operations Error", LDAPException.OPERATIONS_ERROR, "No Database Connection");
        }
        try {
            con.setAutoCommit(false);
            int id = getId(dn, con);
            HashMap<String, String> db2ldap = (HashMap<String, String>) chain.getRequest().get(JdbcInsert.MYVD_DB_DB2LDAP + "LDAPBaseServer");
            PreparedStatement ps = con.prepareStatement("DELETE FROM users WHERE id=?");
            ps.setInt(1, id);
            ps.executeUpdate();
            ps = con.prepareStatement("DELETE FROM locationmap WHERE person=?");
            ps.setInt(1, id);
            ps.executeUpdate();
            ps.close();
            con.commit();
        } catch (SQLException e) {
            try {
                con.rollback();
            } catch (SQLException e1) {
                throw new LDAPException("Could not delete entry or rollback transaction", LDAPException.OPERATIONS_ERROR, e.toString(), e);
            }
            throw new LDAPException("Could not delete entry", LDAPException.OPERATIONS_ERROR, e.toString(), e);
        }
    }
public MytemMaster getMytemMaster(String janCode) throws GaeException {
        HttpClient client = new DefaultHttpClient();
        HttpParams httpParams = client.getParams();
        HttpConnectionParams.setSoTimeout(httpParams, 10000);
        HttpProtocolParams.setVersion(httpParams, HttpVersion.HTTP_1_1);
        BufferedReader reader = null;
        StringBuffer request = new StringBuffer(address);
        request.append("api/mytems/show?jan=");
        request.append(janCode);
        try {
            HttpGet httpGet = new HttpGet(request.toString());
            HttpResponse httpResponse = client.execute(httpGet);
            int statusCode = httpResponse.getStatusLine().getStatusCode();
            if (statusCode == NOT_FOUND) {
                return null;
            }
            if (statusCode >= 400) {
                throw new GaeException("Status Error = " + Integer.toString(statusCode));
            }
            reader = new BufferedReader(new InputStreamReader(httpResponse.getEntity().getContent(), "UTF-8"));
            StringBuilder builder = new StringBuilder();
            String line = null;
            while ((line = reader.readLine()) != null) {
                builder.append(line);
            }
            return createMytemMaster(builder.toString());
        } catch (ClientProtocolException e) {
            throw new GaeException(e);
        } catch (SocketTimeoutException e) {
            throw new GaeException(e);
        } catch (IOException exception) {
            throw new GaeException(exception);
        } finally {
            if (reader != null) {
                try {
                    reader.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
public List<MytemHistory> getMytemHistories(String janCode) throws GaeException {
        HttpClient client = new DefaultHttpClient();
        HttpParams httpParams = client.getParams();
        HttpConnectionParams.setSoTimeout(httpParams, 10000);
        HttpProtocolParams.setVersion(httpParams, HttpVersion.HTTP_1_1);
        BufferedReader reader = null;
        StringBuffer request = new StringBuffer(address);
        request.append("api/mytems/history?jan=");
        request.append(janCode);
        try {
            HttpGet httpGet = new HttpGet(request.toString());
            HttpResponse httpResponse = client.execute(httpGet);
            int statusCode = httpResponse.getStatusLine().getStatusCode();
            if (statusCode == NOT_FOUND) {
                return null;
            }
            if (statusCode >= 400) {
                throw new GaeException("Status Error = " + Integer.toString(statusCode));
            }
            reader = new BufferedReader(new InputStreamReader(httpResponse.getEntity().getContent(), "UTF-8"));
            StringBuilder builder = new StringBuilder();
            String line = null;
            while ((line = reader.readLine()) != null) {
                builder.append(line);
            }
            return createMytemHistories(builder.toString());
        } catch (ClientProtocolException e) {
            throw new GaeException(e);
        } catch (SocketTimeoutException e) {
            throw new GaeException(e);
        } catch (IOException exception) {
            throw new GaeException(exception);
        } finally {
            if (reader != null) {
                try {
                    reader.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
private Bitmap getBitmap(String imageUrl) {
        URL url;
        InputStream input = null;
        try {
            url = new URL(address + imageUrl);
            input = url.openStream();
            return BitmapFactory.decodeStream(input);
        } catch (MalformedURLException e) {
            e.printStackTrace();
            return null;
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        } finally {
            if (input != null) {
                try {
                    input.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
public static void main(String[] args) throws Exception {
        URL url = new URL("http://localhost:9090/node/Insert/" + args[0] + "?address=blah");
        URLConnection conn = url.openConnection();
        conn.setDoOutput(true);
        OutputStream os = conn.getOutputStream();
        Conduit.pump(System.in, os);
        Conduit.pump(conn.getInputStream(), System.out);
        System.out.println("done");
    }
private JButton getButtonImagen() {
        if (buttonImagen == null) {
            buttonImagen = new JButton();
            buttonImagen.setText(Messages.getString("gui.AdministracionResorces.6"));
            buttonImagen.setIcon(new ImageIcon("data/icons/view_sidetree.png"));
            buttonImagen.addActionListener(new java.awt.event.ActionListener() {

                public void actionPerformed(java.awt.event.ActionEvent e) {
                    JFileChooser fc = new JFileChooser();
                    fc.addChoosableFileFilter(new ImageFilter());
                    fc.setAccessory(new ImagePreview(fc));
                    int returnVal = fc.showDialog(AdministracionResorces.this, Messages.getString("gui.AdministracionResorces.8"));
                    if (returnVal == JFileChooser.APPROVE_OPTION) {
                        File file = fc.getSelectedFile();
                        String rutaGlobal = System.getProperty("user.dir") + "/" + rutaDatos + "imagenes/" + file.getName();
                        String rutaRelativa = rutaDatos + "imagenes/" + file.getName();
                        try {
                            FileInputStream fis = new FileInputStream(file);
                            FileOutputStream fos = new FileOutputStream(rutaGlobal, true);
                            FileChannel canalFuente = fis.getChannel();
                            FileChannel canalDestino = fos.getChannel();
                            canalFuente.transferTo(0, canalFuente.size(), canalDestino);
                            fis.close();
                            fos.close();
                            imagen.setImagenURL(rutaRelativa);
                            gui.getEntrenamientoIzquierdaLabel().setIcon(gui.getProcesadorDatos().escalaImageIcon(((Imagen) gui.getComboBoxImagenesIzquierda().getSelectedItem()).getImagenURL()));
                            gui.getEntrenamientoDerechaLabel().setIcon(gui.getProcesadorDatos().escalaImageIcon(((Imagen) gui.getComboBoxImagenesDerecha().getSelectedItem()).getImagenURL()));
                            buttonImagen.setIcon(new ImageIcon("data/icons/view_sidetreeOK.png"));
                            labelImagenPreview.setIcon(gui.getProcesadorDatos().escalaImageIcon(imagen.getImagenURL()));
                        } catch (IOException ex) {
                            ex.printStackTrace();
                        }
                    } else {
                    }
                }
            });
        }
        return buttonImagen;
    }
public void actionPerformed(java.awt.event.ActionEvent e) {
                    JFileChooser fc = new JFileChooser();
                    fc.addChoosableFileFilter(new ImageFilter());
                    fc.setAccessory(new ImagePreview(fc));
                    int returnVal = fc.showDialog(AdministracionResorces.this, Messages.getString("gui.AdministracionResorces.8"));
                    if (returnVal == JFileChooser.APPROVE_OPTION) {
                        File file = fc.getSelectedFile();
                        String rutaGlobal = System.getProperty("user.dir") + "/" + rutaDatos + "imagenes/" + file.getName();
                        String rutaRelativa = rutaDatos + "imagenes/" + file.getName();
                        try {
                            FileInputStream fis = new FileInputStream(file);
                            FileOutputStream fos = new FileOutputStream(rutaGlobal, true);
                            FileChannel canalFuente = fis.getChannel();
                            FileChannel canalDestino = fos.getChannel();
                            canalFuente.transferTo(0, canalFuente.size(), canalDestino);
                            fis.close();
                            fos.close();
                            imagen.setImagenURL(rutaRelativa);
                            gui.getEntrenamientoIzquierdaLabel().setIcon(gui.getProcesadorDatos().escalaImageIcon(((Imagen) gui.getComboBoxImagenesIzquierda().getSelectedItem()).getImagenURL()));
                            gui.getEntrenamientoDerechaLabel().setIcon(gui.getProcesadorDatos().escalaImageIcon(((Imagen) gui.getComboBoxImagenesDerecha().getSelectedItem()).getImagenURL()));
                            buttonImagen.setIcon(new ImageIcon("data/icons/view_sidetreeOK.png"));
                            labelImagenPreview.setIcon(gui.getProcesadorDatos().escalaImageIcon(imagen.getImagenURL()));
                        } catch (IOException ex) {
                            ex.printStackTrace();
                        }
                    } else {
                    }
                }
private JButton getButtonSonido() {
        if (buttonSonido == null) {
            buttonSonido = new JButton();
            buttonSonido.setText(Messages.getString("gui.AdministracionResorces.15"));
            buttonSonido.setIcon(new ImageIcon("data/icons/view_sidetree.png"));
            buttonSonido.addActionListener(new java.awt.event.ActionListener() {

                public void actionPerformed(java.awt.event.ActionEvent e) {
                    JFileChooser fc = new JFileChooser();
                    fc.addChoosableFileFilter(new SoundFilter());
                    int returnVal = fc.showDialog(AdministracionResorces.this, Messages.getString("gui.AdministracionResorces.17"));
                    if (returnVal == JFileChooser.APPROVE_OPTION) {
                        File file = fc.getSelectedFile();
                        String rutaGlobal = System.getProperty("user.dir") + "/" + rutaDatos + "sonidos/" + file.getName();
                        String rutaRelativa = rutaDatos + "sonidos/" + file.getName();
                        try {
                            FileInputStream fis = new FileInputStream(file);
                            FileOutputStream fos = new FileOutputStream(rutaGlobal, true);
                            FileChannel canalFuente = fis.getChannel();
                            FileChannel canalDestino = fos.getChannel();
                            canalFuente.transferTo(0, canalFuente.size(), canalDestino);
                            fis.close();
                            fos.close();
                            imagen.setSonidoURL(rutaRelativa);
                            System.out.println(rutaGlobal + " " + rutaRelativa);
                            buttonSonido.setIcon(new ImageIcon("data/icons/view_sidetreeOK.png"));
                            gui.getAudio().reproduceAudio(imagen);
                        } catch (IOException ex) {
                            ex.printStackTrace();
                        }
                    } else {
                    }
                }
            });
        }
        return buttonSonido;
    }
public void actionPerformed(java.awt.event.ActionEvent e) {
                    JFileChooser fc = new JFileChooser();
                    fc.addChoosableFileFilter(new SoundFilter());
                    int returnVal = fc.showDialog(AdministracionResorces.this, Messages.getString("gui.AdministracionResorces.17"));
                    if (returnVal == JFileChooser.APPROVE_OPTION) {
                        File file = fc.getSelectedFile();
                        String rutaGlobal = System.getProperty("user.dir") + "/" + rutaDatos + "sonidos/" + file.getName();
                        String rutaRelativa = rutaDatos + "sonidos/" + file.getName();
                        try {
                            FileInputStream fis = new FileInputStream(file);
                            FileOutputStream fos = new FileOutputStream(rutaGlobal, true);
                            FileChannel canalFuente = fis.getChannel();
                            FileChannel canalDestino = fos.getChannel();
                            canalFuente.transferTo(0, canalFuente.size(), canalDestino);
                            fis.close();
                            fos.close();
                            imagen.setSonidoURL(rutaRelativa);
                            System.out.println(rutaGlobal + " " + rutaRelativa);
                            buttonSonido.setIcon(new ImageIcon("data/icons/view_sidetreeOK.png"));
                            gui.getAudio().reproduceAudio(imagen);
                        } catch (IOException ex) {
                            ex.printStackTrace();
                        }
                    } else {
                    }
                }
public void generate(String urlString, String target) throws Exception {
        URL url = new URL(urlString);
        HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
        BufferedInputStream inputStream = new BufferedInputStream(urlConnection.getInputStream());
        BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(target));
        byte[] buf = new byte[10 * 1024];
        int len;
        while ((len = inputStream.read(buf, 0, buf.length)) != -1) {
            outputStream.write(buf, 0, len);
        }
        inputStream.close();
        outputStream.close();
        urlConnection.disconnect();
    }
String digest(final UserAccountEntity account) {
            try {
                final MessageDigest digest = MessageDigest.getInstance("SHA-1");
                digest.reset();
                digest.update(account.getUserId().getBytes("UTF-8"));
                digest.update(account.getLastLogin().toString().getBytes("UTF-8"));
                digest.update(account.getPerson().getGivenName().getBytes("UTF-8"));
                digest.update(account.getPerson().getSurname().getBytes("UTF-8"));
                digest.update(account.getPerson().getEmail().getBytes("UTF-8"));
                digest.update(m_random);
                return new String(Base64.altEncode(digest.digest()));
            } catch (final Exception e) {
                LOG.error("Exception", e);
                throw new RuntimeException(e);
            }
        }
public static String getHash(String password) {
        try {
            MessageDigest digest = MessageDigest.getInstance("SHA");
            digest.update(password.getBytes());
            return new String(digest.digest());
        } catch (NoSuchAlgorithmException e) {
            log.error("Hashing algorithm not found");
            return password;
        }
    }
public synchronized String encrypt(String plainText) {
        String hash = null;
        try {
            MessageDigest md = null;
            try {
                md = MessageDigest.getInstance("SHA");
            } catch (NoSuchAlgorithmException e) {
                throw new NoSuchAlgorithmException();
            }
            try {
                if (plainText != null) md.update(plainText.getBytes("UTF-8"));
            } catch (UnsupportedEncodingException e) {
                throw new UnsupportedEncodingException();
            }
            byte raw[] = md.digest();
            hash = (new BASE64Encoder()).encode(raw);
        } catch (NoSuchAlgorithmException e) {
            MessageLog.writeErrorMessage(e, this);
        } catch (UnsupportedEncodingException e) {
            MessageLog.writeErrorMessage(e, this);
        }
        return Util.stripChars(hash);
    }
private String calculateCredential(Account account) {
        MessageDigest md5 = null;
        try {
            md5 = MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException e) {
            return null;
        }
        try {
            md5.update(account.getUsername().getBytes("UTF-8"));
            md5.update(account.getCryptPassword().getBytes("UTF-8"));
            md5.update(String.valueOf(account.getObjectId()).getBytes("UTF-8"));
            md5.update(account.getUid().getBytes("UTF-8"));
            byte[] digest = md5.digest();
            return TextUtils.calculateMD5(digest);
        } catch (UnsupportedEncodingException e) {
            return null;
        }
    }
private static HttpURLConnection _getConnection(HttpPrincipal httpPrincipal) throws IOException {
        if (httpPrincipal == null || httpPrincipal.getUrl() == null) {
            return null;
        }
        URL url = null;
        if ((httpPrincipal.getUserId() <= 0) || (httpPrincipal.getPassword() == null)) {
            url = new URL(httpPrincipal.getUrl() + "/tunnel-web/liferay/do");
        } else {
            url = new URL(httpPrincipal.getUrl() + "/tunnel-web/secure/liferay/do");
        }
        HttpURLConnection urlc = (HttpURLConnection) url.openConnection();
        urlc.setDoInput(true);
        urlc.setDoOutput(true);
        urlc.setUseCaches(false);
        urlc.setRequestMethod("POST");
        if ((httpPrincipal.getUserId() > 0) && (httpPrincipal.getPassword() != null)) {
            String userNameAndPassword = httpPrincipal.getUserId() + ":" + httpPrincipal.getPassword();
            urlc.setRequestProperty("Authorization", "Basic " + Base64.encode(userNameAndPassword.getBytes()));
        }
        return urlc;
    }
public static String postRequest(String url, String content) throws IOException {
        InputStream is = null;
        ByteArrayOutputStream buf = new ByteArrayOutputStream();
        String result = null;
        try {
            Object obj = openConnection(url, content, "POST", "text/xml");
            if (obj instanceof InputStream) {
                is = (InputStream) obj;
            } else {
                return "Cannot open a connection with " + url + " : " + obj.toString();
            }
            int c = is.read();
            while (c != -1) {
                buf.write(c);
                c = is.read();
            }
            result = new String(buf.toByteArray());
        } finally {
            if (is != null) {
                is.close();
            }
            if (buf != null) {
                buf.close();
            }
        }
        return result;
    }
public void addUser(String name, String unit, String organizeName, int userId, int orgId, String email) {
        Connection connection = null;
        PreparedStatement ps = null;
        DBOperation dbo = factory.createDBOperation(POOL_NAME);
        try {
            connection = dbo.getConnection();
            ps = connection.prepareStatement(INSERT_USER);
            ps.setInt(1, AddrslistMainDao.getNewID());
            ps.setInt(2, -100);
            ps.setString(3, name.substring(0, 1));
            ps.setString(4, name.substring(1));
            ps.setString(5, unit);
            ps.setString(6, organizeName);
            ps.setString(7, "");
            ps.setString(8, email);
            ps.setString(9, "");
            ps.setString(10, "");
            ps.setString(11, "");
            ps.setString(12, "");
            ps.setString(13, "");
            ps.setString(14, "");
            ps.setString(15, "");
            ps.setString(16, "");
            ps.setString(17, "");
            ps.setString(18, "");
            ps.setInt(19, userId);
            ps.setInt(20, orgId);
            ps.executeUpdate();
            connection.commit();
        } catch (Exception e) {
            e.printStackTrace();
            try {
                connection.rollback();
            } catch (SQLException e1) {
            }
        } finally {
            try {
                ps.close();
                connection.close();
                dbo.close();
            } catch (Exception e) {
            }
        }
    }