semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public void excluir(Cliente cliente) throws Exception {
        Connection connection = criaConexao(false);
        String sql = "delete from cliente where cod_cliente = ?";
        PreparedStatement stmt = null;
        try {
            stmt = connection.prepareStatement(sql);
            stmt.setLong(1, cliente.getId());
            int retorno = stmt.executeUpdate();
            if (retorno == 0) {
                connection.rollback();
                throw new SQLException("Ocorreu um erro inesperado no momento de remover dados de cliente no banco!");
            }
            connection.commit();
        } catch (SQLException e) {
            connection.rollback();
            throw e;
        } finally {
            try {
                stmt.close();
                this.fechaConexao();
            } catch (SQLException e) {
                throw e;
            }
        }
    }
@Override
    public void incluir(Cliente cliente) throws Exception {
        Connection connection = criaConexao(false);
        String sql = "insert into cliente select nextval('sq_cliente') as cod_cliente, ? as nome,  ? as sexo, ?";
        PreparedStatement stmt = null;
        try {
            stmt = connection.prepareStatement(sql);
            stmt.setString(1, cliente.getNome());
            stmt.setString(2, cliente.getSexo());
            stmt.setInt(3, cliente.getCidade().getCodCidade());
            int retorno = stmt.executeUpdate();
            if (retorno == 0) {
                connection.rollback();
                throw new SQLException("Ocorreu um erro inesperado no momento de inserir dados de cliente no banco!");
            }
            connection.commit();
        } catch (SQLException e) {
            connection.rollback();
            throw e;
        } finally {
            try {
                stmt.close();
                this.fechaConexao();
            } catch (SQLException e) {
                throw e;
            }
        }
    }
public static void doIt(String action) {
        int f = -1;
        Statement s = null;
        Connection connection = null;
        try {
            init();
            log.info("<<< Looking up UserTransaction >>>");
            UserTransaction usertransaction = (UserTransaction) context.lookup("java:comp/UserTransaction");
            log.info("<<< beginning the transaction >>>");
            usertransaction.begin();
            log.info("<<< Connecting to xadatasource >>>");
            connection = xadatasource.getConnection();
            log.info("<<< Connected >>>");
            s = connection.createStatement();
            s.executeUpdate("update testdata set foo=foo + 1 where id=1");
            if ((action != null) && action.equals("commit")) {
                log.info("<<< committing the transaction >>>");
                usertransaction.commit();
            } else {
                log.info("<<< rolling back the transaction >>>");
                usertransaction.rollback();
            }
            log.info("<<< transaction complete >>>");
        } catch (Exception e) {
            log.error("doIt", e);
        } finally {
            try {
                s.close();
                connection.close();
            } catch (Exception x) {
                log.error("problem closing statement/connection", x);
            }
        }
    }
@Override
    protected void doRequest(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String reqPath = req.getPathInfo();
        if (reqPath.startsWith("/")) reqPath = reqPath.substring(1);
        ZipEntry entry = zipInfo.get(reqPath);
        if (entry == null) {
            logger.debug(Utils.join("Requested path not found: [", reqPath, "]"));
            resp.sendError(HttpServletResponse.SC_NOT_FOUND);
            return;
        }
        logger.debug(Utils.join("Requested path: [", reqPath, "]"));
        ServletUtils.establishContentType(reqPath, resp);
        InputStream in = null;
        try {
            in = new BufferedInputStream(zipFile.getInputStream(entry));
            IOUtils.copy(in, resp.getOutputStream());
            logger.debug("Rendered: " + reqPath);
        } catch (FileNotFoundException e) {
            logger.error("zipped resource not found: " + reqPath);
        } finally {
            IOUtils.closeQuietly(in);
        }
    }
public ResourceMigratorBuilder createResourceMigratorBuilder(NotificationReporter reporter) {
            return new ResourceMigratorBuilder() {

                public ResourceMigrator getCompletedResourceMigrator() {
                    return new ResourceMigrator() {

                        public void migrate(InputMetadata meta, InputStream inputStream, OutputCreator outputCreator) throws IOException, ResourceMigrationException {
                            OutputStream outputStream = outputCreator.createOutputStream();
                            IOUtils.copy(inputStream, outputStream);
                        }
                    };
                }

                public void setTarget(Version version) {
                }

                public void startType(String typeName) {
                }

                public void setRegexpPathRecogniser(String re) {
                }

                public void setCustomPathRecogniser(PathRecogniser pathRecogniser) {
                }

                public void addRegexpContentRecogniser(Version version, String re) {
                }

                public void addCustomContentRecogniser(Version version, ContentRecogniser contentRecogniser) {
                }

                public XSLStreamMigratorBuilder createXSLStreamMigratorBuilder() {
                    return null;
                }

                public void addStep(Version inputVersion, Version outputVersion, StreamMigrator streamMigrator) {
                }

                public void endType() {
                }
            };
        }
public ResourceMigrator getCompletedResourceMigrator() {
                    return new ResourceMigrator() {

                        public void migrate(InputMetadata meta, InputStream inputStream, OutputCreator outputCreator) throws IOException, ResourceMigrationException {
                            OutputStream outputStream = outputCreator.createOutputStream();
                            IOUtils.copy(inputStream, outputStream);
                        }
                    };
                }
KeyStore getKeyStore() throws JarSignerException {
        if (keyStore == null) {
            KeyStore store = null;
            if (providerName == null) {
                try {
                    store = KeyStore.getInstance(this.storeType);
                } catch (KeyStoreException e) {
                    e.printStackTrace();
                }
            } else {
                try {
                    store = KeyStore.getInstance(storeType, providerName);
                } catch (KeyStoreException e) {
                    e.printStackTrace();
                } catch (NoSuchProviderException e) {
                    e.printStackTrace();
                }
            }
            if (storeURI == null) {
                throw new JarSignerException("Cannot load the keystore " + " error con el keystore");
            }
            try {
                storeURI = storeURI.replace(File.separatorChar, '/');
                URL url = null;
                try {
                    url = new URL(storeURI);
                } catch (java.net.MalformedURLException e) {
                    url = new File(storeURI).toURI().toURL();
                }
                InputStream is = null;
                try {
                    is = url.openStream();
                    store.load(is, storePass);
                } finally {
                    if (is != null) {
                        is.close();
                    }
                }
            } catch (Exception e) {
                throw new JarSignerException("Cannot load the keystore " + storeURI, e);
            }
            keyStore = store;
        }
        return keyStore;
    }
public static String getURL(String urlString, String getData, String postData) {
        try {
            if (getData != null) if (!getData.equals("")) urlString += "?" + getData;
            URL url = new URL(urlString);
            URLConnection connection = url.openConnection();
            if (!postData.equals("")) {
                connection.setDoOutput(true);
                PrintWriter out = new PrintWriter(connection.getOutputStream());
                out.print(postData);
                out.close();
            }
            BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
            int inputLine;
            String output = "";
            while ((inputLine = in.read()) != -1) output += (char) inputLine;
            in.close();
            return output;
        } catch (Exception e) {
            return null;
        }
    }
public void dumpDB(String in, String out) {
        try {
            FileChannel inChannel = new FileInputStream(in).getChannel();
            FileChannel outChannel = new FileOutputStream(out).getChannel();
            inChannel.transferTo(0, inChannel.size(), outChannel);
            inChannel.close();
            outChannel.close();
        } catch (Exception e) {
            Log.d("exception", e.toString());
        }
    }
private void copyFile(File sourceFile, File targetFile) {
        beNice();
        dispatchEvent(SynchronizationEventType.FileCopy, sourceFile, targetFile);
        File temporaryFile = new File(targetFile.getPath().concat(".jnstemp"));
        while (temporaryFile.exists()) {
            try {
                beNice();
                temporaryFile.delete();
                beNice();
            } catch (Exception ex) {
            }
        }
        try {
            if (targetFile.exists()) {
                targetFile.delete();
            }
            FileInputStream fis = new FileInputStream(sourceFile);
            FileOutputStream fos = new FileOutputStream(temporaryFile);
            byte[] buffer = new byte[204800];
            int readBytes = 0;
            int counter = 0;
            while ((readBytes = fis.read(buffer)) != -1) {
                counter++;
                updateStatus("... processing fragment " + String.valueOf(counter));
                fos.write(buffer, 0, readBytes);
            }
            fis.close();
            fos.close();
            temporaryFile.renameTo(targetFile);
            temporaryFile.setLastModified(sourceFile.lastModified());
            targetFile.setLastModified(sourceFile.lastModified());
        } catch (IOException e) {
            Exception dispatchedException = new Exception("ERROR: Copy File( " + sourceFile.getPath() + ", " + targetFile.getPath() + " )");
            dispatchEvent(dispatchedException, sourceFile, targetFile);
        }
        dispatchEvent(SynchronizationEventType.FileCopyDone, sourceFile, targetFile);
    }
public static final void newRead() {
        HTMLDocument html = new HTMLDocument();
        html.putProperty("IgnoreCharsetDirective", new Boolean(true));
        try {
            HTMLEditorKit kit = new HTMLEditorKit();
            URL url = new URL("http://omega.rtu.lv/en/index.html");
            kit.read(new BufferedReader(new InputStreamReader(url.openStream())), html, 0);
            Reader reader = new FileReader(html.getText(0, html.getLength()));
            List<String> links = HTMLUtils.extractLinks(reader);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
private static String getHash(String hash, String clear) {
        try {
            MessageDigest md = MessageDigest.getInstance(hash);
            md.update(clear.getBytes("UTF-8"));
            byte[] bytes = md.digest();
            String str = new String();
            for (int i = 0; i < bytes.length; ++i) str += Integer.toHexString(0xF0 & bytes[i]).charAt(0) + Integer.toHexString(0x0F & bytes[i]);
            return str;
        } catch (NoSuchAlgorithmException exc) {
        } catch (UnsupportedEncodingException exc) {
        }
        return "";
    }
public static String getMD5(String input) {
        String res = "";
        try {
            MessageDigest algorithm = MessageDigest.getInstance("MD5");
            algorithm.reset();
            algorithm.update(input.getBytes("ISO8859_1"));
            byte[] md5 = algorithm.digest();
            String tmp = "";
            for (int i = 0; i < md5.length; i++) {
                tmp = (Integer.toHexString(0xFF & md5[i]));
                if (tmp.length() == 1) {
                    res += "0" + tmp;
                } else {
                    res += tmp;
                }
            }
        } catch (Exception ex) {
        }
        return res;
    }
public boolean copyOneOfMyFile(File f, String dest) {
        if (!ownsThisFile(f.getName())) return false;
        if (!dest.endsWith(File.separator)) dest = dest.concat(File.separator);
        try {
            BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(new File(dest + f.getName())));
            BufferedInputStream in = new BufferedInputStream(new FileInputStream(f));
            int len = 1024;
            byte[] read = new byte[len];
            while ((len = in.read(read)) > 0) out.write(read, 0, len);
            out.flush();
            out.close();
            in.close();
            if (!PatchManager.mute) System.out.println("file created : " + dest + f.getName());
        } catch (IOException e) {
            System.out.println("copy directory : " + e);
            return false;
        }
        return true;
    }
public boolean addMeFile(File f) {
        try {
            BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(new File(directory + f.getName())));
            BufferedInputStream in = new BufferedInputStream(new FileInputStream(f));
            byte[] read = new byte[128];
            int len = 128;
            while ((len = in.read(read)) > 0) out.write(read, 0, len);
            out.flush();
            out.close();
            in.close();
            if (!PatchManager.mute) System.out.println("added : " + directory + f.getName());
        } catch (IOException e) {
            System.out.println("copy directory : " + e);
            return false;
        }
        return true;
    }
public InputStream getResourceAsStream(String path) {
            try {
                URL url = getResource(path);
                if (url == null) return null;
                return url.openStream();
            } catch (Exception e) {
                Log.ignore(e);
                return null;
            }
        }
@Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
    public Image getGoogleMapImage(final BigDecimal latitude, final BigDecimal longitude, final Integer zoomLevel) {
        if (longitude == null) {
            throw new IllegalArgumentException("Longitude cannot be null.");
        }
        if (latitude == null) {
            throw new IllegalArgumentException("Latitude cannot be null.");
        }
        if (zoomLevel == null) {
            throw new IllegalArgumentException("ZoomLevel cannot be null.");
        }
        final URI url = GoogleMapsUtils.buildGoogleMapsStaticUrl(latitude, longitude, zoomLevel);
        BufferedImage img;
        try {
            URLConnection conn = url.toURL().openConnection();
            img = ImageIO.read(conn.getInputStream());
        } catch (UnknownHostException e) {
            LOGGER.error("Google static MAPS web service is not reachable (UnknownHostException).", e);
            img = new BufferedImage(GoogleMapsUtils.defaultWidth, 100, BufferedImage.TYPE_INT_RGB);
            final Graphics2D graphics = img.createGraphics();
            final Map<Object, Object> renderingHints = CollectionUtils.getHashMap();
            renderingHints.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
            graphics.addRenderingHints(renderingHints);
            graphics.setBackground(Color.WHITE);
            graphics.setColor(Color.GRAY);
            graphics.clearRect(0, 0, GoogleMapsUtils.defaultWidth, 100);
            graphics.drawString("Not Available", 30, 30);
        } catch (IOException e) {
            throw new IllegalStateException(e);
        }
        return img;
    }
private void copyFile(String sourceFilename, String destDirname) throws BuildException {
        log("Copying file " + sourceFilename + " to " + destDirname);
        File destFile = getDestFile(sourceFilename, destDirname);
        InputStream inStream = null;
        OutputStream outStream = null;
        try {
            inStream = new BufferedInputStream(new FileInputStream(sourceFilename));
            outStream = new BufferedOutputStream(new FileOutputStream(destFile));
            byte[] buffer = new byte[1024];
            int n = 0;
            while ((n = inStream.read(buffer)) != -1) outStream.write(buffer, 0, n);
        } catch (Exception e) {
            throw new BuildException("Failed to copy file \"" + sourceFilename + "\" to directory \"" + destDirname + "\"");
        } finally {
            try {
                if (inStream != null) inStream.close();
            } catch (IOException e) {
            }
            try {
                if (outStream != null) outStream.close();
            } catch (IOException e) {
            }
        }
    }
private static List<Properties> findExtensions() {
        URL url = null;
        try {
            List<Properties> extensions = new ArrayList<Properties>();
            Enumeration<URL> res = ExtensionHelper.class.getClassLoader().getResources("logdistiller.properties");
            while (res.hasMoreElements()) {
                url = res.nextElement();
                Properties prop = new Properties();
                prop.load(url.openStream());
                extensions.add(prop);
            }
            return extensions;
        } catch (IOException ioe) {
            String msg = (url == null) ? "unable to list resources logdistiller.properties" : "unable to load resource " + url.toExternalForm();
            throw new RuntimeException(msg, ioe);
        }
    }
private static String getTextFromURL(HttpServletRequest req, String urlString) {
        StringBuffer buffer = new StringBuffer();
        if (!urlString.startsWith("http")) {
            String requestURL = req.getRequestURL().toString();
            urlString = requestURL.substring(0, requestURL.lastIndexOf("/")) + urlString;
        }
        try {
            URL url = new URL(urlString);
            BufferedReader input = new BufferedReader(new InputStreamReader(url.openStream()));
            String line = "";
            while ((line = input.readLine()) != null) {
                buffer.append(line);
                buffer.append(Constants.LF);
            }
        } catch (FileNotFoundException nf) {
            log.error("File not found: " + urlString, nf);
        } catch (Exception e) {
            log.error("Exception while reading file: " + urlString, e);
        }
        return buffer.toString();
    }
public void notifyTerminated(Writer r) {
        all_writers.remove(r);
        if (all_writers.isEmpty()) {
            all_terminated = true;
            Iterator iterator = open_files.iterator();
            while (iterator.hasNext()) {
                FileWriter.FileChunk fc = (FileWriter.FileChunk) iterator.next();
                do {
                    try {
                        fc.stream.flush();
                        fc.stream.close();
                    } catch (IOException e) {
                    }
                    fc = fc.next;
                } while (fc != null);
            }
            iterator = open_files.iterator();
            boolean all_ok = true;
            while (iterator.hasNext()) {
                FileWriter.FileChunk fc = (FileWriter.FileChunk) iterator.next();
                logger.logComment("File chunk <" + fc.name + "> " + fc.start_byte + " " + fc.position + " " + fc.actual_file);
                boolean ok = true;
                while (fc.next != null) {
                    ok = ok && (fc.start_byte + fc.actual_file.length()) == fc.next.start_byte;
                    fc = fc.next;
                }
                if (ok) {
                    logger.logComment("Received file <" + fc.name + "> is contiguous (and hopefully complete)");
                } else {
                    logger.logError("Received file <" + fc.name + "> is NOT contiguous");
                    all_ok = false;
                }
            }
            if (all_ok) {
                byte[] buffer = new byte[16384];
                iterator = open_files.iterator();
                while (iterator.hasNext()) {
                    FileWriter.FileChunk fc = (FileWriter.FileChunk) iterator.next();
                    try {
                        if (fc.next != null) {
                            FileOutputStream fos = new FileOutputStream(fc.actual_file, true);
                            fc = fc.next;
                            while (fc != null) {
                                FileInputStream fis = new FileInputStream(fc.actual_file);
                                int actually_read = fis.read(buffer);
                                while (actually_read != -1) {
                                    fos.write(buffer, 0, actually_read);
                                    actually_read = fis.read(buffer);
                                }
                                fc.actual_file.delete();
                                fc = fc.next;
                            }
                        }
                    } catch (FileNotFoundException e) {
                        e.printStackTrace();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
            fte.allWritersTerminated();
            fte = null;
        }
    }