private Blob loadVaultJson(JSONObject jsonObject, String regionId, String baseUrl) throws JSONException { String vaultName = jsonObject.getString("VaultName"); String url; if (baseUrl.endsWith(vaultName)) { url = baseUrl; } else { url = baseUrl + "/" + vaultName; } String creationDate = jsonObject.getString("CreationDate"); long creationTs = parseTimestamp(creationDate); if (jsonObject.has("SizeInBytes") && !jsonObject.isNull("SizeInBytes")) { Storage<Byte> storage = new Storage<Byte>(jsonObject.getLong("SizeInBytes"), Storage.BYTE); // somewhat dangerous: we want to specify a size for the vault, but currently // dasein-core only allows this specified on the Blob.getInstance() intended for // objects. It has a @Nonnull decorator for objectName, but we pass a null value // here. Currently in the implementation it does not matter. //noinspection ConstantConditions return Blob.getInstance(regionId, url, vaultName, null, creationTs, storage); } return Blob.getInstance(regionId, url, vaultName, creationTs); }
/** * Converts a LOB to the equivalent Java type, i.e. <code>Clob</code> to <code>String</code> and * <code>Blob</code> to <code>byte[]</code>. If the value passed is not a LOB object, it is left * unchanged and no exception is thrown; the idea is to transparently convert only LOBs. * * @param value an object that may be a LOB * @return if the value was a LOB, the equivalent Java object, otherwise the original value * @throws SQLException if an error occurs while reading the LOB contents */ public static Object convertLOB(Object value) throws SQLException { if (value instanceof Clob) { Clob c = (Clob) value; return c.getSubString(1, (int) c.length()); } if (value instanceof Blob) { Blob b = (Blob) value; return b.getBytes(1, (int) b.length()); } return value; }
/** * {@collect.stats} Constructs a <code>SerialBlob</code> object that is a serialized version of * the given <code>Blob</code> object. * * <p>The new <code>SerialBlob</code> object is initialized with the data from the <code>Blob * </code> object; therefore, the <code>Blob</code> object should have previously brought the SQL * <code>BLOB</code> value's data over to the client from the database. Otherwise, the new <code> * SerialBlob</code> object will contain no data. * * @param blob the <code>Blob</code> object from which this <code>SerialBlob</code> object is to * be constructed; cannot be null. * @throws SerialException if an error occurs during serialization * @throws SQLException if the <code>Blob</code> passed to this to this constructor is a <code> * null</code>. * @see java.sql.Blob */ public SerialBlob(Blob blob) throws SerialException, SQLException { if (blob == null) { throw new SQLException("Cannot instantiate a SerialBlob " + "object with a null Blob object"); } len = blob.length(); buf = blob.getBytes(1, (int) len); this.blob = blob; // if ( len < 10240000) // len = 10240000; origLen = len; }
@Override public @Nonnull Blob createBucket(@Nonnull String bucketName, boolean findFreeName) throws InternalException, CloudException { APITrace.begin(getProvider(), "Blob.createBucket"); try { if (bucketName.contains("/")) { throw new OperationNotSupportedException("Nested buckets are not supported"); } String regionId = getContext().getRegionId(); if (regionId == null) { throw new InternalException("No region ID was specified for this request"); } GlacierMethod method = GlacierMethod.build(getProvider(), GlacierAction.CREATE_VAULT) .vaultId(bucketName) .toMethod(); method.invoke(); String url = method.getUrl(); return Blob.getInstance(regionId, url, bucketName, System.currentTimeMillis()); } finally { APITrace.end(); } }
public CacheItemHolder mapRow(ResultSet rs, Connection connection) throws SQLException { URI uri = URI.create(rs.getString("uri")); Vary vary = convertToVary(rs.getString("vary")); Blob blob = rs.getBlob("payload"); Payload payload = null; if (blob != null && !rs.wasNull()) { payload = new InputStreamPayload( new ResultSetInputStream(rs, connection, blob.getBinaryStream()), MIMEType.valueOf(rs.getString("mimetype"))); } Status status = Status.valueOf(rs.getInt("status")); Headers headers = convertToHeaders(rs.getString("headers")); DateTime cacheTime = new DateTime(rs.getTimestamp("cachetime").getTime()); HTTPResponse response = new HTTPResponse(payload, status, headers); return new CacheItemHolder(uri, vary, new CacheItem(rewriteResponse(response), cacheTime)); }
@Override public String getDigest() throws IOException { InputStream inputStream = new FileInputStream(mBlob.getFile()); try { return Utils.computeDigest(inputStream); } finally { IOUtils.closeQuietly(inputStream); } }
@Override public boolean isCompressed() throws IOException { InputStream inputStream = new BufferedInputStream(new FileInputStream(mBlob.getFile())); try { return Utils.isGzipped(inputStream); } finally { IOUtils.closeQuietly(inputStream); } }
@Override public InputStream getStream() throws IOException { if (blob == null) { synchronized (this) { if (blob == null) { blob = session.getFile(ref); } } } return blob.getStream(); }
@Override protected void evolve() { super.evolve(); Char ch; for (int i = 0; i < LENGTH; i++) { if (cur[i] > 0 && (ch = Actor.findChar(i)) != null) { Buff.prolong(ch, Paralysis.class, Paralysis.duration(ch)); } } }
@Override protected void evolve() { super.evolve(); Char ch; for (int i = 0; i < LENGTH; i++) { if (cur[i] > 0 && (ch = Actor.findChar(i)) != null) { if (!ch.immunities().contains(this.getClass())) Buff.prolong(ch, Paralysis.class, Paralysis.duration(ch) / 5); } } }
private Blob loadArchiveJson(JSONObject jsonObject, String bucket, String regionId) throws JSONException { String archiveId = jsonObject.getString("ArchiveId"); Storage<Byte> size = new Storage<Byte>(jsonObject.getLong("Size"), Storage.BYTE); return Blob.getInstance( regionId, archiveId, bucket, archiveId, parseTimestamp(jsonObject.getString("CreationDate")), size); }
@Override protected void evolve() { super.evolve(); int levelDamage = 5 + Dungeon.depth * 5; Char ch; for (int i = 0; i < LENGTH; i++) { if (cur[i] > 0 && (ch = Actor.findChar(i)) != null) { int damage = (ch.HT + levelDamage) / 40; if (damage < 1) { damage = 1; } ch.damage(damage, this); } } Blob blob = Dungeon.level.blobs.get(ParalyticGas.class); if (blob != null) { int par[] = blob.cur; for (int i = 0; i < LENGTH; i++) { int t = cur[i]; int p = par[i]; if (p >= t) { volume -= t; cur[i] = 0; } else { blob.volume -= p; par[i] = 0; } } } }
private void testReadBlob(boolean close) throws Exception { byte[] result = null; String data = "LZW"; when(blob.getBinaryStream()).thenReturn(new ByteArrayInputStream(data.getBytes())); if (close == true) { result = TypeHandlerUtils.readBlob(blob); } else { result = TypeHandlerUtils.readBlob(blob, false); } Assert.assertEquals(data, new String(result)); }
@Override protected void evolve() { super.evolve(); Char ch; int cell; for (int i = area.left; i < area.right; i++) { for (int j = area.top; j < area.bottom; j++) { cell = i + j * Dungeon.level.width(); if (cur[cell] > 0 && (ch = Actor.findChar(cell)) != null) { if (!ch.immunities().contains(this.getClass())) Buff.prolong(ch, Paralysis.class, Paralysis.duration(ch) / 5); } } } }
public static long blob2OutputStream(final Blob blob, final PooledBytesOutputStream os) { if (null == blob) { return 0; } final InputStream is = blob.genInputStream(); if (null != is) { try { return inputStream2OutputStream(is, os); } finally { try { is.close(); } catch (Throwable e) { } } } else { return 0; } }
public static long blob2DataOutput( final Blob blob, final DataOutput output, final BytesPool pool) { if (null == blob) { return 0; } final InputStream is = blob.genInputStream(); if (null != is) { try { return inputStream2DataOutput(is, output, pool); } finally { try { is.close(); } catch (Throwable e) { } } } else { return 0; } }
@Override protected void evolve() { super.evolve(); if (volume > 0) { boolean mapUpdated = false; for (int i = 0; i < LENGTH; i++) { if (off[i] > 0) { int c = Dungeon.level.map[i]; int c1 = c; if (c == Terrain.EMPTY || c == Terrain.EMBERS || c == Terrain.EMPTY_DECO) { c1 = cur[i] > 9 ? Terrain.HIGH_GRASS : Terrain.GRASS; } else if (c == Terrain.GRASS && cur[i] > 9) { c1 = Terrain.HIGH_GRASS; } if (c1 != c) { Level.set(i, Terrain.HIGH_GRASS); mapUpdated = true; GameScene.updateMap(i); if (Dungeon.visible[i]) { GameScene.discoverTile(i, c); } } Char ch = Actor.findChar(i); if (ch != null) { Buff.prolong(ch, Roots.class, TICK); } } } if (mapUpdated) { Dungeon.observe(); } } }
@Override public void use(BlobEmitter emitter) { super.use(emitter); emitter.pour(WebParticle.FACTORY, 0.4f); }
@Override public InputStream getInputStream() throws IOException { return new FileInputStream(mBlob.getFile()); }
private void testConvertBlobPrepare() throws SQLException, MjdbcException { // when(conn.createBlob()).thenReturn(blob); when(MappingUtils.invokeFunction(conn, "createBlob", new Class[] {}, new Object[] {})) .thenReturn(blob); when(blob.setBinaryStream(1)).thenReturn(output); }
@Override public void use(BlobEmitter emitter) { super.use(emitter); emitter.pour(Speck.factory(Speck.PARALYSIS), 0.6f); }
@Override public void use(BlobEmitter emitter) { super.use(emitter); emitter.start(ShaftParticle.FACTORY, 0.9f, 0); }
/** * {@collect.stats} Returns the position in this <code>SerialBlob</code> object where the given * <code>Blob</code> object begins, starting the search at the specified position. * * @param pattern the <code>Blob</code> object for which to search; * @param start the position of the byte in this <code>SerialBlob</code> object from which to * begin the search; the first position is <code>1</code>; must not be less than <code>1 * </code> nor greater than the length of this <code>SerialBlob</code> object * @return the position in this <code>SerialBlob</code> object where the given <code>Blob</code> * object begins, starting at the specified position; <code>-1</code> if the pattern is not * found or the given starting position is out of bounds; position numbering for the return * value starts at <code>1</code> * @throws SerialException if an error occurs when serializing the blob * @throws SQLException if there is an error accessing the <code>BLOB</code> value from the * database */ public long position(Blob pattern, long start) throws SerialException, SQLException { return position(pattern.getBytes(1, (int) (pattern.length())), start); }
/* $if ZimbraVersion >= 7.1.3 $ */ public void renameTo(String newPath) throws IOException { mBlob.renameTo(newPath); }
@Override public String toString() { return mBlob.toString(); }
@Override public long getRawSize() throws IOException { return mBlob.getSize(); }
public InternalOverrideBlobWithMailboxInfo(Blob blob) { super(); mBlob = blob; mVolumeId = blob.getVolumeId(); }
@Override public File getFile() { return mBlob.getFile(); }
@Override public String getPath() { return mBlob.getKey(); }
@Override public void paintComponent(Graphics graphics) { super.paintComponent(graphics); Graphics2D g = (Graphics2D) graphics; g.setStroke(new BasicStroke(3)); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); if (image != null) { for (Blob blob : this.image.getBlobs()) { for (Point point : blob.getPoints()) { g.setColor(new Color(100, 100, 200, 20)); int length = blob.getPoints().size(); int[] xs = new int[length]; int[] ys = new int[length]; for (int i = 0; i < length; i++) { Point p = blob.getPoints().get(i); xs[i] = p.getX(); ys[i] = p.getY(); } g.fillPolygon(xs, ys, length); g.setColor(Color.green); if (blob == selectedBlob) { g.setColor(Color.red); } g.fillOval(point.getX() - 5, point.getY() - 5, 10, 10); int currentIndex = blob.getPoints().indexOf(point); Point lastPoint; if (currentIndex == 0) { lastPoint = blob.getPoints().get(blob.getPoints().size() - 1); } else { lastPoint = blob.getPoints().get(currentIndex - 1); } g.drawLine(point.getX(), point.getY(), lastPoint.getX(), lastPoint.getY()); } } if (tempPoints == null) { return; } g.setColor(Color.green); for (Point point : tempPoints) { g.fillOval(point.getX() - 5, point.getY() - 5, 10, 10); int currentIndex = tempPoints.indexOf(point); if (currentIndex > 0) { Point lastPoint = tempPoints.get(currentIndex - 1); g.setColor(Color.green); g.drawLine(point.getX(), point.getY(), lastPoint.getX(), lastPoint.getY()); } } } }