@SuppressWarnings("deprecation") // https://github.com/embulk/embulk/issues/830 static TimestampFormatterRuby ofLegacy(final String formatString, final org.joda.time.DateTimeZone jodaDateTimeZone) { return new TimestampFormatterRuby(new org.jruby.util.RubyDateFormat(formatString, Locale.ENGLISH, true), null, jodaDateTimeZone, formatString); }
public String format(final Timestamp value) { // TODO: Optimize by using reused StringBuilder. this.formatter.setDateTime(new org.joda.time.DateTime(value.getEpochSecond() * 1000, this.jodaDateTimeZone)); this.formatter.setNSec(value.getNano()); return this.formatter.format(null); }
@JRubyMethod public IRubyObject hash(ThreadContext context) { try { MessageDigest digest = MessageDigest.getInstance("SHA-256"); for (IRubyObject key : table.keySet()) { digest.update((byte) key.hashCode()); digest.update((byte) table.get(key).hashCode()); } return context.runtime.newString(new ByteList(digest.digest())); } catch (NoSuchAlgorithmException ignore) { return context.runtime.newFixnum(System.identityHashCode(table)); } }
public static int strLengthFromRubyString(CodeRangeable string, Encoding enc) { final ByteList bytes = string.getByteList(); if (isSingleByteOptimizable(string, enc)) return bytes.getRealSize(); return strLengthFromRubyStringFull(string, bytes, enc); }
private int strOffset(int nth, boolean singlebyte) { int p = value.begin(); int size = value.realSize(); int e = p + size; int pp = nth(value.getEncoding(), value.unsafeBytes(), p, e, nth, singlebyte); if (pp == -1) return size; return pp - p; }
public static boolean areComparable(CodeRangeable string, CodeRangeable other) { ByteList otherValue = other.getByteList(); if (string.getByteList().getEncoding() == otherValue.getEncoding() || string.getByteList().getRealSize() == 0 || otherValue.getRealSize() == 0) return true; return areComparableViaCodeRange(string, other); }
private static boolean dir_fnmatch(ByteList pattern, ByteList path, int flags) { return org.jruby.util.Dir.fnmatch(pattern.getUnsafeBytes(), pattern.getBegin(), pattern.getBegin()+pattern.getRealSize(), path.getUnsafeBytes(), path.getBegin(), path.getBegin()+path.getRealSize(), flags) == 0; }
static IOException mapFileNotFoundOnGetChannel(final FileResource file, final FileNotFoundException ex) { // Java throws FileNotFoundException both if the file doesn't exist or there were // permission issues, but Ruby needs to disambiguate those two cases return file.exists() ? new ResourceException.PermissionDenied(file.absolutePath()) : new ResourceException.NotFound(file.absolutePath()); }
public static FileResource createResource(String cwd, String pathname) { if (pathname == null) { // null pathnames do not exist return new RegularFileResource(JRubyNonExistentFile.NOT_EXIST); } // Try as a jar resource first FileResource jarResource = JarResource.create(pathname); if (jarResource != null) { return jarResource; } return new RegularFileResource(create(cwd, pathname)); }
private IRubyObject execRecursiveI(ExecRecursiveParams p) { IRubyObject result = null; recursivePush(p.list, p.objid, p.pairid); try { result = p.func.call(p.obj, false); } finally { recursivePop(p.list, p.objid, p.pairid); } return result; }
public static int strLengthFromRubyString(CodeRangeable string) { final ByteList bytes = string.getByteList(); if (isSingleByteOptimizable(string, bytes.getEncoding())) return bytes.getRealSize(); return strLengthFromRubyStringFull(string, bytes, bytes.getEncoding()); }
@JRubyMethod public IRubyObject hash(ThreadContext context) { try { MessageDigest digest = MessageDigest.getInstance("SHA-256"); for (RubyMap map : maps.values()) { digest.update((byte) map.hashCode()); } for (RubyRepeatedField repeatedField : repeatedFields.values()) { digest.update((byte) repeatedFields.hashCode()); } for (IRubyObject field : fields.values()) { digest.update((byte) field.hashCode()); } return context.runtime.newString(new ByteList(digest.digest())); } catch (NoSuchAlgorithmException ignore) { return context.runtime.newFixnum(System.identityHashCode(this)); } }
public static boolean areComparable(CodeRangeable string, CodeRangeable other) { ByteList otherValue = other.getByteList(); if (string.getByteList().getEncoding() == otherValue.getEncoding() || string.getByteList().getRealSize() == 0 || otherValue.getRealSize() == 0) return true; return areComparableViaCodeRange(string, other); }
static IOException mapFileNotFoundOnGetChannel(final FileResource file, final FileNotFoundException ex) { // Java throws FileNotFoundException both if the file doesn't exist or there were // permission issues, but Ruby needs to disambiguate those two cases return file.exists() ? new ResourceException.PermissionDenied(file.absolutePath()) : new ResourceException.NotFound(file.absolutePath()); }
@SuppressWarnings("deprecation") // https://github.com/embulk/embulk/issues/830 static TimestampFormatterRuby of(final String formatString, final ZoneOffset zoneOffset) { return new TimestampFormatterRuby(new org.jruby.util.RubyDateFormat(formatString, Locale.ENGLISH, true), zoneOffset, TimeZoneIds.convertZoneOffsetToJodaDateTimeZone(zoneOffset), formatString); }
public static int strLengthFromRubyString(CodeRangeable string, Encoding enc) { final ByteList bytes = string.getByteList(); if (isSingleByteOptimizable(string, enc)) return bytes.getRealSize(); return strLengthFromRubyStringFull(string, bytes, enc); }
@JRubyMethod(meta = true) public static IRubyObject encode(ThreadContext context, IRubyObject recv, IRubyObject value) { RubyMessage message = (RubyMessage) value; return context.runtime.newString(new ByteList(message.build(context).toByteArray())); }
public static int strLengthFromRubyString(CodeRangeable string) { final ByteList bytes = string.getByteList(); if (isSingleByteOptimizable(string, bytes.getEncoding())) return bytes.getRealSize(); return strLengthFromRubyStringFull(string, bytes, bytes.getEncoding()); }