⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ddbaseimpl.java

📁 java 文件下载器。可自定义
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
					catch (Throwable e)
					{
						Debug.printStackTrace(e);
					}
				}
			}
		}
		class_mon.exit();
		break MISSING_BLOCK_LABEL_119;
		Exception exception;
		exception;
		class_mon.exit();
		throw exception;
		return dht_use_accessor;
	}

	public boolean isAvailable()
	{
		DHTPlugin dht = grabDHT();
		if (dht == null)
			return false;
		else
			return dht.isEnabled();
	}

	public boolean isExtendedUseAllowed()
	{
		DHTPlugin dht = grabDHT();
		if (dht == null)
			return false;
		else
			return dht.isExtendedUseAllowed();
	}

	public DistributedDatabaseContact getLocalContact()
	{
		DHTPlugin dht = grabDHT();
		if (dht == null)
			return null;
		else
			return new DDBaseContactImpl(this, dht.getLocalAddress());
	}

	protected void throwIfNotAvailable()
		throws DistributedDatabaseException
	{
		if (!isAvailable())
			throw new DistributedDatabaseException("DHT not available");
		else
			return;
	}

	protected DHTPlugin getDHT()
		throws DistributedDatabaseException
	{
		throwIfNotAvailable();
		return grabDHT();
	}

	protected void log(String str)
	{
		DHTPlugin dht = grabDHT();
		if (dht != null)
			dht.log(str);
	}

	public DistributedDatabaseKey createKey(Object key)
		throws DistributedDatabaseException
	{
		throwIfNotAvailable();
		return new DDBaseKeyImpl(key);
	}

	public DistributedDatabaseKey createKey(Object key, String description)
		throws DistributedDatabaseException
	{
		throwIfNotAvailable();
		return new DDBaseKeyImpl(key, description);
	}

	public DistributedDatabaseValue createValue(Object value)
		throws DistributedDatabaseException
	{
		throwIfNotAvailable();
		return new DDBaseValueImpl(new DDBaseContactImpl(this, getDHT().getLocalAddress()), value, SystemTime.getCurrentTime(), -1L);
	}

	public DistributedDatabaseContact importContact(InetSocketAddress address)
		throws DistributedDatabaseException
	{
		throwIfNotAvailable();
		DHTPluginContact contact = getDHT().importContact(address);
		if (contact == null)
			throw new DistributedDatabaseException((new StringBuilder()).append("import of '").append(address).append("' failed").toString());
		else
			return new DDBaseContactImpl(this, contact);
	}

	public void write(DistributedDatabaseListener listener, DistributedDatabaseKey key, DistributedDatabaseValue value)
		throws DistributedDatabaseException
	{
		write(listener, key, new DistributedDatabaseValue[] {
			value
		});
	}

	public void write(DistributedDatabaseListener listener, DistributedDatabaseKey key, DistributedDatabaseValue values[])
		throws DistributedDatabaseException
	{
		throwIfNotAvailable();
		for (int i = 0; i < values.length; i++)
			if (((DDBaseValueImpl)values[i]).getBytes().length > DDBaseValueImpl.MAX_VALUE_SIZE)
				throw new DistributedDatabaseException((new StringBuilder()).append("Value size limited to ").append(DDBaseValueImpl.MAX_VALUE_SIZE).append(" bytes").toString());

		if (values.length == 0)
			delete(listener, key);
		else
		if (values.length == 1)
		{
			getDHT().put(((DDBaseKeyImpl)key).getBytes(), key.getDescription(), ((DDBaseValueImpl)values[0]).getBytes(), (byte)0, new listenerMapper(listener, 1, key, 0L, false, false));
		} else
		{
			byte current_key[] = ((DDBaseKeyImpl)key).getBytes();
			byte payload[] = new byte[512];
			int payload_length = 1;
			for (int pos = 0; pos < values.length;)
			{
				DDBaseValueImpl value = (DDBaseValueImpl)values[pos];
				byte bytes[] = value.getBytes();
				int len = bytes.length;
				if (payload_length + len < payload.length - 2)
				{
					payload[payload_length++] = (byte)((len & 0xff00) >> 8);
					payload[payload_length++] = (byte)(len & 0xff);
					System.arraycopy(bytes, 0, payload, payload_length, len);
					payload_length += len;
					pos++;
				} else
				{
					payload[0] = 1;
					byte copy[] = new byte[payload_length];
					System.arraycopy(payload, 0, copy, 0, copy.length);
					byte f_current_key[] = current_key;
					getDHT().put(f_current_key, key.getDescription(), copy, (byte)4, new listenerMapper(listener, 1, key, 0L, false, false));
					payload_length = 1;
					current_key = (new SHA1Simple()).calculateHash(current_key);
				}
			}

			if (payload_length > 1)
			{
				payload[0] = 0;
				byte copy[] = new byte[payload_length];
				System.arraycopy(payload, 0, copy, 0, copy.length);
				byte f_current_key[] = current_key;
				getDHT().put(f_current_key, key.getDescription(), copy, (byte)4, new listenerMapper(listener, 1, key, 0L, false, false));
			}
		}
	}

	public void read(DistributedDatabaseListener listener, DistributedDatabaseKey key, long timeout)
		throws DistributedDatabaseException
	{
		read(listener, key, timeout, 0);
	}

	public void read(DistributedDatabaseListener listener, DistributedDatabaseKey key, long timeout, int options)
		throws DistributedDatabaseException
	{
		throwIfNotAvailable();
		boolean exhaustive = (options & 1) != 0;
		boolean high_priority = (options & 2) != 0;
		getDHT().get(((DDBaseKeyImpl)key).getBytes(), key.getDescription(), (byte)0, 256, timeout, exhaustive, high_priority, new listenerMapper(listener, 2, key, timeout, exhaustive, high_priority));
	}

	public void readKeyStats(DistributedDatabaseListener listener, DistributedDatabaseKey key, long timeout)
		throws DistributedDatabaseException
	{
		throwIfNotAvailable();
		getDHT().get(((DDBaseKeyImpl)key).getBytes(), key.getDescription(), (byte)8, 256, timeout, false, false, new listenerMapper(listener, 6, key, timeout, false, false));
	}

	public void delete(DistributedDatabaseListener listener, DistributedDatabaseKey key)
		throws DistributedDatabaseException
	{
		throwIfNotAvailable();
		getDHT().remove(((DDBaseKeyImpl)key).getBytes(), key.getDescription(), new listenerMapper(listener, 3, key, 0L, false, false));
	}

	public void delete(DistributedDatabaseListener listener, DistributedDatabaseKey key, DistributedDatabaseContact targets[])
		throws DistributedDatabaseException
	{
		throwIfNotAvailable();
		DHTPluginContact plugin_targets[] = new DHTPluginContact[targets.length];
		for (int i = 0; i < targets.length; i++)
			plugin_targets[i] = ((DDBaseContactImpl)targets[i]).getContact();

		getDHT().remove(plugin_targets, ((DDBaseKeyImpl)key).getBytes(), key.getDescription(), new listenerMapper(listener, 3, key, 0L, false, false));
	}

	public void addTransferHandler(final DistributedDatabaseTransferType type, final DistributedDatabaseTransferHandler handler)
		throws DistributedDatabaseException
	{
		throwIfNotAvailable();
		HashWrapper type_key = DDBaseHelpers.getKey(type.getClass());
		if (transfer_map.get(type_key) != null)
		{
			throw new DistributedDatabaseException((new StringBuilder()).append("Handler for class '").append(type.getClass().getName()).append("' already defined").toString());
		} else
		{
			transfer_map.put(type_key, handler);
			final String handler_name = type != torrent_transfer ? "Plugin Defined" : "Torrent Transfer";
			getDHT().registerHandler(type_key.getHash(), new DHTPluginTransferHandler() {

				final String val$handler_name;
				final DistributedDatabaseTransferHandler val$handler;
				final DistributedDatabaseTransferType val$type;
				final DDBaseImpl this$0;

				public String getName()
				{
					return handler_name;
				}

				public byte[] handleRead(DHTPluginContact originator, byte xfer_key[])
				{
					DDBaseValueImpl res = (DDBaseValueImpl)handler.read(new DDBaseContactImpl(DDBaseImpl.this, originator), type, new DDBaseKeyImpl(xfer_key));
					if (res == null)
						return null;
					return res.getBytes();
					Throwable e;
					e;
					Debug.printStackTrace(e);
					return null;
				}

				public void handleWrite(DHTPluginContact originator, byte xfer_key[], byte value[])
				{
					try
					{
						DDBaseContactImpl contact = new DDBaseContactImpl(DDBaseImpl.this, originator);
						handler.write(contact, type, new DDBaseKeyImpl(xfer_key), new DDBaseValueImpl(contact, value, SystemTime.getCurrentTime(), -1L));
					}
					catch (Throwable e)
					{
						Debug.printStackTrace(e);
					}
				}

			
			{
				this$0 = DDBaseImpl.this;
				handler_name = s;
				handler = distributeddatabasetransferhandler;
				type = distributeddatabasetransfertype;
				super();
			}
			});
			return;
		}
	}

	public DistributedDatabaseTransferType getStandardTransferType(int standard_type)
		throws DistributedDatabaseException
	{
		if (standard_type == 1)
			return torrent_transfer;
		else
			throw new DistributedDatabaseException("unknown type");
	}

	protected DistributedDatabaseValue read(DDBaseContactImpl contact, final DistributedDatabaseProgressListener listener, DistributedDatabaseTransferType type, DistributedDatabaseKey key, long timeout)
		throws DistributedDatabaseException
	{
		if (type == torrent_transfer)
			return torrent_transfer.read(contact, listener, type, key, timeout);
		DHTPluginContact plugin_contact = contact.getContact();
		byte data[] = plugin_contact.read(new DHTPluginProgressListener() {

			final DistributedDatabaseProgressListener val$listener;
			final DDBaseImpl this$0;

			public void reportSize(long size)
			{
				listener.reportSize(size);
			}

			public void reportActivity(String str)
			{
				listener.reportActivity(str);
			}

			public void reportCompleteness(int percent)
			{
				listener.reportCompleteness(percent);
			}

			
			{
				this$0 = DDBaseImpl.this;
				listener = distributeddatabaseprogresslistener;
				super();
			}
		}, DDBaseHelpers.getKey(type.getClass()).getHash(), ((DDBaseKeyImpl)key).getBytes(), timeout);
		if (data == null)
			return null;
		else
			return new DDBaseValueImpl(contact, data, SystemTime.getCurrentTime(), -1L);
	}

	public void addListener(DistributedDatabaseListener l)
	{
		listeners.add(l);
	}

	public void removeListener(DistributedDatabaseListener l)
	{
		listeners.remove(l);
	}


}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -