semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
private void transferir() {
        PreparedStatement ps = null;
        StringBuilder sql = new StringBuilder();
        boolean problema = false;
        String idFk = "";
        try {
            for (String tabela : tabelas) {
                idFk = mapaTabelas.get(tabela);
                sql.delete(0, sql.length());
                sql.append("UPDATE ");
                sql.append(tabela);
                sql.append(" SET");
                sql.append(" CODEMP" + idFk + "=?,");
                sql.append(" CODFILIAL" + idFk + "=?,");
                sql.append(" CODPLAN=?");
                sql.append(" WHERE");
                sql.append(" CODEMP" + idFk + "=? AND");
                sql.append(" CODFILIAL" + idFk + "=? AND");
                sql.append(" CODPLAN=?");
                try {
                    status.setText("Atulizando tabela " + tabela);
                    ps = con.prepareStatement(sql.toString());
                    ps.setInt(1, Aplicativo.iCodEmp);
                    ps.setInt(2, lcPlanDest.getCodFilial());
                    ps.setString(3, txtCodPlanDest.getVlrString());
                    ps.setInt(4, Aplicativo.iCodEmp);
                    ps.setInt(5, lcPlanOrig.getCodFilial());
                    ps.setString(6, txtCodPlanOrig.getVlrString());
                    ps.executeUpdate();
                } catch (SQLException e) {
                    e.printStackTrace();
                    problema = true;
                    Funcoes.mensagemErro(this, "Erro ao atualizar planejamento de destino.\n" + e.getMessage(), true, con, e);
                    status.setText("");
                    break;
                }
            }
        } finally {
            try {
                if (problema) {
                    con.rollback();
                } else {
                    sql.delete(0, sql.length());
                    sql.append("DELETE FROM FNSALDOLANCA ");
                    sql.append("WHERE CODEMPPN=? AND CODFILIALPN=? AND CODPLAN=?");
                    ps = con.prepareStatement(sql.toString());
                    ps.setInt(1, Aplicativo.iCodEmp);
                    ps.setInt(2, lcPlanOrig.getCodFilial());
                    ps.setString(3, txtCodPlanOrig.getVlrString());
                    ps.executeUpdate();
                    con.commit();
                    btTransferir.setEnabled(false);
                    status.setText("Transfer�ncia completada.");
                }
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }
public static String callService(String urlString) throws NoItemException, ServiceException {
        if (urlString == null || urlString.length() < 1) return null;
        InputStream inputStream = null;
        try {
            URL url = new URL(urlString);
            URLConnection connection = url.openConnection();
            HttpURLConnection htpc = (HttpURLConnection) connection;
            int responseCode = htpc.getResponseCode();
            String responseMessage = htpc.getResponseMessage();
            String contentType = htpc.getContentType();
            if (responseCode == HttpURLConnection.HTTP_OK) {
                inputStream = connection.getInputStream();
                ByteBuffer buffer = WWIO.readStreamToBuffer(inputStream);
                String charsetName = getCharsetName(contentType);
                return decodeBuffer(buffer, charsetName);
            } else if (responseCode == HttpURLConnection.HTTP_BAD_REQUEST) {
                throw new NoItemException(responseMessage);
            } else {
                throw new ServiceException(responseMessage);
            }
        } catch (MalformedURLException e) {
            String msg = Logging.getMessage("generic.MalformedURL", urlString);
            Logging.logger().log(java.util.logging.Level.SEVERE, msg);
            throw new WWRuntimeException(msg);
        } catch (IOException e) {
            String msg = Logging.getMessage("POI.ServiceError", urlString);
            Logging.logger().log(java.util.logging.Level.SEVERE, msg);
            throw new ServiceException(msg);
        } finally {
            WWIO.closeStream(inputStream, urlString);
        }
    }
public static String getPublicIP(Boolean proxy) {
        String IP = null;
        if (!proxy) {
            try {
                URL url = new URL(XMLConfigParser.urlHost + "getPublicIp.php");
                HttpURLConnection Conn = (HttpURLConnection) url.openConnection();
                InputStream InStream = Conn.getInputStream();
                InputStreamReader Isr = new java.io.InputStreamReader(InStream);
                BufferedReader Br = new java.io.BufferedReader(Isr);
                IP = Br.readLine();
                NetworkLog.logMsg(NetworkLog.LOG_INFO, Tools.class, "Your public IP address is " + IP);
            } catch (Exception e) {
                Log.error(Tools.class, e.getMessage());
            }
        } else {
            XMLConfigParser.readProxyConfiguration();
            System.getProperties().put("proxySet", "true");
            System.getProperties().put("proxyHost", XMLConfigParser.proxyHost);
            System.getProperties().put("proxyPort", XMLConfigParser.proxyPort);
            URL url;
            try {
                url = new URL(XMLConfigParser.urlHost + "getPublicIp.php");
                URLConnection urlConn = url.openConnection();
                String password = XMLConfigParser.proxyUsername + ":" + XMLConfigParser.proxyPassword;
                String encoded = Base64.encodeBase64String(password.getBytes());
                urlConn.setRequestProperty("Proxy-Authorization", encoded);
                InputStream InStream = urlConn.getInputStream();
                InputStreamReader Isr = new java.io.InputStreamReader(InStream);
                BufferedReader Br = new java.io.BufferedReader(Isr);
                IP = Br.readLine();
                NetworkLog.logMsg(NetworkLog.LOG_INFO, Tools.class, "Your public IP address is " + IP);
            } catch (MalformedURLException e) {
                Log.error(Tools.class, e.getMessage());
            } catch (IOException e) {
                Log.error(Tools.class, e.getMessage());
            }
        }
        return IP;
    }
private boolean request(URI uri, Controller controller, String login, String password) {
            SSLHttpClient client = new SSLHttpClient();
            client.getCredentialsProvider().setCredentials(new AuthScope(uri.getHost(), uri.getPort()), new UsernamePasswordCredentials(login, password));
            HttpGet get = new HttpGet(uri);
            get.addHeader("Accept", "application/xml");
            try {
                HttpResponse response = client.execute(get);
                int code = response.getStatusLine().getStatusCode();
                if (code == HttpStatus.SC_OK) {
                    final InputStream is = response.getEntity().getContent();
                    final XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
                    factory.setNamespaceAware(true);
                    final XmlPullParser parser = factory.newPullParser();
                    parser.setInput(is, null);
                    while (parser.next() != XmlPullParser.END_DOCUMENT && !controller.stopped()) {
                        if (parser.getEventType() == XmlPullParser.START_TAG) {
                            String name = parser.getName();
                            if (mEntity.equals(name)) {
                                String id = parser.getAttributeValue(null, "id");
                                if (id != null) {
                                    Item item = new Item(id, parser.nextText());
                                    controller.receiveItem(item);
                                }
                            }
                        }
                    }
                }
            } catch (Exception e) {
                controller.error();
                return false;
            }
            return true;
        }
public static String calculateHash(String password) {
        MessageDigest md = null;
        try {
            md = MessageDigest.getInstance("SHA-1");
            md.reset();
        } catch (NoSuchAlgorithmException ex) {
            ex.printStackTrace();
        }
        md.update(password.getBytes());
        return byteToBase64(md.digest());
    }
public Book importFromURL(URL url) {
        InputStream is = null;
        try {
            is = url.openStream();
            return importFromStream(is, url.toString());
        } catch (Exception ex) {
            throw ModelException.Aide.wrap(ex);
        } finally {
            if (is != null) {
                try {
                    is.close();
                } catch (IOException ex) {
                    throw ModelException.Aide.wrap(ex);
                }
            }
        }
    }
private String transferWSDL(String usernameAndPassword) throws WiseConnectionException {
        String filePath = null;
        try {
            URL endpoint = new URL(wsdlURL);
            HttpURLConnection conn = (HttpURLConnection) endpoint.openConnection();
            conn.setDoOutput(false);
            conn.setDoInput(true);
            conn.setUseCaches(false);
            conn.setRequestMethod("GET");
            conn.setRequestProperty("Accept", "text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5");
            conn.setRequestProperty("Connection", "close");
            if (this.password != null) {
                conn.setRequestProperty("Authorization", "Basic " + (new BASE64Encoder()).encode(usernameAndPassword.getBytes()));
            }
            InputStream is = null;
            if (conn.getResponseCode() == 200) {
                is = conn.getInputStream();
            } else {
                is = conn.getErrorStream();
                InputStreamReader isr = new InputStreamReader(is);
                StringWriter sw = new StringWriter();
                char[] buf = new char[200];
                int read = 0;
                while (read != -1) {
                    read = isr.read(buf);
                    sw.write(buf);
                }
                throw new WiseConnectionException("Remote server's response is an error: " + sw.toString());
            }
            File file = new File(tmpDir, new StringBuffer("Wise").append(IDGenerator.nextVal()).append(".xml").toString());
            OutputStream fos = new BufferedOutputStream(new FileOutputStream(file));
            IOUtils.copyStream(fos, is);
            fos.close();
            is.close();
            filePath = file.getPath();
        } catch (WiseConnectionException wce) {
            throw wce;
        } catch (Exception e) {
            logger.error("Failed to download wsdl from URL : " + wsdlURL);
            throw new WiseConnectionException("Wsdl download failed!", e);
        }
        return filePath;
    }
public void copyFile(String source_name, String dest_name) throws IOException {
        File source_file = new File(source_name);
        File destination_file = new File(dest_name);
        FileInputStream source = null;
        FileOutputStream destination = null;
        byte[] buffer;
        int bytes_read;
        try {
            if (!source_file.exists() || !source_file.isFile()) throw new FileCopyException(QZ.PHRASES.getPhrase("25") + " " + source_name);
            if (!source_file.canRead()) throw new FileCopyException(QZ.PHRASES.getPhrase("26") + " " + QZ.PHRASES.getPhrase("27") + ": " + source_name);
            if (destination_file.exists()) {
                if (destination_file.isFile()) {
                    DataInputStream in = new DataInputStream(System.in);
                    String response;
                    if (!destination_file.canWrite()) throw new FileCopyException(QZ.PHRASES.getPhrase("28") + " " + QZ.PHRASES.getPhrase("29") + ": " + dest_name);
                    System.out.print(QZ.PHRASES.getPhrase("19") + dest_name + QZ.PHRASES.getPhrase("30") + ": ");
                    System.out.flush();
                    response = in.readLine();
                    if (!response.equals("Y") && !response.equals("y")) throw new FileCopyException(QZ.PHRASES.getPhrase("31"));
                } else throw new FileCopyException(QZ.PHRASES.getPhrase("28") + " " + QZ.PHRASES.getPhrase("32") + ": " + dest_name);
            } else {
                File parentdir = parent(destination_file);
                if (!parentdir.exists()) throw new FileCopyException(QZ.PHRASES.getPhrase("28") + " " + QZ.PHRASES.getPhrase("33") + ": " + dest_name);
                if (!parentdir.canWrite()) throw new FileCopyException(QZ.PHRASES.getPhrase("28") + " " + QZ.PHRASES.getPhrase("34") + ": " + dest_name);
            }
            source = new FileInputStream(source_file);
            destination = new FileOutputStream(destination_file);
            buffer = new byte[1024];
            while (true) {
                bytes_read = source.read(buffer);
                if (bytes_read == -1) break;
                destination.write(buffer, 0, bytes_read);
            }
        } finally {
            if (source != null) try {
                source.close();
            } catch (IOException e) {
                ;
            }
            if (destination != null) try {
                destination.close();
            } catch (IOException e) {
                ;
            }
        }
    }
public void copyFile2(String src, String dest) throws IOException {
        String newLine = System.getProperty("line.separator");
        FileWriter fw = null;
        FileReader fr = null;
        BufferedReader br = null;
        BufferedWriter bw = null;
        File source = null;
        try {
            fr = new FileReader(src);
            fw = new FileWriter(dest);
            br = new BufferedReader(fr);
            bw = new BufferedWriter(fw);
            source = new File(src);
            int fileLength = (int) source.length();
            char charBuff[] = new char[fileLength];
            while (br.read(charBuff, 0, fileLength) != -1) bw.write(charBuff, 0, fileLength);
        } catch (FileNotFoundException fnfe) {
            throw new FileCopyException(src + " " + QZ.PHRASES.getPhrase("35"));
        } catch (IOException ioe) {
            throw new FileCopyException(QZ.PHRASES.getPhrase("36"));
        } finally {
            try {
                if (br != null) br.close();
                if (bw != null) bw.close();
            } catch (IOException ioe) {
            }
        }
    }
@Override
    protected RemoteInvocationResult doExecuteRequest(HttpInvokerClientConfiguration config, ByteArrayOutputStream baos) throws IOException, ClassNotFoundException {
        HttpPost postMethod = new HttpPost(config.getServiceUrl());
        postMethod.setEntity(new ByteArrayEntity(baos.toByteArray()));
        HttpResponse rsp = httpClient.execute(postMethod);
        StatusLine sl = rsp.getStatusLine();
        if (sl.getStatusCode() >= 300) {
            throw new IOException("Did not receive successful HTTP response: status code = " + sl.getStatusCode() + ", status message = [" + sl.getReasonPhrase() + "]");
        }
        HttpEntity entity = rsp.getEntity();
        InputStream responseBody = entity.getContent();
        return readRemoteInvocationResult(responseBody, config.getCodebaseUrl());
    }
public static void copyFile(String source, String dest) throws IOException {
        FileChannel in = null, out = null;
        try {
            in = new FileInputStream(new File(source)).getChannel();
            out = new FileOutputStream(new File(dest)).getChannel();
            in.transferTo(0, in.size(), out);
        } finally {
            if (in != null) in.close();
            if (out != null) out.close();
        }
    }
public static byte[] getHashedPassword(String password, byte[] randomBytes) {
        byte[] hashedPassword = null;
        try {
            MessageDigest messageDigest = MessageDigest.getInstance("MD5");
            messageDigest.update(randomBytes);
            messageDigest.update(password.getBytes("UTF-8"));
            hashedPassword = messageDigest.digest();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return hashedPassword;
    }
public static void copyFile(File source, String target) throws FileNotFoundException, IOException {
        File fout = new File(target);
        fout.mkdirs();
        fout.delete();
        fout = new File(target);
        FileChannel in = new FileInputStream(source).getChannel();
        FileChannel out = new FileOutputStream(target).getChannel();
        in.transferTo(0, in.size(), out);
        in.close();
        out.close();
    }
public boolean import_pieces(String filename) {
        int pieceId;
        int i;
        int n;
        int[] color;
        boolean byurl = true;
        e2piece temppiece;
        color = new int[4];
        BufferedReader entree;
        try {
            if (byurl == true) {
                URL url = new URL(baseURL, filename);
                InputStream in = url.openStream();
                entree = new BufferedReader(new InputStreamReader(in));
            } else {
                entree = new BufferedReader(new FileReader(filename));
            }
            pieceId = 0;
            while (true) {
                String lineread = entree.readLine();
                if (lineread == null) {
                    break;
                }
                StringTokenizer tok = new StringTokenizer(lineread, " ");
                n = tok.countTokens();
                if (n == 2) {
                } else {
                    for (i = 0; i < 4; i++) {
                        color[i] = Integer.parseInt(tok.nextToken());
                    }
                    pieceId++;
                    System.out.println("Read Piece : " + pieceId + ":" + color[0] + " " + color[1] + " " + color[2] + " " + color[3]);
                    temppiece = new e2piece(pieceId, color[0] + 1, color[1] + 1, color[2] + 1, color[3] + 1);
                    allpieces.add_piece(temppiece);
                    unplacedpieces.add_piece(temppiece);
                }
            }
            return true;
        } catch (IOException err) {
            return false;
        }
    }
public boolean import_hints(String filename) {
        int pieceId;
        int i, col, row;
        int rotation;
        int number;
        boolean byurl = true;
        e2piece temppiece;
        String lineread;
        StringTokenizer tok;
        BufferedReader entree;
        try {
            if (byurl == true) {
                URL url = new URL(baseURL, filename);
                InputStream in = url.openStream();
                entree = new BufferedReader(new InputStreamReader(in));
            } else {
                entree = new BufferedReader(new FileReader(filename));
            }
            pieceId = 0;
            lineread = entree.readLine();
            tok = new StringTokenizer(lineread, " ");
            number = Integer.parseInt(tok.nextToken());
            for (i = 0; i < number; i++) {
                lineread = entree.readLine();
                if (lineread == null) {
                    break;
                }
                tok = new StringTokenizer(lineread, " ");
                pieceId = Integer.parseInt(tok.nextToken());
                col = Integer.parseInt(tok.nextToken()) - 1;
                row = Integer.parseInt(tok.nextToken()) - 1;
                rotation = Integer.parseInt(tok.nextToken());
                System.out.println("placing hint piece : " + pieceId);
                place_piece_at(pieceId, col, row, 0);
                temppiece = board.get_piece_at(col, row);
                temppiece.reset_rotation();
                temppiece.rotate(rotation);
                temppiece.set_as_hint();
            }
            return true;
        } catch (IOException err) {
            return false;
        }
    }
public boolean import_status(String filename) {
        int pieceId;
        int i, j, col, row;
        int rotation;
        int number;
        boolean byurl = false;
        e2piece temppiece;
        String lineread;
        StringTokenizer tok;
        BufferedReader entree;
        try {
            if (byurl == true) {
                URL url = new URL(baseURL, filename);
                InputStream in = url.openStream();
                entree = new BufferedReader(new InputStreamReader(in));
            } else {
                entree = new BufferedReader(new FileReader(filename));
            }
            pieceId = 0;
            for (i = 0; i < board.colnb; i++) {
                for (j = 0; j < board.rownb; j++) {
                    unplace_piece_at(i, j);
                }
            }
            while (true) {
                lineread = entree.readLine();
                if (lineread == null) {
                    break;
                }
                tok = new StringTokenizer(lineread, " ");
                pieceId = Integer.parseInt(tok.nextToken());
                col = Integer.parseInt(tok.nextToken()) - 1;
                row = Integer.parseInt(tok.nextToken()) - 1;
                rotation = Integer.parseInt(tok.nextToken());
                place_piece_at(pieceId, col, row, 0);
                temppiece = board.get_piece_at(col, row);
                temppiece.reset_rotation();
                temppiece.rotate(rotation);
            }
            return true;
        } catch (IOException err) {
            return false;
        }
    }
public static String getMD5(String source) {
        String s = null;
        char hexDigits[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
        try {
            java.security.MessageDigest md = java.security.MessageDigest.getInstance("MD5");
            md.update(source.getBytes());
            byte tmp[] = md.digest();
            char str[] = new char[16 * 2];
            int k = 0;
            for (int i = 0; i < 16; i++) {
                byte byte0 = tmp[i];
                str[k++] = hexDigits[byte0 >>> 4 & 0xf];
                str[k++] = hexDigits[byte0 & 0xf];
            }
            s = new String(str);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return s;
    }
private static void recurseFiles(File root, File file, TarArchiveOutputStream taos, boolean absolute) throws IOException {
        if (file.isDirectory()) {
            File[] files = file.listFiles();
            for (File file2 : files) {
                recurseFiles(root, file2, taos, absolute);
            }
        } else if ((!file.getName().endsWith(".tar")) && (!file.getName().endsWith(".TAR"))) {
            String filename = null;
            if (absolute) {
                filename = file.getAbsolutePath().substring(root.getAbsolutePath().length());
            } else {
                filename = file.getName();
            }
            TarArchiveEntry tae = new TarArchiveEntry(filename);
            tae.setSize(file.length());
            taos.putArchiveEntry(tae);
            FileInputStream fis = new FileInputStream(file);
            IOUtils.copy(fis, taos);
            taos.closeArchiveEntry();
        }
    }
private static void addFile(File file, TarArchiveOutputStream taos) throws IOException {
        String filename = null;
        filename = file.getName();
        TarArchiveEntry tae = new TarArchiveEntry(filename);
        tae.setSize(file.length());
        taos.putArchiveEntry(tae);
        FileInputStream fis = new FileInputStream(file);
        IOUtils.copy(fis, taos);
        taos.closeArchiveEntry();
    }