semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
private void setManagedContent(Entry entry, Datastream vds) throws StreamIOException {
        if (m_transContext == DOTranslationUtility.SERIALIZE_EXPORT_ARCHIVE && !m_format.equals(ATOM_ZIP1_1)) {
            String mimeType = vds.DSMIME;
            if (MimeTypeHelper.isText(mimeType) || MimeTypeHelper.isXml(mimeType)) {
                try {
                    entry.setContent(IOUtils.toString(vds.getContentStream(), m_encoding), mimeType);
                } catch (IOException e) {
                    throw new StreamIOException(e.getMessage(), e);
                }
            } else {
                entry.setContent(vds.getContentStream(), mimeType);
            }
        } else {
            String dsLocation;
            IRI iri;
            if (m_format.equals(ATOM_ZIP1_1) && m_transContext != DOTranslationUtility.AS_IS) {
                dsLocation = vds.DSVersionID + "." + MimeTypeUtils.fileExtensionForMIMEType(vds.DSMIME);
                try {
                    m_zout.putNextEntry(new ZipEntry(dsLocation));
                    IOUtils.copy(vds.getContentStream(), m_zout);
                    m_zout.closeEntry();
                } catch (IOException e) {
                    throw new StreamIOException(e.getMessage(), e);
                }
            } else {
                dsLocation = StreamUtility.enc(DOTranslationUtility.normalizeDSLocationURLs(m_obj.getPid(), vds, m_transContext).DSLocation);
            }
            iri = new IRI(dsLocation);
            entry.setSummary(vds.DSVersionID);
            entry.setContent(iri, vds.DSMIME);
        }
    }
public static byte[] hash(String identifier) {
        if (function.equals("SHA-1")) {
            try {
                MessageDigest md = MessageDigest.getInstance(function);
                md.reset();
                byte[] code = md.digest(identifier.getBytes());
                byte[] value = new byte[KEY_LENGTH / 8];
                int shrink = code.length / value.length;
                int bitCount = 1;
                for (int j = 0; j < code.length * 8; j++) {
                    int currBit = ((code[j / 8] & (1 << (j % 8))) >> j % 8);
                    if (currBit == 1) bitCount++;
                    if (((j + 1) % shrink) == 0) {
                        int shrinkBit = (bitCount % 2 == 0) ? 0 : 1;
                        value[j / shrink / 8] |= (shrinkBit << ((j / shrink) % 8));
                        bitCount = 1;
                    }
                }
                return value;
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        if (function.equals("CRC32")) {
            CRC32 crc32 = new CRC32();
            crc32.reset();
            crc32.update(identifier.getBytes());
            long code = crc32.getValue();
            code &= (0xffffffffffffffffL >>> (64 - KEY_LENGTH));
            byte[] value = new byte[KEY_LENGTH / 8];
            for (int i = 0; i < value.length; i++) {
                value[value.length - i - 1] = (byte) ((code >> 8 * i) & 0xff);
            }
            return value;
        }
        if (function.equals("Java")) {
            int code = identifier.hashCode();
            code &= (0xffffffff >>> (32 - KEY_LENGTH));
            byte[] value = new byte[KEY_LENGTH / 8];
            for (int i = 0; i < value.length; i++) {
                value[value.length - i - 1] = (byte) ((code >> 8 * i) & 0xff);
            }
            return value;
        }
        return null;
    }
public static void unzip(final File file, final ZipFile zipFile, final File targetDirectory) throws PtException {
        LOG.info("Unzipping zip file '" + file.getAbsolutePath() + "' to directory " + "'" + targetDirectory.getAbsolutePath() + "'.");
        assert (file.exists() && file.isFile());
        if (targetDirectory.exists() == false) {
            LOG.debug("Creating target directory.");
            if (targetDirectory.mkdirs() == false) {
                throw new PtException("Could not create target directory at " + "'" + targetDirectory.getAbsolutePath() + "'!");
            }
        }
        ZipInputStream zipin = null;
        try {
            zipin = new ZipInputStream(new FileInputStream(file));
            ZipEntry nextZipEntry = zipin.getNextEntry();
            while (nextZipEntry != null) {
                LOG.debug("Unzipping entry '" + nextZipEntry.getName() + "'.");
                if (nextZipEntry.isDirectory()) {
                    LOG.debug("Skipping directory.");
                    continue;
                }
                final File targetFile = new File(targetDirectory, nextZipEntry.getName());
                final File parentTargetFile = targetFile.getParentFile();
                if (parentTargetFile.exists() == false) {
                    LOG.debug("Creating directory '" + parentTargetFile.getAbsolutePath() + "'.");
                    if (parentTargetFile.mkdirs() == false) {
                        throw new PtException("Could not create target directory at " + "'" + parentTargetFile.getAbsolutePath() + "'!");
                    }
                }
                InputStream input = null;
                FileOutputStream output = null;
                try {
                    input = zipFile.getInputStream(nextZipEntry);
                    if (targetFile.createNewFile() == false) {
                        throw new PtException("Could not create target file " + "'" + targetFile.getAbsolutePath() + "'!");
                    }
                    output = new FileOutputStream(targetFile);
                    byte[] buffer = new byte[BUFFER_SIZE];
                    int readBytes = input.read(buffer, 0, buffer.length);
                    while (readBytes > 0) {
                        output.write(buffer, 0, readBytes);
                        readBytes = input.read(buffer, 0, buffer.length);
                    }
                } finally {
                    PtCloseUtil.close(input, output);
                }
                nextZipEntry = zipin.getNextEntry();
            }
        } catch (IOException e) {
            throw new PtException("Could not unzip file '" + file.getAbsolutePath() + "'!", e);
        } finally {
            PtCloseUtil.close(zipin);
        }
    }
public static void main(String[] args) throws IOException {
        String uri = "hdfs://localhost:8020/user/leeing/maxtemp/sample.txt";
        Configuration conf = new Configuration();
        FileSystem fs = FileSystem.get(URI.create(uri), conf);
        InputStream in = null;
        try {
            in = fs.open(new Path(uri));
            IOUtils.copyBytes(in, System.out, 8192, false);
        } finally {
            IOUtils.closeStream(in);
        }
    }
@Override
    protected ModelAndView handleRequestInternal(final HttpServletRequest request, final HttpServletResponse response) throws Exception {
        final String filename = ServletRequestUtils.getRequiredStringParameter(request, "id");
        final File file = new File(path, filename + ".html");
        logger.debug("Getting static content from: " + file.getPath());
        final InputStream is = getServletContext().getResourceAsStream(file.getPath());
        OutputStream out = null;
        if (is != null) {
            try {
                out = response.getOutputStream();
                IOUtils.copy(is, out);
            } catch (IOException ioex) {
                logger.error(ioex);
            } finally {
                is.close();
                if (out != null) {
                    out.close();
                }
            }
        }
        return null;
    }
public String readLines() {
        StringBuffer lines = new StringBuffer();
        try {
            int HttpResult;
            URL url = new URL(address);
            URLConnection urlconn = url.openConnection();
            urlconn.connect();
            HttpURLConnection httpconn = (HttpURLConnection) urlconn;
            HttpResult = httpconn.getResponseCode();
            if (HttpResult != HttpURLConnection.HTTP_OK) {
                System.out.println("�޷����ӵ�" + address);
            } else {
                BufferedReader reader = new BufferedReader(new InputStreamReader(urlconn.getInputStream()));
                while (true) {
                    String line = reader.readLine();
                    if (line == null) break;
                    lines.append(line + "\r\n");
                }
                reader.close();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return lines.toString();
    }
public boolean copy(long id) {
        boolean bool = false;
        this.result = null;
        Connection conn = null;
        Object vo = null;
        try {
            PojoParser parser = PojoParser.getInstances();
            conn = ConnectUtil.getConnect();
            conn.setAutoCommit(false);
            String sql = SqlUtil.getInsertSql(this.getCls());
            vo = this.findById(conn, "select * from " + parser.getTableName(cls) + " where " + parser.getPriamryKey(cls) + "=" + id);
            String pk = parser.getPriamryKey(cls);
            this.getClass().getMethod("set" + SqlUtil.getFieldName(pk), new Class[] { long.class }).invoke(vo, new Object[] { 0 });
            PreparedStatement ps = conn.prepareStatement(sql);
            setPsParams(ps, vo);
            ps.executeUpdate();
            ps.close();
            conn.commit();
            bool = true;
        } catch (Exception e) {
            try {
                conn.rollback();
            } catch (Exception ex) {
            }
            this.result = e.getMessage();
        } finally {
            this.closeConnectWithTransaction(conn);
        }
        return bool;
    }
public boolean copy(Class<?> subCls, String subCol, long id) {
        boolean bool = false;
        this.result = null;
        Connection conn = null;
        Object vo = null;
        try {
            conn = ConnectUtil.getConnect();
            conn.setAutoCommit(false);
            PojoParser parser = PojoParser.getInstances();
            String sql = SqlUtil.getInsertSql(this.getCls());
            vo = this.findById(conn, "select * from " + parser.getTableName(cls) + " where " + parser.getPriamryKey(cls) + "=" + id);
            String pk = parser.getPriamryKey(cls);
            this.getCls().getMethod("set" + SqlUtil.getFieldName(pk), new Class[] { long.class }).invoke(vo, new Object[] { 0 });
            PreparedStatement ps = conn.prepareStatement(sql);
            setPsParams(ps, vo);
            ps.executeUpdate();
            ps.close();
            long key = this.id;
            parser = PojoParser.getInstances();
            sql = SqlUtil.getInsertSql(subCls);
            Class<?> clses = this.cls;
            this.cls = subCls;
            ps = conn.prepareStatement("select * from " + parser.getTableName(subCls) + " where " + subCol + "=" + id);
            this.assembleObjToList(ps);
            ps = conn.prepareStatement(sql);
            ids = new long[orgList.size()];
            Method m = subCls.getMethod("set" + SqlUtil.getFieldName(subCol), new Class[] { long.class });
            for (int i = 0; i < orgList.size(); ++i) {
                Object obj = orgList.get(i);
                subCls.getMethod("set" + SqlUtil.getFieldName(parser.getPriamryKey(subCls)), new Class[] { long.class }).invoke(obj, new Object[] { 0 });
                m.invoke(obj, new Object[] { key });
                setPsParams(ps, obj);
                ps.addBatch();
                if ((i % 100) == 0) ps.executeBatch();
                ids[i] = this.id;
            }
            ps.executeBatch();
            ps.close();
            conn.commit();
            this.cls = clses;
            this.id = key;
            bool = true;
        } catch (Exception e) {
            try {
                conn.rollback();
            } catch (Exception ex) {
                ex.printStackTrace();
            }
            this.result = e.getMessage();
        } finally {
            this.closeConnectWithTransaction(conn);
        }
        return bool;
    }
public boolean save(Object obj) {
        boolean bool = false;
        this.result = null;
        if (obj == null) return bool;
        Connection conn = null;
        try {
            conn = ConnectUtil.getConnect();
            conn.setAutoCommit(false);
            String sql = SqlUtil.getInsertSql(this.getCls());
            PreparedStatement ps = conn.prepareStatement(sql);
            setPsParams(ps, obj);
            ps.executeUpdate();
            ps.close();
            conn.commit();
            bool = true;
        } catch (Exception e) {
            try {
                conn.rollback();
            } catch (SQLException e1) {
            }
            this.result = e.getMessage();
        } finally {
            this.closeConnectWithTransaction(conn);
        }
        return bool;
    }
public static String md5(String text) {
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(text.getBytes());
            return ForumUtil.bufferToHex(md.digest());
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
            return null;
        }
    }
public static String md5hash(String text) {
        java.security.MessageDigest md;
        try {
            md = java.security.MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException(e);
        }
        md.update(text.getBytes());
        byte[] md5bytes = md.digest();
        return new String(org.apache.commons.codec.binary.Hex.encodeHex(md5bytes));
    }
public boolean authenticate(String plaintext) throws NoSuchAlgorithmException {
        String[] passwordParts = this.password.split("\\$");
        md = MessageDigest.getInstance("SHA-1");
        md.update(passwordParts[1].getBytes());
        isAuthenticated = toHex(md.digest(plaintext.getBytes())).equalsIgnoreCase(passwordParts[2]);
        return isAuthenticated;
    }
@Override
    public String getHash(String text) throws NoSuchAlgorithmException {
        MessageDigest md5 = MessageDigest.getInstance("MD5");
        md5.update(text.getBytes());
        BigInteger hash = new BigInteger(1, md5.digest());
        return hash.toString(16);
    }
public static SVNConfiguracion load(URL urlConfiguracion) {
        SVNConfiguracion configuracion = null;
        try {
            XMLDecoder xenc = new XMLDecoder(urlConfiguracion.openStream());
            configuracion = (SVNConfiguracion) xenc.readObject();
            configuracion.setFicheroConfiguracion(urlConfiguracion);
            xenc.close();
        } catch (Exception exception) {
            exception.printStackTrace();
        }
        return configuracion;
    }
public static void downloadFile(String htmlUrl, String dirUrl) {
        try {
            URL url = new URL(htmlUrl);
            System.out.println("Opening connection to " + htmlUrl + "...");
            URLConnection urlC = url.openConnection();
            InputStream is = url.openStream();
            Date date = new Date(urlC.getLastModified());
            System.out.println(", modified on: " + date.toLocaleString() + ")...");
            System.out.flush();
            FileOutputStream fos = null;
            String localFile = null;
            StringTokenizer st = new StringTokenizer(url.getFile(), "/");
            while (st.hasMoreTokens()) localFile = st.nextToken();
            fos = new FileOutputStream(dirUrl + "/" + localFile);
            int oneChar, count = 0;
            while ((oneChar = is.read()) != -1) {
                fos.write(oneChar);
                count++;
            }
            is.close();
            fos.close();
            System.out.println(count + " byte(s) copied");
        } catch (MalformedURLException e) {
            System.err.println(e.toString());
        } catch (IOException e) {
            System.err.println(e.toString());
        }
    }
public static Collection providers(Class service, ClassLoader loader) {
        List classList = new ArrayList();
        List nameSet = new ArrayList();
        String name = "META-INF/services/" + service.getName();
        Enumeration services;
        try {
            services = (loader == null) ? ClassLoader.getSystemResources(name) : loader.getResources(name);
        } catch (IOException ioe) {
            System.err.println("Service: cannot load " + name);
            return classList;
        }
        while (services.hasMoreElements()) {
            URL url = (URL) services.nextElement();
            InputStream input = null;
            BufferedReader reader = null;
            try {
                input = url.openStream();
                reader = new BufferedReader(new InputStreamReader(input, "utf-8"));
                String line = reader.readLine();
                while (line != null) {
                    int ci = line.indexOf('#');
                    if (ci >= 0) line = line.substring(0, ci);
                    line = line.trim();
                    int si = line.indexOf(' ');
                    if (si >= 0) line = line.substring(0, si);
                    line = line.trim();
                    if (line.length() > 0) {
                        if (!nameSet.contains(line)) nameSet.add(line);
                    }
                    line = reader.readLine();
                }
            } catch (IOException ioe) {
                System.err.println("Service: problem with: " + url);
            } finally {
                try {
                    if (input != null) input.close();
                    if (reader != null) reader.close();
                } catch (IOException ioe2) {
                    System.err.println("Service: problem with: " + url);
                }
            }
        }
        Iterator names = nameSet.iterator();
        while (names.hasNext()) {
            String className = (String) names.next();
            try {
                classList.add(Class.forName(className, true, loader).newInstance());
            } catch (ClassNotFoundException e) {
                System.err.println("Service: cannot find class: " + className);
            } catch (InstantiationException e) {
                System.err.println("Service: cannot instantiate: " + className);
            } catch (IllegalAccessException e) {
                System.err.println("Service: illegal access to: " + className);
            } catch (NoClassDefFoundError e) {
                System.err.println("Service: " + e + " for " + className);
            } catch (Exception e) {
                System.err.println("Service: exception for: " + className + " " + e);
            }
        }
        return classList;
    }
public void createZip(String baseDir, String objFileName) throws Exception {
        logger.info("createZip: [ " + baseDir + "]   [" + objFileName + "]");
        baseDir = baseDir + "/" + timesmpt;
        File folderObject = new File(baseDir);
        if (folderObject.exists()) {
            List<?> fileList = getSubFiles(new File(baseDir));
            ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(objFileName));
            ZipEntry ze = null;
            byte[] buf = new byte[1024];
            int readLen = 0;
            for (int i = 0; i < fileList.size(); i++) {
                File f = (File) fileList.get(i);
                ze = new ZipEntry(getAbsFileName(baseDir, f));
                ze.setSize(f.length());
                ze.setTime(f.lastModified());
                zos.putNextEntry(ze);
                InputStream is = new BufferedInputStream(new FileInputStream(f));
                while ((readLen = is.read(buf, 0, 1024)) != -1) {
                    zos.write(buf, 0, readLen);
                }
                is.close();
            }
            zos.close();
        } else {
            throw new Exception("this folder isnot exist!");
        }
    }
public static void main(String[] args) throws Exception {
        DES des = new DES();
        StreamBlockReader reader = new StreamBlockReader(new FileInputStream("D:\\test1.txt"));
        StreamBlockWriter writer = new StreamBlockWriter(new FileOutputStream("D:\\test2.txt"));
        SingleKey key = new SingleKey(new Block(64), "");
        key = new SingleKey(new Block("1111111100000000111111110000000011111111000000001111111100000000"), "");
        Mode mode = new ECBDESMode(des);
        des.decrypt(reader, writer, key, mode);
    }
private void streamBinaryData(String urlstr, String format, ServletOutputStream outstr, HttpServletResponse resp) {
        String ErrorStr = null;
        try {
            resp.setContentType(getMimeType(format));
            BufferedInputStream bis = null;
            BufferedOutputStream bos = null;
            try {
                URL url = new URL(urlstr);
                URLConnection urlc = url.openConnection();
                int length = urlc.getContentLength();
                resp.setContentLength(length);
                InputStream in = urlc.getInputStream();
                bis = new BufferedInputStream(in);
                bos = new BufferedOutputStream(outstr);
                byte[] buff = new byte[length];
                int bytesRead;
                while (-1 != (bytesRead = bis.read(buff, 0, buff.length))) {
                    bos.write(buff, 0, bytesRead);
                }
            } catch (Exception e) {
                e.printStackTrace();
                ErrorStr = "Error Streaming the Data";
                outstr.print(ErrorStr);
            } finally {
                if (bis != null) {
                    bis.close();
                }
                if (bos != null) {
                    bos.close();
                }
                if (outstr != null) {
                    outstr.flush();
                    outstr.close();
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
public static boolean copyFile(final File src, final File dest, long extent, final boolean overwrite) throws FileNotFoundException, IOException {
        boolean result = false;
        if (LOGGER.isLoggable(Level.FINE)) {
            LOGGER.fine("Copying file " + src + " to " + dest + " extent " + extent + " exists " + dest.exists());
        }
        if (dest.exists()) {
            if (overwrite) {
                dest.delete();
                LOGGER.finer(dest.getAbsolutePath() + " removed before copy.");
            } else {
                return result;
            }
        }
        FileInputStream fis = null;
        FileOutputStream fos = null;
        FileChannel fcin = null;
        FileChannel fcout = null;
        try {
            fis = new FileInputStream(src);
            fos = new FileOutputStream(dest);
            fcin = fis.getChannel();
            fcout = fos.getChannel();
            if (extent < 0) {
                extent = fcin.size();
            }
            long trans = fcin.transferTo(0, extent, fcout);
            if (trans < extent) {
                result = false;
            }
            result = true;
        } catch (IOException e) {
            String message = "Copying " + src.getAbsolutePath() + " to " + dest.getAbsolutePath() + " with extent " + extent + " got IOE: " + e.getMessage();
            if (e.getMessage().equals("Invalid argument")) {
                LOGGER.severe("Failed copy, trying workaround: " + message);
                workaroundCopyFile(src, dest);
            } else {
                IOException newE = new IOException(message);
                newE.setStackTrace(e.getStackTrace());
                throw newE;
            }
        } finally {
            if (fcin != null) {
                fcin.close();
            }
            if (fcout != null) {
                fcout.close();
            }
            if (fis != null) {
                fis.close();
            }
            if (fos != null) {
                fos.close();
            }
        }
        return result;
    }