semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
protected byte[] computeHash() {
        try {
            final MessageDigest inputHash = MessageDigest.getInstance("SHA");
            inputHash.update(bufferFileData().getBytes());
            return inputHash.digest();
        } catch (final NoSuchAlgorithmException nsae) {
            lastException = nsae;
            return new byte[0];
        } catch (final IOException ioe) {
            lastException = ioe;
            return new byte[0];
        }
    }
private void readCard() {
        try {
            final String urlString = createURLStringExistRESTGetXQuery("//scheda[cata = \"" + cata + "\"]");
            InputStream inputStream = new URL(urlString).openStream();
            uiSchedaXml.read(inputStream);
            inputStream.close();
        } catch (MalformedURLException e) {
            System.out.println(e);
        } catch (IOException e) {
            System.out.println(e);
        }
    }
private void writeCard() {
        try {
            new URL(createURLStringExistRESTGetXQuery("update value //scheda[cata = \"" + cata + "\"] with " + "\"replaced from /schede/scheda-... by jEpi-Scheda-Applet\"")).openStream().close();
            String urlString = "http://" + server + "/exist/rest/db/schede/" + "scheda-" + cata + ".xml";
            HttpURLConnection httpURLConnection = (HttpURLConnection) new URL(urlString).openConnection();
            httpURLConnection.setDoOutput(true);
            httpURLConnection.setRequestMethod("PUT");
            OutputStream outputStream = httpURLConnection.getOutputStream();
            uiSchedaXml.write(outputStream);
            outputStream.close();
            httpURLConnection.getInputStream().close();
            httpURLConnection.disconnect();
        } catch (MalformedURLException e) {
            System.out.println(e);
        } catch (IOException e) {
            System.out.println(e);
        }
    }
protected String getFileContentAsString(String filePath, String encoding) throws IOException {
        URL testURL = Thread.currentThread().getContextClassLoader().getResource(filePath);
        InputStream input = null;
        StringWriter sw = new StringWriter();
        try {
            if (testURL != null) {
                input = testURL.openStream();
            } else {
                input = new FileInputStream(filePath);
            }
            IOUtils.copy(input, sw, encoding);
        } finally {
            if (input != null) {
                input.close();
            }
        }
        return sw.toString();
    }
@Override
    protected Object doInBackground() throws Exception {
        ArchiveInputStream bufIn = null;
        FileOutputStream fileOut = null;
        try {
            bufIn = DecompressionWorker.guessStream(fileToExtract);
            ArchiveEntry curZip = null;
            int progress = 0;
            while ((curZip = bufIn.getNextEntry()) != null) {
                if (!curZip.isDirectory()) {
                    byte[] content = new byte[(int) curZip.getSize()];
                    fileOut = new FileOutputStream(extractionFile.getAbsolutePath() + File.separator + curZip.getName());
                    for (int i = 0; i < content.length; i++) {
                        fileOut.write(content[i]);
                    }
                    publish(new Integer(progress));
                    progress++;
                }
            }
        } finally {
            if (bufIn != null) {
                bufIn.close();
            }
        }
        return null;
    }
@Override
    public boolean checkConnection() {
        int status = 0;
        try {
            URL url = new URL(TupeloProxy.endpoint);
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            status = conn.getResponseCode();
        } catch (Exception e) {
            logger.severe("Connection test failed with code:" + status);
            e.printStackTrace();
        }
        return status > 199 && status < 400;
    }
static int[] bubble(int[] s) {
        boolean f = true;
        while (f) {
            f = false;
            for (int i = 0; i < s.length - 1; i++) {
                if (s[i] > s[i + 1]) {
                    int t = s[i];
                    s[i] = s[i + 1];
                    s[i + 1] = t;
                    f = true;
                }
            }
        }
        return s;
    }
protected void performInsertTest() throws Exception {
        Connection conn = connect();
        EntityDescriptor ed = repository.getEntityDescriptor(User.class);
        User testUser = new User();
        Date now = new Date();
        conn.setAutoCommit(false);
        testUser.setUsername("rednose");
        testUser.setUCreated("dbUtilTest");
        testUser.setUModified("dbUtilTest");
        testUser.setDtCreated(now);
        testUser.setDtModified(now);
        String sql = dbUtil.genInsert(ed, testUser);
        Statement st = conn.createStatement();
        long id = 0;
        System.err.println("Insert: " + sql);
        int rv = st.executeUpdate(sql, dbUtil.supportsGeneratedKeyQuery() ? Statement.RETURN_GENERATED_KEYS : Statement.NO_GENERATED_KEYS);
        if (rv > 0) {
            if (dbUtil.supportsGeneratedKeyQuery()) {
                ResultSet rs = st.getGeneratedKeys();
                if (rs.next()) id = rs.getLong(1);
            } else {
                id = queryId(ed, now, "dbUtilTest", conn, dbUtil);
            }
            if (id > 0) testUser.setId(id); else rv = 0;
        }
        conn.rollback();
        assertTrue("oups, insert failed?", id != 0);
        System.err.println("successfully created user with id #" + id + " temporarily");
    }
private ShaderProgram loadShaderProgram() {
        ShaderProgram sp = null;
        String vertexProgram = null;
        String fragmentProgram = null;
        Shader[] shaders = new Shader[2];
        try {
            ClassLoader cl = this.getClass().getClassLoader();
            URL url = cl.getResource("Shaders/ivory.vert");
            System.out.println("url " + url);
            InputStream inputSteam = cl.getResourceAsStream("Shaders/ivory.vert");
            Reader reader = null;
            if (inputSteam != null) {
                reader = new InputStreamReader(inputSteam);
            } else {
                File file = new File("lib");
                URL url2 = new URL("jar:file:" + file.getAbsolutePath() + "/j3d-vrml97-i3mainz.jar!/Shaders/ivory.vert");
                InputStream inputSteam2 = url2.openStream();
                reader = new InputStreamReader(inputSteam2);
            }
            char[] buffer = new char[10000];
            int len = reader.read(buffer);
            vertexProgram = new String(buffer);
            vertexProgram = vertexProgram.substring(0, len);
        } catch (Exception e) {
            System.err.println("could'nt load ivory.vert");
            e.printStackTrace();
        }
        try {
            ClassLoader cl = this.getClass().getClassLoader();
            URL url = cl.getResource("Shaders/ivory.frag");
            System.out.println("url " + url);
            InputStream inputSteam = cl.getResourceAsStream("Shaders/ivory.frag");
            Reader reader = null;
            if (inputSteam != null) {
                reader = new InputStreamReader(inputSteam);
            } else {
                File file = new File("lib");
                URL url2 = new URL("jar:file:" + file.getAbsolutePath() + "/j3d-vrml97-i3mainz.jar!/Shaders/ivory.frag");
                InputStream inputSteam2 = url2.openStream();
                reader = new InputStreamReader(inputSteam2);
            }
            char[] buffer = new char[10000];
            int len = reader.read(buffer);
            fragmentProgram = new String(buffer);
            fragmentProgram = fragmentProgram.substring(0, len);
        } catch (Exception e) {
            System.err.println("could'nt load ivory.frag");
            e.printStackTrace();
        }
        if (vertexProgram != null && fragmentProgram != null) {
            shaders[0] = new SourceCodeShader(Shader.SHADING_LANGUAGE_GLSL, Shader.SHADER_TYPE_VERTEX, vertexProgram);
            shaders[1] = new SourceCodeShader(Shader.SHADING_LANGUAGE_GLSL, Shader.SHADER_TYPE_FRAGMENT, fragmentProgram);
            sp = new GLSLShaderProgram();
            sp.setShaders(shaders);
        }
        return sp;
    }
public static void copy(File source, File dest) throws BuildException {
        dest = new File(dest, source.getName());
        if (source.isFile()) {
            byte[] buffer = new byte[4096];
            FileInputStream fin = null;
            FileOutputStream fout = null;
            try {
                fin = new FileInputStream(source);
                fout = new FileOutputStream(dest);
                int count = 0;
                while ((count = fin.read(buffer)) > 0) fout.write(buffer, 0, count);
                fin.close();
                fout.close();
            } catch (IOException ex) {
                throw new BuildException(ex);
            } finally {
                try {
                    if (fin != null) fin.close();
                } catch (IOException ex) {
                }
                try {
                    if (fout != null) fout.close();
                } catch (IOException ex) {
                }
            }
        } else {
            dest.mkdirs();
            File[] children = source.listFiles();
            for (File child : children) copy(child, dest);
        }
    }
public void getDownloadInfo(String _url) throws Exception {
        URL url = new URL(_url);
        con = (HttpURLConnection) url.openConnection();
        con.setRequestProperty("User-Agent", "test");
        con.setRequestProperty("Accept", "*/*");
        con.setRequestProperty("Range", "bytes=0-");
        con.setRequestMethod("HEAD");
        con.setUseCaches(false);
        con.connect();
        con.disconnect();
        if (mustRedirect()) secureRedirect();
        url = con.getURL();
        setURL(url.toString());
        setSize(Long.parseLong(con.getHeaderField("Content-Length")));
        setResumable(con.getResponseCode() == 206);
        setLastModified(con.getLastModified());
        setRangeEnd(getSize() - 1);
    }
public void initGet() throws Exception {
        URL url = new URL(getURL());
        con = (HttpURLConnection) url.openConnection();
        con.setRequestProperty("Accept", "*/*");
        con.setRequestProperty("Range", "bytes=" + getPosition() + "-" + getRangeEnd());
        con.setUseCaches(false);
        con.connect();
        setInputStream(con.getInputStream());
    }
private static InputStream connect(String url) throws IOException {
        int status = 0;
        String currentlyActiveServer = getCurrentlyActiveServer();
        try {
            long begin = System.currentTimeMillis();
            HttpURLConnection httpConnection = (HttpURLConnection) new URL(currentlyActiveServer + url).openConnection();
            httpConnection.setConnectTimeout(connectTimeOut);
            httpConnection.setReadTimeout(readTimeOut);
            httpConnection.setRequestProperty("User-Agent", USER_AGENT);
            InputStream in = httpConnection.getInputStream();
            status = httpConnection.getResponseCode();
            if (status == 200) {
                long elapsedTime = System.currentTimeMillis() - begin;
                averageConnectTime = (averageConnectTime * (averageSampleSize - 1) + elapsedTime) / averageSampleSize;
                if (geoNamesServerFailover != null && averageConnectTime > 5000 && !currentlyActiveServer.equals(geoNamesServerFailover)) {
                    timeOfLastFailureMainServer = System.currentTimeMillis();
                }
                return in;
            }
        } catch (IOException e) {
            return tryFailoverServer(url, currentlyActiveServer, 0, e);
        }
        IOException ioException = new IOException("status code " + status + " for " + url);
        return tryFailoverServer(url, currentlyActiveServer, status, ioException);
    }
private static synchronized InputStream tryFailoverServer(String url, String currentlyActiveServer, int status, IOException e) throws MalformedURLException, IOException {
        logger.log(Level.WARNING, "problems connecting to geonames server " + currentlyActiveServer, e);
        if (geoNamesServerFailover == null || currentlyActiveServer.equals(geoNamesServerFailover)) {
            if (currentlyActiveServer.equals(geoNamesServerFailover)) {
                timeOfLastFailureMainServer = 0;
            }
            throw e;
        }
        timeOfLastFailureMainServer = System.currentTimeMillis();
        logger.info("trying to connect to failover server " + geoNamesServerFailover);
        URLConnection conn = new URL(geoNamesServerFailover + url).openConnection();
        String userAgent = USER_AGENT + " failover from " + geoNamesServer;
        if (status != 0) {
            userAgent += " " + status;
        }
        conn.setRequestProperty("User-Agent", userAgent);
        InputStream in = conn.getInputStream();
        return in;
    }
private final String encryptPassword(final String password) throws EncryptionExecption {
        if ((password == null) || (password.length() == 0)) {
            throw new NullPointerException();
        }
        try {
            final MessageDigest md = MessageDigest.getInstance("SHA");
            md.update((password).getBytes("UTF-8"));
            return new BASE64Encoder().encode(md.digest());
        } catch (NoSuchAlgorithmException e) {
            throw new EncryptionExecption(e);
        } catch (UnsupportedEncodingException e) {
            throw new EncryptionExecption(e);
        }
    }
@Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String uuid = req.getParameterValues(Constants.PARAM_UUID)[0];
        String datastream = null;
        if (req.getRequestURI().contains(Constants.SERVLET_DOWNLOAD_FOXML_PREFIX)) {
            resp.addHeader("Content-Disposition", "attachment; ContentType = \"text/xml\"; filename=\"" + uuid + "_local_version.foxml\"");
        } else {
            datastream = req.getParameterValues(Constants.PARAM_DATASTREAM)[0];
            resp.addHeader("Content-Disposition", "attachment; ContentType = \"text/xml\"; filename=\"" + uuid + "_local_version_" + datastream + ".xml\"");
        }
        String xmlContent = URLDecoder.decode(req.getParameterValues(Constants.PARAM_CONTENT)[0], "UTF-8");
        InputStream is = new ByteArrayInputStream(xmlContent.getBytes("UTF-8"));
        ServletOutputStream os = resp.getOutputStream();
        IOUtils.copyStreams(is, os);
        os.flush();
    }
@Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String uuid = req.getParameterValues(Constants.PARAM_UUID)[0];
        String datastream = null;
        if (req.getRequestURI().contains(Constants.SERVLET_DOWNLOAD_FOXML_PREFIX)) {
            resp.addHeader("Content-Disposition", "attachment; ContentType = \"text/xml\"; filename=\"" + uuid + "_server_version.foxml\"");
        } else {
            datastream = req.getParameterValues(Constants.PARAM_DATASTREAM)[0];
            resp.addHeader("Content-Disposition", "attachment; ContentType = \"text/xml\"; filename=\"" + uuid + "_server_version_" + datastream + ".xml\"");
        }
        ServletOutputStream os = resp.getOutputStream();
        if (uuid != null && !"".equals(uuid)) {
            try {
                StringBuffer sb = new StringBuffer();
                if (req.getRequestURI().contains(Constants.SERVLET_DOWNLOAD_FOXML_PREFIX)) {
                    sb.append(config.getFedoraHost()).append("/objects/").append(uuid).append("/objectXML");
                } else if (req.getRequestURI().contains(Constants.SERVLET_DOWNLOAD_DATASTREAMS_PREFIX)) {
                    sb.append(config.getFedoraHost()).append("/objects/").append(uuid).append("/datastreams/").append(datastream).append("/content");
                }
                InputStream is = RESTHelper.get(sb.toString(), config.getFedoraLogin(), config.getFedoraPassword(), false);
                if (is == null) {
                    return;
                }
                try {
                    if (req.getRequestURI().contains(Constants.SERVLET_DOWNLOAD_DATASTREAMS_PREFIX)) {
                        os.write(Constants.XML_HEADER_WITH_BACKSLASHES.getBytes());
                    }
                    IOUtils.copyStreams(is, os);
                } catch (IOException e) {
                    resp.setStatus(HttpURLConnection.HTTP_NOT_FOUND);
                    LOGGER.error("Problem with downloading foxml.", e);
                } finally {
                    os.flush();
                    if (is != null) {
                        try {
                            is.close();
                        } catch (IOException e) {
                            resp.setStatus(HttpURLConnection.HTTP_NOT_FOUND);
                            LOGGER.error("Problem with downloading foxml.", e);
                        } finally {
                            is = null;
                        }
                    }
                }
            } catch (IOException e) {
                resp.setStatus(HttpURLConnection.HTTP_NOT_FOUND);
                LOGGER.error("Problem with downloading foxml.", e);
            } finally {
                os.flush();
            }
        }
    }
protected InputStream openInputStream(String filename) throws FileNotFoundException {
        InputStream in = null;
        try {
            URL url = new URL(filename);
            in = url.openConnection().getInputStream();
            logger.info("Opening file " + filename);
        } catch (FileNotFoundException e) {
            logger.error("Resource file not found: " + filename);
            throw e;
        } catch (IOException e) {
            logger.error("Resource file can not be readed: " + filename);
            throw new FileNotFoundException("Resource file can not be readed: " + filename);
        }
        if (in == null) {
            logger.error("Resource file not found: " + filename);
            throw new FileNotFoundException(filename);
        }
        return in;
    }
public static void copy(File src, File dest, boolean overwrite) throws IOException {
        if (!src.exists()) throw new IOException("File source does not exists");
        if (dest.exists()) {
            if (!overwrite) throw new IOException("File destination already exists");
            dest.delete();
        } else {
            dest.createNewFile();
        }
        InputStream is = new FileInputStream(src);
        OutputStream os = new FileOutputStream(dest);
        byte[] buffer = new byte[1024 * 4];
        int len = 0;
        while ((len = is.read(buffer)) > 0) {
            os.write(buffer, 0, len);
        }
        os.close();
        is.close();
    }
public static void main(String args[]) {
        if (args.length < 1) {
            printUsage();
        }
        URL url;
        BufferedReader in = null;
        try {
            url = new URL(args[0]);
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            int responseCode = connection.getResponseCode();
            if (responseCode == 200) {
                in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
                String line = null;
                while ((line = in.readLine()) != null) {
                    System.out.println(line);
                }
            } else {
                System.out.println("Response code " + responseCode + " means there was an error reading url " + args[0]);
            }
        } catch (IOException e) {
            System.err.println("IOException attempting to read url " + args[0]);
            e.printStackTrace();
        } finally {
            if (in != null) {
                try {
                    in.close();
                } catch (Exception ignore) {
                }
            }
        }
    }
public static void copyFile(File sourceFile, File destFile) {
        FileChannel source = null;
        FileChannel destination = null;
        try {
            if (!destFile.exists()) {
                destFile.createNewFile();
            }
            source = new FileInputStream(sourceFile).getChannel();
            destination = new FileOutputStream(destFile).getChannel();
            destination.transferFrom(source, 0, source.size());
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                if (source != null) {
                    source.close();
                }
                if (destination != null) {
                    destination.close();
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
public static void updatePicInfo(Connection conn, int nr, int lock, DBPicInfo picInfo) throws SQLException {
        String sql = "";
        PreparedStatement pstmt = null;
        try {
            if (!picInfo.getName().equals("")) {
                sql = "update DBPic set name=? where bnr=?";
                pstmt = conn.prepareStatement(sql);
                pstmt.setString(1, picInfo.getName());
                pstmt.setInt(2, nr);
                pstmt.executeUpdate();
            }
            if (picInfo.getRate() != 0) {
                sql = "update DBPic set rate=? where bnr=?";
                pstmt = conn.prepareStatement(sql);
                pstmt.setInt(1, picInfo.getRate());
                pstmt.setInt(2, nr);
                pstmt.executeUpdate();
            }
            sql = "update DBThumb set thumb_lock=? where bnr=?";
            pstmt = conn.prepareStatement(sql);
            pstmt.setInt(1, lock);
            pstmt.setInt(2, nr);
            pstmt.executeUpdate();
            if (picInfo.getCategories() != null) {
                sql = "delete from Zuordnen where bnr=?";
                pstmt = conn.prepareStatement(sql);
                pstmt.setInt(1, nr);
                pstmt.executeUpdate();
                DaoUpdate.insertPicInCategories(conn, nr, picInfo.getCategories());
            }
            if (picInfo.getKeywords() != null) {
                sql = "delete from Haben where bnr=?";
                pstmt = conn.prepareStatement(sql);
                pstmt.setInt(1, nr);
                pstmt.executeUpdate();
                DaoUpdate.insertPicInKeywords(conn, nr, picInfo.getKeywords());
            }
            conn.commit();
        } catch (SQLException e) {
            conn.rollback();
            throw e;
        } finally {
            pstmt.close();
        }
    }
private String getData(String requestUrl) throws AuthenticationException, IOException {
        URL url = new URL(requestUrl);
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        String header;
        try {
            header = oauthAuthenticator.getHttpAuthorizationHeader(url.toString(), "GET", profile.getOAuthToken(), profile.getOAuthTokenSecret());
        } catch (OAuthException e) {
            throw new AuthenticationException(e);
        }
        conn.setRequestProperty("Authorization", header);
        if (conn.getResponseCode() == HttpURLConnection.HTTP_UNAUTHORIZED) {
            throw new AuthenticationException();
        }
        InputStreamReader reader = new InputStreamReader(conn.getInputStream());
        char[] buffer = new char[1024];
        int bytesRead = 0;
        StringBuilder data = new StringBuilder();
        while ((bytesRead = reader.read(buffer)) != -1) {
            data.append(buffer, 0, bytesRead);
        }
        reader.close();
        if (conn.getResponseCode() != HttpURLConnection.HTTP_OK) {
            throw new IOException(conn.getResponseCode() + " " + conn.getResponseMessage() + "\n" + data);
        }
        return data.toString();
    }