_id
stringlengths
2
7
title
stringlengths
3
140
partition
stringclasses
3 values
text
stringlengths
73
34.1k
language
stringclasses
1 value
meta_information
dict
q158100
CcBase64.checkIllegalCharacters
train
private static byte[] checkIllegalCharacters(final byte[] bytes) { final ByteArrayOutputStream out = new ByteArrayOutputStream(); for (final byte byt: bytes) { if (BASE64CHARS.indexOf(byt) < 0) { out.write(byt); } } return out.toByteArray(); }
java
{ "resource": "" }
q158101
CcSigned.mac
train
private Mac mac() throws IOException { try { final Mac mac = Mac.getInstance(this.alg); mac.init(this.key); return mac; } catch (final NoSuchAlgorithmException | InvalidKeyException err) { throw new IOException(err); } }
java
{ "resource": "" }
q158102
AbstractHmTextBody.text
train
@SuppressWarnings("PMD.AssignmentInOperand") private String text(final T item) throws IOException { final String text; try ( InputStream input = this.itemBody(item); ByteArrayOutputStream output = new ByteArrayOutputStream() ) { // @checkstyle MagicNumberC...
java
{ "resource": "" }
q158103
TkAuth.act
train
private Response act(final Request req, final Identity identity) throws IOException { Request wrap = new RqWithoutHeader(req, this.header); if (!identity.equals(Identity.ANONYMOUS)) { wrap = new RqWithAuth(identity, this.header, wrap); } return this.pass.exit(this.ori...
java
{ "resource": "" }
q158104
RqWithDefaultHeader.build
train
private static Request build(final Request req, final String hdr, final String val) throws IOException { final Request request; if (new RqHeaders.Base(req).header(hdr).iterator().hasNext()) { request = req; } else { request = new RqWithHeader(req, hdr, val); ...
java
{ "resource": "" }
q158105
CcHex.decode
train
private static int decode(final int hex) { if (hex >= CcHex.BACK.length) { throw new DecodingException( String.format("invalid hex char: 0x%2x", hex) ); } final int dec = CcHex.BACK[hex]; if (dec < 0) { throw new DecodingException( ...
java
{ "resource": "" }
q158106
RsPrettyXml.transform
train
private static byte[] transform(final InputStream body) throws IOException { final SAXSource source = new SAXSource(new InputSource(body)); final ByteArrayOutputStream result = new ByteArrayOutputStream(); try { final XMLReader xmlreader = SAXParserFactory.newInstance() ...
java
{ "resource": "" }
q158107
RsPrettyXml.prepareDocType
train
private static void prepareDocType(final InputStream body, final Transformer transformer) throws IOException { try { final String html = "html"; final DocumentType doctype = RsPrettyXml.getDocType(body); if (null != doctype) { if (null == doctype.getSy...
java
{ "resource": "" }
q158108
RsPrettyXml.getDocType
train
private static DocumentType getDocType(final InputStream body) throws IOException { final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); try { factory.setFeature(RsPrettyXml.LOAD_EXTERNAL_DTD, false); final DocumentBuilder builder = fac...
java
{ "resource": "" }
q158109
CcXor.xor
train
private byte[] xor(final byte[] input) { final byte[] output = new byte[input.length]; if (this.secret.length == 0) { System.arraycopy(input, 0, output, 0, input.length); } else { int spos = 0; for (int pos = 0; pos < input.length; ++pos) { out...
java
{ "resource": "" }
q158110
PsTwitter.identity
train
private Identity identity(final String tkn) throws IOException { return parse( this.user .uri() .set( URI.create( new Href(PsTwitter.VERIFY_URL) .with(PsTwitter.ACCESS_TOKEN, tkn) ...
java
{ "resource": "" }
q158111
PsTwitter.fetch
train
private String fetch() throws IOException { return this.token .method("POST") .header( "Content-Type", "application/x-www-form-urlencoded;charset=UTF-8" ) .header( "Authorization", String.format( ...
java
{ "resource": "" }
q158112
SiHmac.bitLength
train
private static int bitLength(final int bits) { int correct = bits; if (bits != SiHmac.HMAC256 && bits != SiHmac.HMAC384 && bits != SiHmac.HMAC512) { correct = SiHmac.HMAC256; } return correct; }
java
{ "resource": "" }
q158113
SiHmac.encrypt
train
private byte[] encrypt(final byte[] bytes) throws IOException { try (Formatter formatter = new Formatter()) { for (final byte byt : this.create().doFinal(bytes)) { formatter.format("%02x", byt); } return formatter.toString().getBytes(Charset.defaultCharset());...
java
{ "resource": "" }
q158114
PsFacebook.fetch
train
private User fetch(final String token) { try { return new DefaultFacebookClient( token, this.requestor, new DefaultJsonMapper(), Version.LATEST ).fetchObject( "me", User.class ); } catch (...
java
{ "resource": "" }
q158115
PsFacebook.token
train
private String token(final String home, final String code) throws IOException { final String response = this.request .uri() .set( URI.create( new Href(PsFacebook.ACCESS_TOKEN_URL) .with(PsFacebook.CLIENT_ID, this.app) ...
java
{ "resource": "" }
q158116
RqAuth.identity
train
public Identity identity() throws IOException { final Iterator<String> headers = new RqHeaders.Base(this).header(this.header).iterator(); final Identity user; if (headers.hasNext()) { user = new CcPlain().decode( new Utf8String(headers.next()).asBytes() ...
java
{ "resource": "" }
q158117
RsPrettyJson.transform
train
private static byte[] transform(final InputStream body) throws IOException { final ByteArrayOutputStream res = new ByteArrayOutputStream(); try (JsonReader rdr = Json.createReader(body)) { final JsonObject obj = rdr.readObject(); try (JsonWriter wrt = Json.createWriterFactory( ...
java
{ "resource": "" }
q158118
TkVersioned.make
train
private static String make() { final ResourceBundle res = ResourceBundle.getBundle("org.takes.version"); return String.format( "%s %s %s", res.getString("version"), res.getString("revision"), res.getString("date") ); }
java
{ "resource": "" }
q158119
XeDirectives.transform
train
@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops") private static Iterable<Directive> transform(final Iterable<String> texts) { final Collection<Directive> list = new LinkedList<>(); for (final String text : texts) { try { for (final Directive dir : new Directives(...
java
{ "resource": "" }
q158120
MainRemote.port
train
private static int port(final File file) throws Exception { while (!file.exists()) { TimeUnit.MILLISECONDS.sleep(1L); } final int port; try (InputStream input = Files.newInputStream(file.toPath())) { // @checkstyle MagicNumber (1 line) final byte[] buf...
java
{ "resource": "" }
q158121
FkContentType.getType
train
@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops") private static MediaTypes getType(final Request req) throws IOException { MediaTypes list = new MediaTypes(); final Iterable<String> headers = new RqHeaders.Base(req) .header("Content-Type"); for (final String hdr : header...
java
{ "resource": "" }
q158122
RsVelocity.render
train
private static InputStream render(final String folder, final InputStream template, final Map<String, Object> params) throws IOException { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final Writer writer = new Utf8OutputStreamContent(baos); final VelocityEngine ...
java
{ "resource": "" }
q158123
RsVelocity.convert
train
private static Map<String, Object> convert( final Map<CharSequence, Object> params) { final Map<String, Object> map = new HashMap<>(params.size()); for (final Map.Entry<CharSequence, Object> ent : params.entrySet()) { map.put(ent.getKey().toString(), ent.getValue()); } ...
java
{ "resource": "" }
q158124
RsJson.print
train
private static byte[] print(final RsJson.Source src) throws IOException { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); try (JsonWriter writer = Json.createWriter(baos)) { writer.write(src.toJson()); } return baos.toByteArray(); }
java
{ "resource": "" }
q158125
PsGithub.fetch
train
private Identity fetch(final String token) throws IOException { final String uri = new Href(this.api).path("user") .with(PsGithub.ACCESS_TOKEN, token).toString(); return PsGithub.parse( new JdkRequest(uri) .header("accept", "application/json") .fet...
java
{ "resource": "" }
q158126
PsGithub.token
train
private String token(final String home, final String code) throws IOException { final String uri = new Href(this.github) .path(PsGithub.LOGIN).path("oauth").path(PsGithub.ACCESS_TOKEN) .toString(); return new JdkRequest(uri) .method("POST") .header...
java
{ "resource": "" }
q158127
RsWithHeader.extend
train
private static Iterable<String> extend(final Iterable<String> head, final String header) { if (!RsWithHeader.HEADER.matcher(header).matches()) { throw new IllegalArgumentException( String.format( // @checkstyle LineLength (1 line) "head...
java
{ "resource": "" }
q158128
RqOnce.wrap
train
private static Request wrap(final Request req) { final AtomicBoolean seen = new AtomicBoolean(false); return new Request() { @Override public Iterable<String> head() throws IOException { return req.head(); } @Override public In...
java
{ "resource": "" }
q158129
FkHost.fork
train
private static Fork fork(final String host, final Take take) { return new Fork() { @Override public Opt<Response> route(final Request req) throws IOException { final String hst = new RqHeaders.Smart( new RqHeaders.Base(req) ).single("ho...
java
{ "resource": "" }
q158130
TkRetry.strings
train
private static List<String> strings(final List<IOException> failures) { final List<String> result = new ArrayList<>(failures.size()); final Iterable<String> transform = new Transform<>( failures, new TransformAction<IOException, String>() { @Override ...
java
{ "resource": "" }
q158131
CcSalted.salt
train
@SuppressWarnings("PMD.AvoidArrayLoops") private static byte[] salt(final byte[] text) { final byte size = (byte) CcSalted.RND.nextInt(Tv.TEN); final byte[] output = new byte[text.length + (int) size + 2]; output[0] = size; byte sum = (byte) 0; for (int idx = 0; idx < (int) s...
java
{ "resource": "" }
q158132
CcSalted.unsalt
train
@SuppressWarnings("PMD.CyclomaticComplexity") private static byte[] unsalt(final byte[] text) { if (text.length == 0) { throw new DecodingException("empty input"); } final int size = text[0]; if (size < 0) { throw new DecodingException( String....
java
{ "resource": "" }
q158133
RqFormBase.map
train
private Map<String, List<String>> map() throws IOException { if (this.saved.isEmpty()) { this.saved.add(this.freshMap()); } return this.saved.get(0); }
java
{ "resource": "" }
q158134
RqFormBase.freshMap
train
private Map<String, List<String>> freshMap() throws IOException { final String body = new RqPrint(this.req).printBody(); final Map<String, List<String>> map = new HashMap<>(1); // @checkstyle MultipleStringLiteralsCheck (1 line) for (final String pair : body.split("&")) { if ...
java
{ "resource": "" }
q158135
RqSocket.getLocalAddress
train
public InetAddress getLocalAddress() throws IOException { return InetAddress.getByName( new RqHeaders.Smart(new RqHeaders.Base(this)) .single("X-Takes-LocalAddress") ); }
java
{ "resource": "" }
q158136
RqSocket.getRemoteAddress
train
public InetAddress getRemoteAddress() throws IOException { return InetAddress.getByName( new RqHeaders.Smart(new RqHeaders.Base(this)) .single("X-Takes-RemoteAddress") ); }
java
{ "resource": "" }
q158137
ZipUtil.containsEntry
train
public static boolean containsEntry(File zip, String name) { ZipFile zf = null; try { zf = new ZipFile(zip); return zf.getEntry(name) != null; } catch (IOException e) { throw ZipExceptionUtil.rethrow(e); } finally { closeQuietly(zf); } }
java
{ "resource": "" }
q158138
ZipUtil.getCompressionMethodOfEntry
train
public static int getCompressionMethodOfEntry(File zip, String name) { ZipFile zf = null; try { zf = new ZipFile(zip); ZipEntry zipEntry = zf.getEntry(name); if (zipEntry == null) { return -1; } return zipEntry.getMethod(); } catch (IOException e) { throw ZipE...
java
{ "resource": "" }
q158139
ZipUtil.containsAnyEntry
train
public static boolean containsAnyEntry(File zip, String[] names) { ZipFile zf = null; try { zf = new ZipFile(zip); for (int i = 0; i < names.length; i++) { if (zf.getEntry(names[i]) != null) { return true; } } return false; } catch (IOException e) { ...
java
{ "resource": "" }
q158140
ZipUtil.doUnpackEntry
train
private static byte[] doUnpackEntry(ZipFile zf, String name) throws IOException { ZipEntry ze = zf.getEntry(name); if (ze == null) { return null; // entry not found } InputStream is = zf.getInputStream(ze); try { return IOUtils.toByteArray(is); } finally { IOUtils.closeQui...
java
{ "resource": "" }
q158141
ZipUtil.unpackEntry
train
public static byte[] unpackEntry(InputStream is, String name) { ByteArrayUnpacker action = new ByteArrayUnpacker(); if (!handle(is, name, action)) return null; // entry not found return action.getBytes(); }
java
{ "resource": "" }
q158142
ZipUtil.unpackEntry
train
public static boolean unpackEntry(InputStream is, String name, File file) throws IOException { return handle(is, name, new FileUnpacker(file)); }
java
{ "resource": "" }
q158143
ZipUtil.handle
train
public static boolean handle(File zip, String name, ZipEntryCallback action) { ZipFile zf = null; try { zf = new ZipFile(zip); ZipEntry ze = zf.getEntry(name); if (ze == null) { return false; // entry not found } InputStream in = new BufferedInputStream(zf.getInputStream(...
java
{ "resource": "" }
q158144
ZipUtil.handle
train
public static boolean handle(InputStream is, String name, ZipEntryCallback action) { SingleZipEntryCallback helper = new SingleZipEntryCallback(name, action); iterate(is, helper); return helper.found(); }
java
{ "resource": "" }
q158145
ZipUtil.unpack
train
public static void unpack(File zip, final File outputDir, Charset charset) { unpack(zip, outputDir, IdentityNameMapper.INSTANCE, charset); }
java
{ "resource": "" }
q158146
ZipUtil.packEntry
train
public static byte[] packEntry(File file) { log.trace("Compressing '{}' into a ZIP file with single entry.", file); ByteArrayOutputStream result = new ByteArrayOutputStream(); try { ZipOutputStream out = new ZipOutputStream(result); ZipEntry entry = ZipEntryUtil.fromFile(file.getName(), file); ...
java
{ "resource": "" }
q158147
ZipUtil.pack
train
private static void pack(File dir, ZipOutputStream out, NameMapper mapper, String pathPrefix, boolean mustHaveChildren) throws IOException { String[] filenames = dir.list(); if (filenames == null) { if (!dir.exists()) { throw new ZipException("Given file '" + dir + "' doesn't exist!"); } ...
java
{ "resource": "" }
q158148
ZipUtil.createEmpty
train
public static void createEmpty(File file) { // https://en.wikipedia.org/wiki/Zip_(file_format)#Limits FileOutputStream fos = null; try { fos = new FileOutputStream(file); fos.write(new byte[] {0x50,0x4B,0x05,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0...
java
{ "resource": "" }
q158149
ZipUtil.pack
train
public static void pack(ZipEntrySource[] entries, OutputStream os) { if (log.isDebugEnabled()) { log.debug("Creating stream from {}.", Arrays.asList(entries)); } pack(entries, os, false); }
java
{ "resource": "" }
q158150
ZipUtil.pack
train
public static void pack(ZipEntrySource[] entries, File zip) { if (log.isDebugEnabled()) { log.debug("Creating '{}' from {}.", zip, Arrays.asList(entries)); } OutputStream out = null; try { out = new BufferedOutputStream(new FileOutputStream(zip)); pack(entries, out, true); } c...
java
{ "resource": "" }
q158151
ZipUtil.removeEntry
train
public static void removeEntry(File zip, String path, File destZip) { removeEntries(zip, new String[] { path }, destZip); }
java
{ "resource": "" }
q158152
ZipUtil.copyEntries
train
private static void copyEntries(File zip, final ZipOutputStream out) { // this one doesn't call copyEntries with ignoredEntries, because that has poorer performance final Set<String> names = new HashSet<String>(); iterate(zip, new ZipEntryCallback() { public void process(InputStream in, ZipEntry zipEn...
java
{ "resource": "" }
q158153
ZipUtil.copyEntries
train
private static void copyEntries(File zip, final ZipOutputStream out, final Set<String> ignoredEntries) { final Set<String> names = new HashSet<String>(); final Set<String> dirNames = filterDirEntries(zip, ignoredEntries); iterate(zip, new ZipEntryCallback() { public void process(InputStream in, ZipEnt...
java
{ "resource": "" }
q158154
ZipUtil.replaceEntries
train
public static boolean replaceEntries(File zip, ZipEntrySource[] entries, File destZip) { if (log.isDebugEnabled()) { log.debug("Copying '" + zip + "' to '" + destZip + "' and replacing entries " + Arrays.asList(entries) + "."); } final Map<String, ZipEntrySource> entryByPath = entriesByPath(entries);...
java
{ "resource": "" }
q158155
FileSource.pair
train
public static FileSource[] pair(File[] files, String[] names) { if (files.length > names.length) { throw new IllegalArgumentException("names array must contain " + "at least the same amount of items as files array or more"); } FileSource[] result = new FileSource[files.length]; f...
java
{ "resource": "" }
q158156
FileZipEntryTransformer.transform
train
public void transform(InputStream in, ZipEntry zipEntry, ZipOutputStream out) throws IOException { File inFile = null; File outFile = null; try { inFile = File.createTempFile("zip", null); outFile = File.createTempFile("zip", null); copy(in, inFile); transform(zipEntry, inFile, outFi...
java
{ "resource": "" }
q158157
AsiExtraField.getLocalFileDataData
train
public byte[] getLocalFileDataData() { // CRC will be added later byte[] data = new byte[getLocalFileDataLength().getValue() - WORD]; System.arraycopy(ZipShort.getBytes(getMode()), 0, data, 0, 2); byte[] linkArray = getLinkedFile().getBytes(); // Uses default charset - see class Javadoc // CheckSty...
java
{ "resource": "" }
q158158
AsiExtraField.parseFromLocalFileData
train
public void parseFromLocalFileData(byte[] data, int offset, int length) throws ZipException { long givenChecksum = ZipLong.getValue(data, offset); byte[] tmp = new byte[length - WORD]; System.arraycopy(data, offset + WORD, tmp, 0, length - WORD); crc.reset(); crc.update(tmp); long realChe...
java
{ "resource": "" }
q158159
AsiExtraField.getMode
train
protected int getMode(int mode) { int type = FILE_FLAG; if (isLink()) { type = LINK_FLAG; } else if (isDirectory()) { type = DIR_FLAG; } return type | (mode & PERM_MASK); }
java
{ "resource": "" }
q158160
ZipEntryUtil.copy
train
static ZipEntry copy(ZipEntry original, String newName) { ZipEntry copy = new ZipEntry(newName == null ? original.getName() : newName); if (original.getCrc() != -1) { copy.setCrc(original.getCrc()); } if (original.getMethod() != -1) { copy.setMethod(original.getMethod()); } if (origi...
java
{ "resource": "" }
q158161
ZipEntryUtil.copyEntry
train
static void copyEntry(ZipEntry zipEntry, InputStream in, ZipOutputStream out) throws IOException { copyEntry(zipEntry, in, out, true); }
java
{ "resource": "" }
q158162
ZipEntryUtil.copyEntry
train
static void copyEntry(ZipEntry originalEntry, InputStream in, ZipOutputStream out, boolean preserveTimestamps) throws IOException { ZipEntry copy = copy(originalEntry); if (preserveTimestamps) { TimestampStrategyFactory.getInstance().setTime(copy, originalEntry); } else { copy.setTime(Syste...
java
{ "resource": "" }
q158163
ZipEntryUtil.fromFile
train
static ZipEntry fromFile(String name, File file) { ZipEntry zipEntry = new ZipEntry(name); if (!file.isDirectory()) { zipEntry.setSize(file.length()); } zipEntry.setTime(file.lastModified()); ZTFilePermissions permissions = ZTFilePermissionsUtil.getDefaultStategy().getPermissions(file); i...
java
{ "resource": "" }
q158164
ExtraFieldUtils.register
train
public static void register(Class<?> c) { try { ZipExtraField ze = (ZipExtraField) c.newInstance(); implementations.put(ze.getHeaderId(), c); } catch (ClassCastException cc) { throw new RuntimeException(c + " doesn\'t implement ZipExtraField"); } catch (InstantiationException ie) {...
java
{ "resource": "" }
q158165
ExtraFieldUtils.parse
train
public static List<ZipExtraField> parse(byte[] data) throws ZipException { List<ZipExtraField> v = new ArrayList<ZipExtraField>(); if (data == null) { return v; } int start = 0; while (start <= data.length - WORD) { ZipShort headerId = new ZipShort(data, start); int length = (new Z...
java
{ "resource": "" }
q158166
ExtraFieldUtils.mergeLocalFileDataData
train
public static byte[] mergeLocalFileDataData(List<ZipExtraField> data) { int regularExtraFieldCount = data.size(); int sum = WORD * regularExtraFieldCount; for (ZipExtraField element : data) { sum += element.getLocalFileDataLength().getValue(); } byte[] result = new byte[sum]; int start =...
java
{ "resource": "" }
q158167
ZipLong.getBytes
train
public static byte[] getBytes(long value) { byte[] result = new byte[WORD]; result[0] = (byte) ((value & BYTE_MASK)); result[BYTE_1] = (byte) ((value & BYTE_1_MASK) >> BYTE_1_SHIFT); result[BYTE_2] = (byte) ((value & BYTE_2_MASK) >> BYTE_2_SHIFT); result[BYTE_3] = (byte) ((value & BYTE_3_MASK) >> BY...
java
{ "resource": "" }
q158168
ZipLong.getValue
train
public static long getValue(byte[] bytes, int offset) { long value = (bytes[offset + BYTE_3] << BYTE_3_SHIFT) & BYTE_3_MASK; value += (bytes[offset + BYTE_2] << BYTE_2_SHIFT) & BYTE_2_MASK; value += (bytes[offset + BYTE_1] << BYTE_1_SHIFT) & BYTE_1_MASK; value += (bytes[offset] & BYTE_MASK); return ...
java
{ "resource": "" }
q158169
FileUtilsV2_2.forceDeleteOnExit
train
public static void forceDeleteOnExit(File file) throws IOException { if (file.isDirectory()) { deleteDirectoryOnExit(file); } else { file.deleteOnExit(); } }
java
{ "resource": "" }
q158170
FileUtilsV2_2.deleteDirectoryOnExit
train
private static void deleteDirectoryOnExit(File directory) throws IOException { if (!directory.exists()) { return; } directory.deleteOnExit(); if (!isSymlink(directory)) { cleanDirectoryOnExit(directory); } }
java
{ "resource": "" }
q158171
FileUtils.copy
train
public static void copy(File file, OutputStream out) throws IOException { FileInputStream in = new FileInputStream(file); try { IOUtils.copy(new BufferedInputStream(in), out); } finally { IOUtils.closeQuietly(in); } }
java
{ "resource": "" }
q158172
FileUtils.getTempFileFor
train
public static File getTempFileFor(File file) { File parent = file.getParentFile(); String name = file.getName(); File result; int index = 0; do { result = new File(parent, name + "_" + index++); } while (result.exists()); return result; }
java
{ "resource": "" }
q158173
Zips.addTransformer
train
public Zips addTransformer(String path, ZipEntryTransformer transformer) { this.transformers.add(new ZipEntryTransformerEntry(path, transformer)); return this; }
java
{ "resource": "" }
q158174
Zips.process
train
public void process() { if (src == null && dest == null) { throw new IllegalArgumentException("Source and destination shouldn't be null together"); } File destinationFile = null; try { destinationFile = getDestinationFile(); ZipOutputStream out = null; ZipEntryOrInfoAdapter zipE...
java
{ "resource": "" }
q158175
Zips.iterateExistingExceptRemoved
train
private void iterateExistingExceptRemoved(ZipEntryOrInfoAdapter zipEntryCallback) { if (src == null) { // if we don't have source specified, then we have nothing to iterate. return; } final Set<String> removedDirs = ZipUtil.filterDirEntries(src, removedEntries); ZipFile zf = null; try {...
java
{ "resource": "" }
q158176
Zips.iterateChangedAndAdded
train
private void iterateChangedAndAdded(ZipEntryOrInfoAdapter zipEntryCallback) { for (ZipEntrySource entrySource : changedEntries) { InputStream entrySourceStream = null; try { ZipEntry entry = entrySource.getEntry(); if (nameMapper != null) { String mappedName = nameMapper.map(e...
java
{ "resource": "" }
q158177
Zips.handleInPlaceActions
train
private void handleInPlaceActions(File result) throws IOException { if (isInPlace()) { // we operate in-place FileUtils.forceDelete(src); if (result.isFile()) { FileUtils.moveFile(result, src); } else { FileUtils.moveDirectory(result, src); } } }
java
{ "resource": "" }
q158178
Zips.isEntryInDir
train
private boolean isEntryInDir(Set<String> dirNames, String entryName) { // this should be done with a trie, put dirNames in a trie and check if entryName leads to // some node or not. for(String dirName : dirNames) { if (entryName.startsWith(dirName)) { return true; } } return fal...
java
{ "resource": "" }
q158179
ZipFileUtil.createZipInputStream
train
static ZipInputStream createZipInputStream(InputStream inStream, Charset charset) { if (charset == null) return new ZipInputStream(inStream); try { Constructor<ZipInputStream> constructor = ZipInputStream.class.getConstructor(new Class[] { InputStream.class, Charset.class }); return (ZipInput...
java
{ "resource": "" }
q158180
ZipFileUtil.createZipOutputStream
train
static ZipOutputStream createZipOutputStream(BufferedOutputStream outStream, Charset charset) { if (charset == null) return new ZipOutputStream(outStream); try { Constructor<ZipOutputStream> constructor = ZipOutputStream.class.getConstructor(new Class[] { OutputStream.class, Charset.class }); ...
java
{ "resource": "" }
q158181
ZipFileUtil.getZipFile
train
static ZipFile getZipFile(File src, Charset charset) throws IOException { if (charset == null) { return new ZipFile(src); } try { Constructor<ZipFile> constructor = ZipFile.class.getConstructor(new Class[] { File.class, Charset.class }); return (ZipFile) constructor.newInstance(new Object...
java
{ "resource": "" }
q158182
ZipShort.getBytes
train
public byte[] getBytes() { byte[] result = new byte[2]; result[0] = (byte) (value & BYTE_MASK); result[1] = (byte) ((value & BYTE_1_MASK) >> BYTE_1_SHIFT); return result; }
java
{ "resource": "" }
q158183
ZipShort.getValue
train
public static int getValue(byte[] bytes, int offset) { int value = (bytes[offset + 1] << BYTE_1_SHIFT) & BYTE_1_MASK; value += (bytes[offset] & BYTE_MASK); return value; }
java
{ "resource": "" }
q158184
UnrecognizedExtraField.copy
train
private static byte[] copy(byte[] from) { if (from != null) { byte[] to = new byte[from.length]; System.arraycopy(from, 0, to, 0, to.length); return to; } return null; }
java
{ "resource": "" }
q158185
StreamZipEntryTransformer.transform
train
public void transform(InputStream in, ZipEntry zipEntry, ZipOutputStream out) throws IOException { ZipEntry entry = new ZipEntry(zipEntry.getName()); entry.setTime(System.currentTimeMillis()); out.putNextEntry(entry); transform(zipEntry, in, out); out.closeEntry(); }
java
{ "resource": "" }
q158186
JsonAssert.node
train
public JsonAssert node(String node) { return new JsonAssert(path.to(node), configuration, getNode(actual, node)); }
java
{ "resource": "" }
q158187
JsonAssert.and
train
public JsonAssert and(JsonAssertion... assertions) { Arrays.stream(assertions).forEach(a -> a.doAssert(this)); return this; }
java
{ "resource": "" }
q158188
JsonAssert.isEqualTo
train
@Override public JsonAssert isEqualTo(Object expected) { Diff diff = Diff.create(expected, actual, "fullJson", path.asPrefix(), configuration); String overridingErrorMessage = info.overridingErrorMessage(); if (!isNullOrEmpty(overridingErrorMessage) && !diff.similar()) { failWit...
java
{ "resource": "" }
q158189
JsonAssert.failWithMessage
train
private void failWithMessage(String errorMessage) { AssertionError assertionError = Failures.instance().failureIfErrorMessageIsOverridden(info); if (assertionError == null) { // error message was not overridden, build it. String description = MessageFormatter.instance().format(info.descripti...
java
{ "resource": "" }
q158190
JsonAssert.isObject
train
public MapAssert<String, Object> isObject() { Node node = assertType(OBJECT); return new JsonMapAssert((Map<String, Object>) node.getValue(), path.asPrefix(), configuration) .as("Different value found in node \"%s\"", path); }
java
{ "resource": "" }
q158191
JsonAssert.asNumber
train
public BigDecimalAssert asNumber() { isPresent(NUMBER.getDescription()); Node node = getNode(actual, ""); if (node.getNodeType() == NUMBER) { return createBigDecimalAssert(node.decimalValue()); } else if (node.getNodeType() == STRING) { try { retur...
java
{ "resource": "" }
q158192
JsonAssert.isArray
train
public ListAssert<Object> isArray() { Node node = assertType(ARRAY); return new JsonListAssert((List<?>)node.getValue(), path.asPrefix(), configuration) .as("Different value found in node \"%s\"", path); }
java
{ "resource": "" }
q158193
JsonAssert.isBoolean
train
public BooleanAssert isBoolean() { Node node = assertType(BOOLEAN); return new BooleanAssert((Boolean) node.getValue()).as("Different value found in node \"%s\"", path); }
java
{ "resource": "" }
q158194
JsonAssert.isString
train
public StringAssert isString() { Node node = assertType(STRING); return new StringAssert((String) node.getValue()).as("Different value found in node \"%s\"", path); }
java
{ "resource": "" }
q158195
JsonAssert.isNotNull
train
@Override public JsonAssert isNotNull() { isPresent("not null"); Node node = getNode(actual, ""); if (node.getNodeType() == NULL) { failOnType(node, "not null"); } return this; }
java
{ "resource": "" }
q158196
Path.toField
train
Path toField(String name) { if (isRoot()) { return copy(name); } else { return copy(path + "." + name); } }
java
{ "resource": "" }
q158197
JsonMatchers.jsonPartEquals
train
public static <T> ConfigurableJsonMatcher<T> jsonPartEquals(String path, Object expected) { return new JsonPartMatcher<>(path, expected); }
java
{ "resource": "" }
q158198
JsonMatchers.jsonPartMatches
train
public static <T> Matcher<T> jsonPartMatches(String path, Matcher<?> matcher) { return new MatcherApplyingMatcher<>(path, matcher); }
java
{ "resource": "" }
q158199
ClassUtils.isClassPresent
train
static boolean isClassPresent(String className) { try { ClassUtils.class.getClassLoader().loadClass(className); return true; } catch (Throwable e) { return false; } }
java
{ "resource": "" }