protected Properties getProperties() { Properties p = new Properties(); FileInputStream fis = null; try { fis = new FileInputStream(file); p.load(fis); return p; } catch (Exception e) { throw new RuntimeException("Could not read file: " + file); } finally { Utils.closeQuietly(fis); } }
public PermissionsI() { Long l = (Long) Utils .internalForm(ome.model.internal.Permissions.EMPTY); if (l == null) { throw new IllegalStateException("Permissions.DEFAULT is null"); } this.perm1 = l.longValue(); }
/** * produces a String representation of the {@link PermissionsI} similar to * those on a Unix filesystem. Unset bits are represented by a dash, while * other bits are represented by a symbolic value in the correct bit * position. For example, a Permissions with all rights * granted to all but WORLD roles would look like: rwrw-- */ @Override public String toString() { return Utils.toPermissions(perm1).toString(); }
/** * Limit the objects to which {@link Policy} instances are applied. This * reduces the overhead of creating a {@link HashSet} for every object in * a returned graph. * * @param obj e.g. the argument to {@link #listActiveRestrictions(IObject)}. * @return true if the given object should <em>not</em> be restricted. */ protected boolean filterObject(IObject obj) { if (obj == null) { return true; } return !types.contains( Utils.trueClass(obj.getClass())); // Fix javassist }
public Object call(IObject object) { if (object == null) { return null; } IObject copy = (IObject) Utils.trueInstance(object.getClass()); copy.setId(object.getId()); copy.unload(); list.add(copy); if (count) { count(object); /* PERFORMANCE HIT */ } return null; }
/** * instantiates an object using the trueClass. * * @param source * Regular or CGLIB-based class. * @return the regular Java instance. */ public static <T extends IObject> T trueInstance(Class<T> source) { final Class<T> trueClass = trueClass(source); final T result; try { result = trueClass.newInstance(); } catch (InstantiationException e) { throw new RuntimeException(String.format(msg, trueClass), e); } catch (IllegalAccessException e) { throw new RuntimeException("Not allowed to create class:" + trueClass, e); } return result; }
IObject unloaded = Utils.trueInstance(f.getClass().asSubclass(IObject.class)); unloaded.setId(proxy.getId()); unloaded.unload();
/** * Return byte array of Thumbnail, providing byte array * * @param thumbnail * @param buf * @return a byte array * @throws IOException */ public byte[] getThumbnail(Thumbnail thumbnail, byte[] buf) throws IOException { String path = getThumbnailPath(thumbnail.getId()); FileInputStream stream = new FileInputStream(path); try { stream.read(buf, 0, buf.length); } finally { Utils.closeQuietly(stream); } return buf; }
/** * Return the short type name of an {@link Annotation}. If the instance is * an {@link ome.model.annotations.TextAnnotation} the returned value will * be "TextAnnotation". * * @param annotation * @return See above. */ private String annotationTypeString(Annotation annotation) { Class ac = Utils.trueClass(annotation.getClass()); int dot = ac.getName().lastIndexOf('.'); if (dot < 0) { dot = -1; } String at = ac.getName().substring(dot + 1, ac.getName().length()); return at; }
public PermissionsI(String representation) { Long l = (Long) Utils.internalForm(ome.model.internal.Permissions .parseString(representation)); if (l == null) { throw new IllegalStateException(representation + " produced null"); } this.perm1 = l.longValue(); }
public static ome.model.internal.Permissions convert(omero.model.Permissions p) { if (p == null) { return null; } return Utils.toPermissions(p.getPerm1()); }
set(null, ex); } finally { Utils.closeQuietly(bufIn);
protected Class findClass(Class source) { return (Class) c2c().get(Utils.trueClass(source)); }
public PermissionsI(ome.model.internal.Permissions sourceP) { setPerm1((Long) ome.util.Utils.internalForm(sourceP)); this.restrictions = sourceP.getRestrictions(); String[] extRestr = sourceP.copyExtendedRestrictions(); this.extendedRestrictions = extRestr == null ? null : Arrays.<String>asList(extRestr); }
@Override public ExperimenterGroup mapRow(ResultSet arg0, int arg1) throws SQLException { ExperimenterGroup group = new ExperimenterGroup(); group.setId(arg0.getLong(1)); group.setName(arg0.getString(2)); Permissions p = Utils.toPermissions(arg0.getLong(3)); group.getDetails().setPermissions(p); return group; } }, id);
public void download(long fileId, File file, int blockSize) throws ServerError, IOException { final ServiceFactoryPrx sf = getSession(); final OriginalFile obj = (OriginalFile) sf.getQueryService().get("OriginalFile", fileId); final RawFileStorePrx store = sf.createRawFileStore(); final FileOutputStream stream = new FileOutputStream(file); final long size = obj.getSize().getValue(); long offset = 0; store.setFileId(fileId); try { for (offset = 0; (offset+blockSize) < size;) { stream.write(store.read(offset, blockSize)); offset += blockSize; } stream.write(store.read(offset, (int) (size-offset))); } finally { Utils.closeQuietly(stream); store.close(); } }
@SuppressWarnings("unchecked") public static <T extends IObject> T reflectiveNewInstance(T f) { Method m; T iobj; try { Class<T> c = (Class<T>) Utils.trueClass(f.getClass()); iobj = c.newInstance(); } catch (Exception e) { InternalException ie = new InternalException(e.getMessage()); ie.setStackTrace(e.getStackTrace()); throw ie; } return iobj; }
private void handleGroupChange(IObject obj, Permissions newPerms) { final ExperimenterGroup group = load(obj); if (newPerms == null) { throw new ApiUsageException("PERMS cannot be null"); } final Permissions oldPerms = group.getDetails().getPermissions(); if (oldPerms.sameRights(newPerms)) { log.debug(String.format("Ignoring unchanged permissions: %s", newPerms)); return; } final Long internal = (Long) Utils.internalForm(newPerms); sql.changeGroupPermissions(obj.getId(), internal); log.info(String.format("Changed permissions for %s to %s", obj.getId(), internal)); eventlog(obj.getId(), newPerms.toString()); }
final Permissions newPermissions = Utils.toPermissions(perm1); final boolean isToGroupReadable = newPermissions.isGranted(Permissions.Role.GROUP, Permissions.Right.READ); if (isToGroupReadable) {
Utils.closeQuietly(stream); if (rfs != null) { rfs.close();