Cleanup / persistent history

This commit is contained in:
Jesse Boyd 2016-04-05 02:07:36 +10:00
parent 0dfbd44c72
commit ba04eb9fc8
92 changed files with 938 additions and 2400 deletions

1
.gitignore vendored
View File

@ -12,3 +12,4 @@
/.idea
/forge/build
forge/.gradle/gradle.log
*.log

View File

@ -1,13 +1,12 @@
package com.boydti.fawe.bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import com.boydti.fawe.Fawe;
import com.boydti.fawe.config.BBC;
import com.boydti.fawe.object.FaweCommand;
import com.boydti.fawe.object.FawePlayer;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
public class BukkitCommand implements CommandExecutor {

View File

@ -1,13 +1,11 @@
package com.boydti.fawe.bukkit;
import com.boydti.fawe.util.TaskManager;
import java.util.HashMap;
import org.apache.commons.lang.mutable.MutableInt;
import org.bukkit.Bukkit;
import org.bukkit.plugin.Plugin;
import com.boydti.fawe.util.TaskManager;
public class BukkitTaskMan extends TaskManager {
private final Plugin plugin;

View File

@ -7,7 +7,6 @@ import com.boydti.fawe.bukkit.regions.FactionsFeature;
import com.boydti.fawe.bukkit.regions.FactionsUUIDFeature;
import com.boydti.fawe.bukkit.regions.GriefPreventionFeature;
import com.boydti.fawe.bukkit.regions.PlotMeFeature;
import com.boydti.fawe.bukkit.regions.PlotSquaredFeature;
import com.boydti.fawe.bukkit.regions.PreciousStonesFeature;
import com.boydti.fawe.bukkit.regions.ResidenceFeature;
import com.boydti.fawe.bukkit.regions.TownyFeature;
@ -298,17 +297,6 @@ public class FaweBukkit extends JavaPlugin implements IFawe, Listener {
} else {
Fawe.debug("Plugin 'GriefPrevention' not found. GriefPrevention features disabled.");
}
final Plugin plotsquaredPlugin = Bukkit.getServer().getPluginManager().getPlugin("PlotSquared");
if ((plotsquaredPlugin != null) && plotsquaredPlugin.isEnabled()) {
try {
managers.add(new PlotSquaredFeature(plotsquaredPlugin, this));
Fawe.debug("Plugin 'PlotSquared' found. Using it now.");
} catch (final Throwable e) {
e.printStackTrace();
}
} else {
Fawe.debug("Plugin 'PlotSquared' not found. PlotSquared features disabled.");
}
final Plugin preciousstonesPlugin = Bukkit.getServer().getPluginManager().getPlugin("PreciousStones");
if ((preciousstonesPlugin != null) && preciousstonesPlugin.isEnabled()) {
try {

View File

@ -1,7 +1,6 @@
package com.boydti.fawe.bukkit;
import net.milkbowl.vault.permission.Permission;
import org.bukkit.Bukkit;
import org.bukkit.plugin.RegisteredServiceProvider;

View File

@ -1,17 +1,5 @@
package com.boydti.fawe.bukkit;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import com.boydti.fawe.Fawe;
import com.boydti.fawe.config.BBC;
import com.boydti.fawe.config.Settings;
@ -26,6 +14,16 @@ import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.LocalWorld;
import com.sk89q.worldedit.bukkit.BukkitUtil;
import com.sk89q.worldedit.regions.Region;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
/**
* Kinda a really messy class I just copied over from an old project<br>

View File

@ -1,8 +1,7 @@
package com.boydti.fawe.bukkit.regions;
import org.bukkit.entity.Player;
import com.boydti.fawe.regions.FaweMaskManager;
import org.bukkit.entity.Player;
public abstract class BukkitMaskManager extends FaweMaskManager<Player> {

View File

@ -1,16 +1,15 @@
package com.boydti.fawe.bukkit.regions;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.plugin.Plugin;
import com.boydti.fawe.bukkit.FaweBukkit;
import com.boydti.fawe.object.FawePlayer;
import com.massivecraft.factions.entity.BoardColl;
import com.massivecraft.factions.entity.Faction;
import com.massivecraft.massivecore.ps.PS;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.plugin.Plugin;
public class FactionsFeature extends BukkitMaskManager implements Listener {
FaweBukkit plugin;

View File

@ -1,12 +1,5 @@
package com.boydti.fawe.bukkit.regions;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.plugin.Plugin;
import com.boydti.fawe.bukkit.FaweBukkit;
import com.boydti.fawe.object.FawePlayer;
import com.boydti.fawe.object.RegionWrapper;
@ -14,6 +7,12 @@ import com.boydti.fawe.util.Perm;
import com.massivecraft.factions.Board;
import com.massivecraft.factions.FLocation;
import com.massivecraft.factions.Faction;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.plugin.Plugin;
public class FactionsUUIDFeature extends BukkitMaskManager implements Listener {
private final Board instance;

View File

@ -1,16 +1,14 @@
package com.boydti.fawe.bukkit.regions;
import com.boydti.fawe.bukkit.FaweBukkit;
import com.boydti.fawe.object.FawePlayer;
import me.ryanhamshire.GriefPrevention.Claim;
import me.ryanhamshire.GriefPrevention.GriefPrevention;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.plugin.Plugin;
import com.boydti.fawe.bukkit.FaweBukkit;
import com.boydti.fawe.object.FawePlayer;
public class GriefPreventionFeature extends BukkitMaskManager implements Listener {
FaweBukkit plugin;
Plugin griefprevention;

View File

@ -1,10 +1,5 @@
package com.boydti.fawe.bukkit.regions;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.plugin.Plugin;
import com.boydti.fawe.bukkit.FaweBukkit;
import com.boydti.fawe.object.FawePlayer;
import com.worldcretornica.plotme_core.Plot;
@ -12,6 +7,10 @@ import com.worldcretornica.plotme_core.PlotMe_Core;
import com.worldcretornica.plotme_core.bukkit.PlotMe_CorePlugin;
import com.worldcretornica.plotme_core.bukkit.api.BukkitPlayer;
import com.worldcretornica.plotme_core.bukkit.api.BukkitWorld;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.plugin.Plugin;
public class PlotMeFeature extends BukkitMaskManager implements Listener {
FaweBukkit plugin;

View File

@ -1,85 +0,0 @@
package com.boydti.fawe.bukkit.regions;
import java.util.HashSet;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.plugin.Plugin;
import com.boydti.fawe.bukkit.FaweBukkit;
import com.boydti.fawe.object.FawePlayer;
import com.boydti.fawe.object.RegionWrapper;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.plotsquared.bukkit.BukkitMain;
public class PlotSquaredFeature extends BukkitMaskManager implements Listener {
FaweBukkit plugin;
public PlotSquaredFeature(final Plugin plotPlugin, final FaweBukkit p3) {
super(plotPlugin.getName());
this.plugin = p3;
BukkitMain.worldEdit = null;
PS.get().worldedit = null;
}
@Override
public BukkitMask getMask(final FawePlayer<Player> fp) {
final PlotPlayer pp = PlotPlayer.wrap(fp.parent);
Plot plot = pp.getCurrentPlot();
if (plot == null) {
final com.intellectualcrafters.plot.object.Location loc = pp.getLocation();
final String world = loc.getWorld();
int min = Integer.MAX_VALUE;
for (final Plot p : pp.getPlots()) {
if (p.getArea().worldname.equals(world)) {
final double d = p.getHome().getEuclideanDistanceSquared(loc);
if (d < min) {
min = (int) d;
plot = p;
}
}
}
}
if (plot != null) {
final PlotId id = plot.getId();
boolean hasPerm = false;
if (plot.owner != null) {
if (plot.owner.equals(pp.getUUID())) {
hasPerm = true;
} else if (plot.isAdded(pp.getUUID()) && pp.hasPermission("fawe.plotsquared.member")) {
hasPerm = true;
}
if (hasPerm) {
final World world = fp.parent.getWorld();
final com.intellectualcrafters.plot.object.RegionWrapper region = plot.getLargestRegion();
final HashSet<com.intellectualcrafters.plot.object.RegionWrapper> regions = plot.getRegions();
final Location pos1 = new Location(world, region.minX, 0, region.minZ);
final Location pos2 = new Location(world, region.maxX, 256, region.maxZ);
final HashSet<RegionWrapper> faweRegions = new HashSet<RegionWrapper>();
for (final com.intellectualcrafters.plot.object.RegionWrapper current : regions) {
faweRegions.add(new RegionWrapper(current.minX, current.maxX, current.minZ, current.maxZ));
}
return new BukkitMask(pos1, pos2) {
@Override
public String getName() {
return "PLOT^2:" + id;
}
@Override
public HashSet<RegionWrapper> getRegions() {
return faweRegions;
}
};
}
}
}
return null;
}
}

View File

@ -1,19 +1,16 @@
package com.boydti.fawe.bukkit.regions;
import com.boydti.fawe.bukkit.FaweBukkit;
import com.boydti.fawe.object.FawePlayer;
import java.util.List;
import net.sacredlabyrinth.Phaed.PreciousStones.FieldFlag;
import net.sacredlabyrinth.Phaed.PreciousStones.PreciousStones;
import net.sacredlabyrinth.Phaed.PreciousStones.vectors.Field;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.plugin.Plugin;
import com.boydti.fawe.bukkit.FaweBukkit;
import com.boydti.fawe.object.FawePlayer;
public class PreciousStonesFeature extends BukkitMaskManager implements Listener {
FaweBukkit plugin;
Plugin preciousstones;

View File

@ -1,15 +1,14 @@
package com.boydti.fawe.bukkit.regions;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.plugin.Plugin;
import com.bekvon.bukkit.residence.Residence;
import com.bekvon.bukkit.residence.protection.ClaimedResidence;
import com.bekvon.bukkit.residence.protection.CuboidArea;
import com.boydti.fawe.bukkit.FaweBukkit;
import com.boydti.fawe.object.FawePlayer;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.plugin.Plugin;
public class ResidenceFeature extends BukkitMaskManager implements Listener {
FaweBukkit plugin;

View File

@ -1,11 +1,5 @@
package com.boydti.fawe.bukkit.regions;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.plugin.Plugin;
import com.boydti.fawe.bukkit.FaweBukkit;
import com.boydti.fawe.object.FawePlayer;
import com.palmergames.bukkit.towny.Towny;
@ -13,6 +7,11 @@ import com.palmergames.bukkit.towny.object.PlayerCache;
import com.palmergames.bukkit.towny.object.TownBlock;
import com.palmergames.bukkit.towny.object.TownyUniverse;
import com.palmergames.bukkit.towny.object.WorldCoord;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.plugin.Plugin;
public class TownyFeature extends BukkitMaskManager implements Listener {
FaweBukkit plugin;

View File

@ -1,11 +1,5 @@
package com.boydti.fawe.bukkit.regions;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.plugin.Plugin;
import com.boydti.fawe.bukkit.FaweBukkit;
import com.boydti.fawe.object.FawePlayer;
import com.sk89q.worldedit.BlockVector;
@ -13,6 +7,11 @@ import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.protection.ApplicableRegionSet;
import com.sk89q.worldguard.protection.managers.RegionManager;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.plugin.Plugin;
public class Worldguard extends BukkitMaskManager implements Listener {
WorldGuardPlugin worldguard;

View File

@ -1,9 +1,5 @@
package com.boydti.fawe.bukkit.v1_8;
import static com.boydti.fawe.util.ReflectionUtils.getRefClass;
import org.bukkit.Bukkit;
import com.boydti.fawe.bukkit.v0.BukkitEditSessionWrapper_0;
import com.boydti.fawe.util.ReflectionUtils.RefClass;
import com.boydti.fawe.util.ReflectionUtils.RefField;
@ -11,6 +7,10 @@ import com.boydti.fawe.util.ReflectionUtils.RefMethod;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.blocks.BlockType;
import org.bukkit.Bukkit;
import static com.boydti.fawe.util.ReflectionUtils.getRefClass;
public class BukkitEditSessionWrapper_1_8 extends BukkitEditSessionWrapper_0 {

View File

@ -10,7 +10,6 @@ import com.boydti.fawe.config.Settings;
import com.boydti.fawe.object.FawePlayer;
import com.boydti.fawe.regions.general.PlotSquaredFeature;
import com.boydti.fawe.util.Lag;
import com.boydti.fawe.util.MainUtil;
import com.boydti.fawe.util.MemUtil;
import com.boydti.fawe.util.TaskManager;
import com.boydti.fawe.util.WEManager;
@ -155,8 +154,8 @@ public class Fawe {
this.IMP.startMetrics();
}
// Delete old history
MainUtil.deleteDirectory(new File(IMP.getDirectory(), "history"));
// // Delete old history
// MainUtil.deleteDirectory(new File(IMP.getDirectory(), "history"));
// Delayed setup
TaskManager.IMP.later(new Runnable() {

View File

@ -1,12 +1,11 @@
package com.boydti.fawe.command;
import java.io.File;
import com.boydti.fawe.Fawe;
import com.boydti.fawe.FaweAPI;
import com.boydti.fawe.config.BBC;
import com.boydti.fawe.object.FaweCommand;
import com.boydti.fawe.object.FawePlayer;
import java.io.File;
public class Stream extends FaweCommand {

View File

@ -1,6 +1,7 @@
package com.boydti.fawe.config;
import com.boydti.fawe.Fawe;
import com.boydti.fawe.configuration.file.YamlConfiguration;
import com.boydti.fawe.object.FawePlayer;
import com.boydti.fawe.util.StringMan;
import java.io.File;
@ -8,7 +9,6 @@ import java.util.EnumSet;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
import com.boydti.fawe.configuration.file.YamlConfiguration;
public enum BBC {

View File

@ -1,5 +1,7 @@
package com.boydti.fawe.config;
import com.boydti.fawe.configuration.file.YamlConfiguration;
import com.sk89q.worldedit.LocalSession;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
@ -8,10 +10,6 @@ import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import com.boydti.fawe.configuration.file.YamlConfiguration;
import com.sk89q.worldedit.LocalSession;
public class Settings {
public static int MAX_BLOCKSTATES = 1337;
@ -26,7 +24,7 @@ public class Settings {
public static boolean ENABLE_HARD_LIMIT = true;
public static boolean STORE_HISTORY_ON_DISK = false;
public static int COMPRESSION_LEVEL = 0;
public static int BUFFER_SIZE = 59049;
public static int BUFFER_SIZE = 531441;
public static boolean METRICS = true;
public static void setup(final File file) {

View File

@ -1,7 +1,5 @@
package com.boydti.fawe.configuration;
import com.boydti.fawe.configuration.ConfigurationOptions;
import com.boydti.fawe.configuration.ConfigurationSection;
import java.util.Map;
/**

View File

@ -1,7 +1,5 @@
package com.boydti.fawe.configuration;
import com.boydti.fawe.configuration.Configuration;
/**
* Various settings for controlling the input and output of a {@link
* com.boydti.fawe.configuration.Configuration}

View File

@ -1,6 +1,5 @@
package com.boydti.fawe.configuration;
import com.boydti.fawe.configuration.Configuration;
import java.util.List;
import java.util.Map;
import java.util.Set;

View File

@ -1,9 +1,5 @@
package com.boydti.fawe.configuration;
import com.boydti.fawe.configuration.Configuration;
import com.boydti.fawe.configuration.ConfigurationSection;
import com.boydti.fawe.configuration.MemoryConfigurationOptions;
import com.boydti.fawe.configuration.MemorySection;
import java.util.Map;
/**

View File

@ -1,7 +1,5 @@
package com.boydti.fawe.configuration;
import com.boydti.fawe.configuration.ConfigurationOptions;
/**
* Various settings for controlling the input and output of a {@link
* com.boydti.fawe.configuration.MemoryConfiguration}

View File

@ -1,6 +1,5 @@
package com.boydti.fawe.configuration;
import com.boydti.fawe.configuration.ConfigurationSection;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;

View File

@ -3,7 +3,6 @@ package com.boydti.fawe.configuration.file;
import com.boydti.fawe.configuration.Configuration;
import com.boydti.fawe.configuration.InvalidConfigurationException;
import com.boydti.fawe.configuration.MemoryConfiguration;
import com.boydti.fawe.configuration.file.FileConfigurationOptions;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;

View File

@ -1,8 +1,5 @@
package com.boydti.fawe.configuration.file;
import com.boydti.fawe.configuration.file.FileConfigurationOptions;
import com.boydti.fawe.configuration.file.YamlConfiguration;
/**
* Various settings for controlling the input and output of a {@link
* com.boydti.fawe.configuration.file.YamlConfiguration}

View File

@ -1,7 +1,5 @@
package com.boydti.fawe.configuration.serialization;
import com.boydti.fawe.configuration.serialization.DelegateDeserialization;
import com.boydti.fawe.configuration.serialization.SerializableAs;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

View File

@ -1,6 +1,5 @@
package com.boydti.fawe.configuration.serialization;
import com.boydti.fawe.configuration.serialization.ConfigurationSerializable;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

View File

@ -1,16 +1,22 @@
package com.boydti.fawe.object;
import java.util.HashSet;
import java.util.UUID;
import com.boydti.fawe.Fawe;
import com.boydti.fawe.config.Settings;
import com.boydti.fawe.object.changeset.DiskStorageHistory;
import com.boydti.fawe.util.WEManager;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.IncompleteRegionException;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.regions.RegionSelector;
import com.sk89q.worldedit.regions.selector.CuboidRegionSelector;
import com.sk89q.worldedit.world.World;
import java.io.File;
import java.util.ArrayDeque;
import java.util.HashSet;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
public abstract class FawePlayer<T> {
@ -30,6 +36,35 @@ public abstract class FawePlayer<T> {
public FawePlayer(final T parent) {
this.parent = parent;
Fawe.get().register(this);
if (getSession() == null || getPlayer() == null || session.getSize() != 0 || !Settings.STORE_HISTORY_ON_DISK) {
return;
}
try {
UUID uuid = getUUID();
for (World world : WorldEdit.getInstance().getServer().getWorlds()) {
ArrayDeque<Integer> editIds = new ArrayDeque<>();
File folder = new File(Fawe.imp().getDirectory(), "history" + File.separator + world.getName() + File.separator + uuid);
if (folder.isDirectory()) {
for (File file : folder.listFiles()) {
if (file.getName().endsWith(".bd")) {
int index = Integer.parseInt(file.getName().split("\\.")[0]);
editIds.add(index);
}
}
}
if (editIds.size() > 0) {
Fawe.debug("[FAWE] Indexing " + editIds.size() + " history objects for " + getName());
for (int index : editIds) {
DiskStorageHistory set = new DiskStorageHistory(world, uuid, index);
EditSession edit = set.toEditSession(getPlayer());
session.remember(edit);
}
}
}
} catch (Exception e) {
e.printStackTrace();
Fawe.debug("Failed to load history for: " + getName());
}
}
public abstract String getName();
@ -57,7 +92,7 @@ public abstract class FawePlayer<T> {
}
public LocalSession getSession() {
return (this.session != null || this.getPlayer() == null) ? this.session : Fawe.get().getWorldEdit().getSession(this.getPlayer());
return (this.session != null || this.getPlayer() == null) ? this.session : (session = Fawe.get().getWorldEdit().getSession(this.getPlayer()));
}
public HashSet<RegionWrapper> getCurrentRegions() {

View File

@ -12,13 +12,18 @@ import com.sk89q.jnbt.NBTOutputStream;
import com.sk89q.jnbt.NamedTag;
import com.sk89q.jnbt.Tag;
import com.sk89q.worldedit.BlockVector;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.EditSessionFactory;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.history.change.BlockChange;
import com.sk89q.worldedit.history.change.Change;
import com.sk89q.worldedit.history.change.EntityCreate;
import com.sk89q.worldedit.history.change.EntityRemove;
import com.sk89q.worldedit.history.changeset.ChangeSet;
import com.sk89q.worldedit.world.World;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
@ -28,6 +33,7 @@ import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
@ -45,11 +51,11 @@ import net.jpountz.lz4.LZ4OutputStream;
*/
public class DiskStorageHistory implements ChangeSet, FaweChangeSet {
private final File bdFile;
private final File nbtfFile;
private final File nbttFile;
private final File entfFile;
private final File enttFile;
private File bdFile;
private File nbtfFile;
private File nbttFile;
private File entfFile;
private File enttFile;
/*
* Block data
@ -85,25 +91,48 @@ public class DiskStorageHistory implements ChangeSet, FaweChangeSet {
private int ox;
private int oz;
private final AtomicInteger size;
private AtomicInteger size = new AtomicInteger();
private World world;
public DiskStorageHistory(String name) {
public DiskStorageHistory(World world, UUID uuid) {
size = new AtomicInteger();
String base = "history" + File.separator + name;
String base = "history" + File.separator + world.getName() + File.separator + uuid;
File folder = new File(Fawe.imp().getDirectory(), base);
int i;
for (i = 0;; i++) {
File test = new File(folder, i + ".bd");
if (!test.exists()) {
int max = 0;
if (folder.exists()) {
for (File file : folder.listFiles()) {
String name = file.getName().split("\\.")[0];
if (name.matches("\\d+")) {
int index = Integer.parseInt(name);
if (index > max) {
max = index;
}
}
}
}
init(world, uuid, ++max);
}
public DiskStorageHistory(World world, UUID uuid, int index) {
init(world, uuid, index);
}
public void init(World world, UUID uuid, int i) {
this.world = world;
String base = "history" + File.separator + world.getName() + File.separator + uuid;
base += File.separator + i;
nbtfFile = new File(Fawe.imp().getDirectory(), base + ".nbtf");
nbttFile = new File(Fawe.imp().getDirectory(), base + ".nbtt");
entfFile = new File(Fawe.imp().getDirectory(), base + ".entf");
enttFile = new File(Fawe.imp().getDirectory(), base + ".entt");
bdFile = new File(Fawe.imp().getDirectory(), base + ".bd");
break;
}
}
public EditSession toEditSession(Player player) {
EditSessionFactory factory = WorldEdit.getInstance().getEditSessionFactory();
EditSession edit = factory.getEditSession(world, -1, null, player);
edit.setChangeSet(this);
return edit;
}
@Override
@ -240,8 +269,6 @@ public class DiskStorageHistory implements ChangeSet, FaweChangeSet {
LZ4Compressor compressor = factory.fastCompressor();
osBD = new LZ4OutputStream(stream, Settings.BUFFER_SIZE, factory.fastCompressor());
if (Settings.COMPRESSION_LEVEL > 0) {
// Deflater deflater = new Deflater(Math.min(9, Settings.COMPRESSION_LEVEL), true);
// osBD = new DeflaterOutputStream(osBD, deflater, true);
osBD = new LZ4OutputStream(osBD, Settings.BUFFER_SIZE, factory.highCompressor());
}
ox = x;
@ -310,12 +337,12 @@ public class DiskStorageHistory implements ChangeSet, FaweChangeSet {
flush();
try {
if (bdFile.exists()) {
if (osNBTF != null) {
if (nbtfFile.exists()) {
NBTInputStream os = new NBTInputStream(new GZIPInputStream(new FileInputStream(nbtfFile)));
NamedTag tag = os.readNamedTag();
}
final NBTInputStream nbtf = osNBTF != null ? new NBTInputStream(new GZIPInputStream(new FileInputStream(nbtfFile))) : null;
final NBTInputStream nbtt = osNBTT != null ? new NBTInputStream(new GZIPInputStream(new FileInputStream(nbttFile))) : null;
final NBTInputStream nbtf = nbtfFile.exists() ? new NBTInputStream(new GZIPInputStream(new FileInputStream(nbtfFile))) : null;
final NBTInputStream nbtt = nbttFile.exists() ? new NBTInputStream(new GZIPInputStream(new FileInputStream(nbttFile))) : null;
FileInputStream fis = new FileInputStream(bdFile);
LZ4Factory factory = LZ4Factory.fastestInstance();
@ -326,7 +353,8 @@ public class DiskStorageHistory implements ChangeSet, FaweChangeSet {
} else {
gis = new LZ4InputStream(fis);
}
gis.skip(8);
ox = ((gis.read() << 24) + (gis.read() << 16) + (gis.read() << 8) + (gis.read() << 0));
oz = ((gis.read() << 24) + (gis.read() << 16) + (gis.read() << 8) + (gis.read() << 0));
return new Iterator<Change>() {
private CompoundTag lastFrom = read(nbtf);
@ -338,7 +366,9 @@ public class DiskStorageHistory implements ChangeSet, FaweChangeSet {
try {
NamedTag nt = stream.readNamedTag();
return nt != null ? ((CompoundTag) nt.getTag()) : null;
} catch (IOException e) {}
} catch (IOException e) {
e.printStackTrace();
}
}
return null;
}
@ -428,5 +458,4 @@ public class DiskStorageHistory implements ChangeSet, FaweChangeSet {
flush();
return size.get();
}
}

View File

@ -1,8 +1,5 @@
package com.boydti.fawe.object.extent;
import java.util.ArrayList;
import java.util.List;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.Vector2D;
@ -15,6 +12,8 @@ import com.sk89q.worldedit.function.operation.Operation;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.world.biome.BaseBiome;
import java.util.ArrayList;
import java.util.List;
public class NullExtent implements Extent {

View File

@ -1,11 +1,10 @@
package com.boydti.fawe.regions;
import com.boydti.fawe.object.RegionWrapper;
import com.sk89q.worldedit.BlockVector;
import java.util.Arrays;
import java.util.HashSet;
import com.boydti.fawe.object.RegionWrapper;
public class FaweMask {
private String description = null;
private BlockVector position1;

View File

@ -1,8 +1,7 @@
package com.boydti.fawe.util;
import java.util.concurrent.atomic.AtomicBoolean;
import com.boydti.fawe.config.Settings;
import java.util.concurrent.atomic.AtomicBoolean;
public class MemUtil {

View File

@ -54,7 +54,6 @@ import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.extent.MaskingExtent;
import com.sk89q.worldedit.extent.buffer.ForgetfulExtentBuffer;
import com.sk89q.worldedit.extent.inventory.BlockBag;
import com.sk89q.worldedit.extent.reorder.MultiStageReorder;
import com.sk89q.worldedit.extent.world.SurvivalModeExtent;
import com.sk89q.worldedit.function.GroundFunction;
import com.sk89q.worldedit.function.RegionMaskingFilter;
@ -152,9 +151,8 @@ public class EditSession implements Extent {
}
protected final World world;
private final FaweChangeSet changeSet;
private FaweChangeSet changeSet;
private final EditSessionWrapper wrapper;
private MultiStageReorder reorderExtent;
private @Nullable Extent changeSetExtent;
private MaskingExtent maskingExtent;
private @Nullable ProcessedWEExtent processed;
@ -243,14 +241,11 @@ public class EditSession implements Extent {
this.changeSet = new NullChangeSet();
return;
}
this.changeSet = Settings.STORE_HISTORY_ON_DISK ? new DiskStorageHistory(actor.getUniqueId().toString()) : new MemoryOptimizedHistory();
this.changeSet = Settings.STORE_HISTORY_ON_DISK ? new DiskStorageHistory(world, actor.getUniqueId()) : new MemoryOptimizedHistory();
Extent extent;
final String name = actor.getName();
final FawePlayer<Object> fp = FawePlayer.wrap(name);
final LocalSession session = fp.getSession();
if (this.fastmode = (session == null ? false : session.hasFastMode())) {
session.clearHistory();
}
if (fp.hasWorldEditBypass()) {
// Bypass skips processing and area restrictions
extent = new FastWorldEditExtent(world, this.thread);
@ -370,6 +365,11 @@ public class EditSession implements Extent {
return this.changeSet;
}
public void setChangeSet(FaweChangeSet set) {
changes = -1;
this.changeSet = set;
}
/**
* Get the maximum number of blocks that can be changed. -1 will be returned
* if it the limit disabled.
@ -398,16 +398,13 @@ public class EditSession implements Extent {
* @return whether the queue is enabled
*/
public boolean isQueueEnabled() {
return (this.reorderExtent != null) && this.reorderExtent.isEnabled();
return false;
}
/**
* Queue certain types of block for better reproduction of those blocks.
*/
public void enableQueue() {
if (this.reorderExtent != null) {
this.reorderExtent.setEnabled(true);
}
}
/**
@ -417,9 +414,6 @@ public class EditSession implements Extent {
if (this.isQueueEnabled()) {
this.flushQueue();
}
if (this.reorderExtent != null) {
this.reorderExtent.setEnabled(true);
}
}
/**

View File

@ -278,6 +278,10 @@ public class LocalSession {
return null;
}
public int getSize() {
return history.size();
}
/**
* Get the default region selector.
*

View File

@ -19,8 +19,6 @@
package com.sk89q.worldedit.command;
import static com.google.common.base.Preconditions.checkNotNull;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
@ -34,6 +32,9 @@ import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.world.registry.WorldData;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Helper class to 'bake' a transform into a clipboard.
*

View File

@ -19,20 +19,6 @@
package com.sk89q.worldedit.command;
import static com.google.common.base.Preconditions.checkNotNull;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileFilter;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Arrays;
import java.util.Comparator;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.boydti.fawe.util.SetQueue;
import com.boydti.fawe.util.TaskManager;
import com.sk89q.minecraft.util.commands.Command;
@ -59,6 +45,20 @@ import com.sk89q.worldedit.util.io.Closer;
import com.sk89q.worldedit.util.io.file.FilenameException;
import com.sk89q.worldedit.util.io.file.FilenameResolutionException;
import com.sk89q.worldedit.world.registry.WorldData;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileFilter;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Arrays;
import java.util.Comparator;
import java.util.logging.Level;
import java.util.logging.Logger;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Commands that work with schematic files.

View File

@ -19,11 +19,6 @@
package com.sk89q.worldedit.command;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.sk89q.minecraft.util.commands.Logging.LogMode.ALL;
import java.io.File;
import com.boydti.fawe.util.SetQueue;
import com.boydti.fawe.util.TaskManager;
import com.sk89q.minecraft.util.commands.Command;
@ -35,6 +30,11 @@ import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.entity.Player;
import java.io.File;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.sk89q.minecraft.util.commands.Logging.LogMode.ALL;
/**
* Commands related to scripting.

View File

@ -19,8 +19,13 @@
package com.sk89q.worldedit.function.visitor;
import static com.google.common.base.Preconditions.checkNotNull;
import com.sk89q.worldedit.BlockVector;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.function.RegionFunction;
import com.sk89q.worldedit.function.operation.Operation;
import com.sk89q.worldedit.function.operation.Operations;
import com.sk89q.worldedit.function.operation.RunContext;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collection;
@ -29,13 +34,8 @@ import java.util.List;
import java.util.Queue;
import java.util.Set;
import com.sk89q.worldedit.BlockVector;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.function.RegionFunction;
import com.sk89q.worldedit.function.operation.Operation;
import com.sk89q.worldedit.function.operation.Operations;
import com.sk89q.worldedit.function.operation.RunContext;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Performs a breadth-first search starting from points added with

View File

@ -19,14 +19,14 @@
package com.sk89q.worldedit.function.visitor;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Collection;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.function.RegionFunction;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.operation.Operations;
import java.util.Collection;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Visits adjacent points on the same X-Z plane as long as the points

View File

@ -19,17 +19,17 @@
package com.sk89q.worldedit.function.visitor;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Iterator;
import java.util.List;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.entity.Entity;
import com.sk89q.worldedit.function.EntityFunction;
import com.sk89q.worldedit.function.operation.Operation;
import com.sk89q.worldedit.function.operation.Operations;
import com.sk89q.worldedit.function.operation.RunContext;
import java.util.Iterator;
import java.util.List;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Visits entities as provided by an {@code Iterator}.

View File

@ -19,10 +19,6 @@
package com.sk89q.worldedit.function.visitor;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.List;
import com.sk89q.worldedit.Vector2D;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.function.FlatRegionFunction;
@ -30,6 +26,10 @@ import com.sk89q.worldedit.function.operation.Operation;
import com.sk89q.worldedit.function.operation.Operations;
import com.sk89q.worldedit.function.operation.RunContext;
import com.sk89q.worldedit.regions.FlatRegion;
import java.util.List;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Applies region functions to columns in a {@link FlatRegion}.

View File

@ -19,11 +19,6 @@
package com.sk89q.worldedit.function.visitor;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.List;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.Vector2D;
import com.sk89q.worldedit.WorldEditException;
@ -34,6 +29,11 @@ import com.sk89q.worldedit.function.operation.Operation;
import com.sk89q.worldedit.function.operation.Operations;
import com.sk89q.worldedit.function.operation.RunContext;
import com.sk89q.worldedit.regions.FlatRegion;
import java.util.List;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Visits the layers within a region.

View File

@ -19,12 +19,11 @@
package com.sk89q.worldedit.function.visitor;
import java.util.Collection;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.function.RegionFunction;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.operation.Operations;
import java.util.Collection;
/**
* A {@link RecursiveVisitor} that goes orthogonally to the side and down, but never up.

View File

@ -19,13 +19,14 @@
package com.sk89q.worldedit.function.visitor;
import static com.google.common.base.Preconditions.checkNotNull;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.function.RegionFunction;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.operation.Operations;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* An implementation of an {@link BreadthFirstSearch} that uses a mask to
* determine where a block should be visited.

View File

@ -19,9 +19,6 @@
package com.sk89q.worldedit.function.visitor;
import java.util.Iterator;
import java.util.List;
import com.sk89q.worldedit.BlockVector;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.function.RegionFunction;
@ -29,6 +26,8 @@ import com.sk89q.worldedit.function.operation.Operation;
import com.sk89q.worldedit.function.operation.Operations;
import com.sk89q.worldedit.function.operation.RunContext;
import com.sk89q.worldedit.regions.Region;
import java.util.Iterator;
import java.util.List;
/**
* Utility class to apply region functions to {@link com.sk89q.worldedit.regions.Region}.

View File

@ -19,14 +19,15 @@
package com.sk89q.worldedit.history.change;
import static com.google.common.base.Preconditions.checkNotNull;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.entity.Entity;
import com.sk89q.worldedit.history.UndoContext;
import com.sk89q.worldedit.util.Location;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Logs the creation of an entity and removes the entity upon undo.
*/

View File

@ -19,14 +19,15 @@
package com.sk89q.worldedit.history.change;
import static com.google.common.base.Preconditions.checkNotNull;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.entity.Entity;
import com.sk89q.worldedit.history.UndoContext;
import com.sk89q.worldedit.util.Location;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Tracks the removal of an entity.
*/

View File

@ -1,248 +0,0 @@
package net.jpountz.lz4;
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import static net.jpountz.lz4.LZ4BlockOutputStream.COMPRESSION_LEVEL_BASE;
import static net.jpountz.lz4.LZ4BlockOutputStream.COMPRESSION_METHOD_LZ4;
import static net.jpountz.lz4.LZ4BlockOutputStream.COMPRESSION_METHOD_RAW;
import static net.jpountz.lz4.LZ4BlockOutputStream.DEFAULT_SEED;
import static net.jpountz.lz4.LZ4BlockOutputStream.HEADER_LENGTH;
import static net.jpountz.lz4.LZ4BlockOutputStream.MAGIC;
import static net.jpountz.lz4.LZ4BlockOutputStream.MAGIC_LENGTH;
import java.io.EOFException;
import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.zip.Checksum;
import net.jpountz.util.SafeUtils;
import net.jpountz.util.Utils;
import net.jpountz.xxhash.StreamingXXHash32;
import net.jpountz.xxhash.XXHash32;
import net.jpountz.xxhash.XXHashFactory;
/**
* {@link InputStream} implementation to decode data written with
* {@link LZ4BlockOutputStream}. This class is not thread-safe and does not
* support {@link #mark(int)}/{@link #reset()}.
* @see LZ4BlockOutputStream
*/
public final class LZ4BlockInputStream extends FilterInputStream {
private final LZ4FastDecompressor decompressor;
private final Checksum checksum;
private byte[] buffer;
private byte[] compressedBuffer;
private int originalLen;
private int o;
private boolean finished;
/**
* Create a new {@link InputStream}.
*
* @param in the {@link InputStream} to poll
* @param decompressor the {@link LZ4FastDecompressor decompressor} instance to
* use
* @param checksum the {@link Checksum} instance to use, must be
* equivalent to the instance which has been used to
* write the stream
*/
public LZ4BlockInputStream(InputStream in, LZ4FastDecompressor decompressor, Checksum checksum) {
super(in);
this.decompressor = decompressor;
this.checksum = checksum;
this.buffer = new byte[0];
this.compressedBuffer = new byte[HEADER_LENGTH];
o = originalLen = 0;
finished = false;
}
/**
* Create a new instance using {@link XXHash32} for checksuming.
* @see #LZ4BlockInputStream(InputStream, LZ4FastDecompressor, Checksum)
* @see StreamingXXHash32#asChecksum()
*/
public LZ4BlockInputStream(InputStream in, LZ4FastDecompressor decompressor) {
this(in, decompressor, XXHashFactory.fastestInstance().newStreamingHash32(DEFAULT_SEED).asChecksum());
}
/**
* Create a new instance which uses the fastest {@link LZ4FastDecompressor} available.
* @see LZ4Factory#fastestInstance()
* @see #LZ4BlockInputStream(InputStream, LZ4FastDecompressor)
*/
public LZ4BlockInputStream(InputStream in) {
this(in, LZ4Factory.fastestInstance().fastDecompressor());
}
@Override
public int available() throws IOException {
return originalLen - o;
}
@Override
public int read() throws IOException {
if (finished) {
return -1;
}
if (o == originalLen) {
refill();
}
if (finished) {
return -1;
}
return buffer[o++] & 0xFF;
}
@Override
public int read(byte[] b, int off, int len) throws IOException {
SafeUtils.checkRange(b, off, len);
if (finished) {
return -1;
}
if (o == originalLen) {
refill();
}
if (finished) {
return -1;
}
len = Math.min(len, originalLen - o);
System.arraycopy(buffer, o, b, off, len);
o += len;
return len;
}
@Override
public int read(byte[] b) throws IOException {
return read(b, 0, b.length);
}
@Override
public long skip(long n) throws IOException {
if (finished) {
return -1;
}
if (o == originalLen) {
refill();
}
if (finished) {
return -1;
}
final int skipped = (int) Math.min(n, originalLen - o);
o += skipped;
return skipped;
}
private void refill() throws IOException {
readFully(compressedBuffer, HEADER_LENGTH);
for (int i = 0; i < MAGIC_LENGTH; ++i) {
if (compressedBuffer[i] != MAGIC[i]) {
throw new IOException("Stream is corrupted");
}
}
final int token = compressedBuffer[MAGIC_LENGTH] & 0xFF;
final int compressionMethod = token & 0xF0;
final int compressionLevel = COMPRESSION_LEVEL_BASE + (token & 0x0F);
if (compressionMethod != COMPRESSION_METHOD_RAW && compressionMethod != COMPRESSION_METHOD_LZ4) {
throw new IOException("Stream is corrupted");
}
final int compressedLen = SafeUtils.readIntLE(compressedBuffer, MAGIC_LENGTH + 1);
originalLen = SafeUtils.readIntLE(compressedBuffer, MAGIC_LENGTH + 5);
final int check = SafeUtils.readIntLE(compressedBuffer, MAGIC_LENGTH + 9);
assert HEADER_LENGTH == MAGIC_LENGTH + 13;
if (originalLen > 1 << compressionLevel
|| originalLen < 0
|| compressedLen < 0
|| (originalLen == 0 && compressedLen != 0)
|| (originalLen != 0 && compressedLen == 0)
|| (compressionMethod == COMPRESSION_METHOD_RAW && originalLen != compressedLen)) {
throw new IOException("Stream is corrupted");
}
if (originalLen == 0 && compressedLen == 0) {
if (check != 0) {
throw new IOException("Stream is corrupted");
}
finished = true;
return;
}
if (buffer.length < originalLen) {
buffer = new byte[Math.max(originalLen, buffer.length * 3 / 2)];
}
switch (compressionMethod) {
case COMPRESSION_METHOD_RAW:
readFully(buffer, originalLen);
break;
case COMPRESSION_METHOD_LZ4:
if (compressedBuffer.length < originalLen) {
compressedBuffer = new byte[Math.max(compressedLen, compressedBuffer.length * 3 / 2)];
}
readFully(compressedBuffer, compressedLen);
try {
final int compressedLen2 = decompressor.decompress(compressedBuffer, 0, buffer, 0, originalLen);
if (compressedLen != compressedLen2) {
throw new IOException("Stream is corrupted");
}
} catch (LZ4Exception e) {
throw new IOException("Stream is corrupted", e);
}
break;
default:
throw new AssertionError();
}
checksum.reset();
checksum.update(buffer, 0, originalLen);
if ((int) checksum.getValue() != check) {
throw new IOException("Stream is corrupted");
}
o = 0;
}
private void readFully(byte[] b, int len) throws IOException {
int read = 0;
while (read < len) {
final int r = in.read(b, read, len - read);
if (r < 0) {
throw new EOFException("Stream ended prematurely");
}
read += r;
}
assert len == read;
}
@Override
public boolean markSupported() {
return false;
}
@SuppressWarnings("sync-override")
@Override
public void mark(int readlimit) {
// unsupported
}
@SuppressWarnings("sync-override")
@Override
public void reset() throws IOException {
throw new IOException("mark/reset not supported");
}
@Override
public String toString() {
return getClass().getSimpleName() + "(in=" + in
+ ", decompressor=" + decompressor + ", checksum=" + checksum + ")";
}
}

View File

@ -1,259 +0,0 @@
package net.jpountz.lz4;
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.io.FilterOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.zip.Checksum;
import net.jpountz.util.SafeUtils;
import net.jpountz.xxhash.StreamingXXHash32;
import net.jpountz.xxhash.XXHashFactory;
/**
* Streaming LZ4.
* <p>
* This class compresses data into fixed-size blocks of compressed data.
* @see LZ4BlockInputStream
*/
public final class LZ4BlockOutputStream extends FilterOutputStream {
static final byte[] MAGIC = new byte[] { 'L', 'Z', '4', 'B', 'l', 'o', 'c', 'k' };
static final int MAGIC_LENGTH = MAGIC.length;
static final int HEADER_LENGTH =
MAGIC_LENGTH // magic bytes
+ 1 // token
+ 4 // compressed length
+ 4 // decompressed length
+ 4; // checksum
static final int COMPRESSION_LEVEL_BASE = 10;
static final int MIN_BLOCK_SIZE = 64;
static final int MAX_BLOCK_SIZE = 1 << (COMPRESSION_LEVEL_BASE + 0x0F);
static final int COMPRESSION_METHOD_RAW = 0x10;
static final int COMPRESSION_METHOD_LZ4 = 0x20;
static final int DEFAULT_SEED = 0x9747b28c;
private static int compressionLevel(int blockSize) {
if (blockSize < MIN_BLOCK_SIZE) {
throw new IllegalArgumentException("blockSize must be >= " + MIN_BLOCK_SIZE + ", got " + blockSize);
} else if (blockSize > MAX_BLOCK_SIZE) {
throw new IllegalArgumentException("blockSize must be <= " + MAX_BLOCK_SIZE + ", got " + blockSize);
}
int compressionLevel = 32 - Integer.numberOfLeadingZeros(blockSize - 1); // ceil of log2
assert (1 << compressionLevel) >= blockSize;
assert blockSize * 2 > (1 << compressionLevel);
compressionLevel = Math.max(0, compressionLevel - COMPRESSION_LEVEL_BASE);
assert compressionLevel >= 0 && compressionLevel <= 0x0F;
return compressionLevel;
}
private final int blockSize;
private final int compressionLevel;
private final LZ4Compressor compressor;
private final Checksum checksum;
private final byte[] buffer;
private final byte[] compressedBuffer;
private final boolean syncFlush;
private boolean finished;
private int o;
/**
* Create a new {@link OutputStream} with configurable block size. Large
* blocks require more memory at compression and decompression time but
* should improve the compression ratio.
*
* @param out the {@link OutputStream} to feed
* @param blockSize the maximum number of bytes to try to compress at once,
* must be >= 64 and <= 32 M
* @param compressor the {@link LZ4Compressor} instance to use to compress
* data
* @param checksum the {@link Checksum} instance to use to check data for
* integrity.
* @param syncFlush true if pending data should also be flushed on {@link #flush()}
*/
public LZ4BlockOutputStream(OutputStream out, int blockSize, LZ4Compressor compressor, Checksum checksum, boolean syncFlush) {
super(out);
this.blockSize = blockSize;
this.compressor = compressor;
this.checksum = checksum;
this.compressionLevel = compressionLevel(blockSize);
this.buffer = new byte[blockSize];
final int compressedBlockSize = HEADER_LENGTH + compressor.maxCompressedLength(blockSize);
this.compressedBuffer = new byte[compressedBlockSize];
this.syncFlush = syncFlush;
o = 0;
finished = false;
System.arraycopy(MAGIC, 0, compressedBuffer, 0, MAGIC_LENGTH);
}
/**
* Create a new instance which checks stream integrity using
* {@link StreamingXXHash32} and doesn't sync flush.
* @see #LZ4BlockOutputStream(OutputStream, int, LZ4Compressor, Checksum, boolean)
* @see StreamingXXHash32#asChecksum()
*/
public LZ4BlockOutputStream(OutputStream out, int blockSize, LZ4Compressor compressor) {
this(out, blockSize, compressor, XXHashFactory.fastestInstance().newStreamingHash32(DEFAULT_SEED).asChecksum(), false);
}
/**
* Create a new instance which compresses with the standard LZ4 compression
* algorithm.
* @see #LZ4BlockOutputStream(OutputStream, int, LZ4Compressor)
* @see LZ4Factory#fastCompressor()
*/
public LZ4BlockOutputStream(OutputStream out, int blockSize) {
this(out, blockSize, LZ4Factory.fastestInstance().fastCompressor());
}
/**
* Create a new instance which compresses into blocks of 64 KB.
* @see #LZ4BlockOutputStream(OutputStream, int)
*/
public LZ4BlockOutputStream(OutputStream out) {
this(out, 1 << 16);
}
private void ensureNotFinished() {
if (finished) {
throw new IllegalStateException("This stream is already closed");
}
}
@Override
public void write(int b) throws IOException {
ensureNotFinished();
if (o == blockSize) {
flushBufferedData();
}
buffer[o++] = (byte) b;
}
@Override
public void write(byte[] b, int off, int len) throws IOException {
SafeUtils.checkRange(b, off, len);
ensureNotFinished();
while (o + len > blockSize) {
final int l = blockSize - o;
System.arraycopy(b, off, buffer, o, blockSize - o);
o = blockSize;
flushBufferedData();
off += l;
len -= l;
}
System.arraycopy(b, off, buffer, o, len);
o += len;
}
@Override
public void write(byte[] b) throws IOException {
ensureNotFinished();
write(b, 0, b.length);
}
@Override
public void close() throws IOException {
if (!finished) {
finish();
}
if (out != null) {
out.close();
out = null;
}
}
private void flushBufferedData() throws IOException {
if (o == 0) {
return;
}
checksum.reset();
checksum.update(buffer, 0, o);
final int check = (int) checksum.getValue();
int compressedLength = compressor.compress(buffer, 0, o, compressedBuffer, HEADER_LENGTH);
final int compressMethod;
if (compressedLength >= o) {
compressMethod = COMPRESSION_METHOD_RAW;
compressedLength = o;
System.arraycopy(buffer, 0, compressedBuffer, HEADER_LENGTH, o);
} else {
compressMethod = COMPRESSION_METHOD_LZ4;
}
compressedBuffer[MAGIC_LENGTH] = (byte) (compressMethod | compressionLevel);
writeIntLE(compressedLength, compressedBuffer, MAGIC_LENGTH + 1);
writeIntLE(o, compressedBuffer, MAGIC_LENGTH + 5);
writeIntLE(check, compressedBuffer, MAGIC_LENGTH + 9);
assert MAGIC_LENGTH + 13 == HEADER_LENGTH;
out.write(compressedBuffer, 0, HEADER_LENGTH + compressedLength);
o = 0;
}
/**
* Flush this compressed {@link OutputStream}.
*
* If the stream has been created with <code>syncFlush=true</code>, pending
* data will be compressed and appended to the underlying {@link OutputStream}
* before calling {@link OutputStream#flush()} on the underlying stream.
* Otherwise, this method just flushes the underlying stream, so pending
* data might not be available for reading until {@link #finish()} or
* {@link #close()} is called.
*/
@Override
public void flush() throws IOException {
if (out != null) {
if (syncFlush) {
flushBufferedData();
}
out.flush();
}
}
/**
* Same as {@link #close()} except that it doesn't close the underlying stream.
* This can be useful if you want to keep on using the underlying stream.
*/
public void finish() throws IOException {
ensureNotFinished();
flushBufferedData();
compressedBuffer[MAGIC_LENGTH] = (byte) (COMPRESSION_METHOD_RAW | compressionLevel);
writeIntLE(0, compressedBuffer, MAGIC_LENGTH + 1);
writeIntLE(0, compressedBuffer, MAGIC_LENGTH + 5);
writeIntLE(0, compressedBuffer, MAGIC_LENGTH + 9);
assert MAGIC_LENGTH + 13 == HEADER_LENGTH;
out.write(compressedBuffer, 0, HEADER_LENGTH);
finished = true;
out.flush();
}
private static void writeIntLE(int i, byte[] buf, int off) {
buf[off++] = (byte) i;
buf[off++] = (byte) (i >>> 8);
buf[off++] = (byte) (i >>> 16);
buf[off++] = (byte) (i >>> 24);
}
@Override
public String toString() {
return getClass().getSimpleName() + "(out=" + out + ", blockSize=" + blockSize
+ ", compressor=" + compressor + ", checksum=" + checksum + ")";
}
}

View File

@ -14,6 +14,10 @@ package net.jpountz.lz4;
* limitations under the License.
*/
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import static net.jpountz.lz4.LZ4Constants.COPY_LENGTH;
import static net.jpountz.lz4.LZ4Constants.LAST_LITERALS;
import static net.jpountz.lz4.LZ4Constants.ML_BITS;
@ -26,9 +30,6 @@ import static net.jpountz.util.ByteBufferUtils.writeByte;
import static net.jpountz.util.ByteBufferUtils.writeInt;
import static net.jpountz.util.ByteBufferUtils.writeLong;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
enum LZ4ByteBufferUtils {
;
static int hash(ByteBuffer buf, int i) {

View File

@ -18,9 +18,10 @@ import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.util.Arrays;
import net.jpountz.util.Native;
import net.jpountz.util.Utils;
import static net.jpountz.lz4.LZ4Constants.DEFAULT_COMPRESSION_LEVEL;
import static net.jpountz.lz4.LZ4Constants.MAX_COMPRESSION_LEVEL;
@ -244,12 +245,6 @@ public final class LZ4Factory {
return fastDecompressor();
}
/** Prints the fastest instance. */
public static void main(String[] args) {
System.out.println("Fastest instance is " + fastestInstance());
System.out.println("Fastest Java instance is " + fastestJavaInstance());
}
@Override
public String toString() {
return getClass().getSimpleName() + ":" + impl;

View File

@ -14,13 +14,13 @@ package net.jpountz.lz4;
* limitations under the License.
*/
import static net.jpountz.lz4.LZ4Constants.DEFAULT_COMPRESSION_LEVEL;
import java.nio.ByteBuffer;
import net.jpountz.util.ByteBufferUtils;
import net.jpountz.util.SafeUtils;
import static net.jpountz.lz4.LZ4Constants.DEFAULT_COMPRESSION_LEVEL;
/**
* High compression {@link LZ4Compressor}s implemented with JNI bindings to the
* original C implementation of LZ4.

View File

@ -2,16 +2,24 @@
package net.jpountz.lz4;
import static net.jpountz.lz4.LZ4Constants.*;
import static net.jpountz.lz4.LZ4Utils.*;
import java.nio.ByteBuffer;
import java.util.Arrays;
import net.jpountz.lz4.LZ4Utils.Match;
import net.jpountz.util.ByteBufferUtils;
import net.jpountz.util.SafeUtils;
import static net.jpountz.lz4.LZ4Constants.DEFAULT_COMPRESSION_LEVEL;
import static net.jpountz.lz4.LZ4Constants.HASH_TABLE_SIZE_HC;
import static net.jpountz.lz4.LZ4Constants.LAST_LITERALS;
import static net.jpountz.lz4.LZ4Constants.MAX_DISTANCE;
import static net.jpountz.lz4.LZ4Constants.MF_LIMIT;
import static net.jpountz.lz4.LZ4Constants.MIN_MATCH;
import static net.jpountz.lz4.LZ4Constants.ML_MASK;
import static net.jpountz.lz4.LZ4Constants.OPTIMAL_ML;
import static net.jpountz.lz4.LZ4Utils.copyTo;
import static net.jpountz.lz4.LZ4Utils.hashHC;
/**
* High compression compressor.
*/

View File

@ -2,16 +2,24 @@
package net.jpountz.lz4;
import static net.jpountz.lz4.LZ4Constants.*;
import static net.jpountz.lz4.LZ4Utils.*;
import java.nio.ByteBuffer;
import java.util.Arrays;
import net.jpountz.lz4.LZ4Utils.Match;
import net.jpountz.util.ByteBufferUtils;
import net.jpountz.util.UnsafeUtils;
import static net.jpountz.lz4.LZ4Constants.DEFAULT_COMPRESSION_LEVEL;
import static net.jpountz.lz4.LZ4Constants.HASH_TABLE_SIZE_HC;
import static net.jpountz.lz4.LZ4Constants.LAST_LITERALS;
import static net.jpountz.lz4.LZ4Constants.MAX_DISTANCE;
import static net.jpountz.lz4.LZ4Constants.MF_LIMIT;
import static net.jpountz.lz4.LZ4Constants.MIN_MATCH;
import static net.jpountz.lz4.LZ4Constants.ML_MASK;
import static net.jpountz.lz4.LZ4Constants.OPTIMAL_ML;
import static net.jpountz.lz4.LZ4Utils.copyTo;
import static net.jpountz.lz4.LZ4Utils.hashHC;
/**
* High compression compressor.
*/
@ -22,9 +30,12 @@ final class LZ4HCJavaUnsafeCompressor extends LZ4Compressor {
private final int maxAttempts;
final int compressionLevel;
LZ4HCJavaUnsafeCompressor() { this(DEFAULT_COMPRESSION_LEVEL); }
LZ4HCJavaUnsafeCompressor() {
this(DEFAULT_COMPRESSION_LEVEL);
}
LZ4HCJavaUnsafeCompressor(int compressionLevel) {
this.maxAttempts = 1<<(compressionLevel-1);
this.maxAttempts = 1 << (compressionLevel - 1);
this.compressionLevel = compressionLevel;
}
@ -96,7 +107,6 @@ final class LZ4HCJavaUnsafeCompressor extends LZ4Compressor {
}
boolean insertAndFindBestMatch(byte[] buf, int off, int matchLimit, Match match) {
match.start = off;
match.len = 0;
@ -160,7 +170,7 @@ final class LZ4HCJavaUnsafeCompressor extends LZ4Compressor {
break;
}
if (LZ4UnsafeUtils.readIntEquals(buf, ref, off)) {
final int matchLenForward = MIN_MATCH +LZ4UnsafeUtils.commonBytes(buf, ref + MIN_MATCH, off + MIN_MATCH, matchLimit);
final int matchLenForward = MIN_MATCH + LZ4UnsafeUtils.commonBytes(buf, ref + MIN_MATCH, off + MIN_MATCH, matchLimit);
final int matchLenBackward = LZ4UnsafeUtils.commonBytesBackward(buf, ref, off, base, startLimit);
final int matchLen = matchLenBackward + matchLenForward;
if (matchLen > match.len) {
@ -239,7 +249,7 @@ final class LZ4HCJavaUnsafeCompressor extends LZ4Compressor {
break;
}
if (LZ4ByteBufferUtils.readIntEquals(buf, ref, off)) {
final int matchLenForward = MIN_MATCH +LZ4ByteBufferUtils.commonBytes(buf, ref + MIN_MATCH, off + MIN_MATCH, matchLimit);
final int matchLenForward = MIN_MATCH + LZ4ByteBufferUtils.commonBytes(buf, ref + MIN_MATCH, off + MIN_MATCH, matchLimit);
final int matchLenBackward = LZ4ByteBufferUtils.commonBytesBackward(buf, ref, off, base, startLimit);
final int matchLen = matchLenBackward + matchLenForward;
if (matchLen > match.len) {

View File

@ -15,7 +15,6 @@ package net.jpountz.lz4;
*/
import java.nio.ByteBuffer;
import net.jpountz.util.Native;

View File

@ -14,12 +14,13 @@ package net.jpountz.lz4;
* limitations under the License.
*/
import java.nio.ByteBuffer;
import static net.jpountz.util.ByteBufferUtils.checkNotReadOnly;
import static net.jpountz.util.ByteBufferUtils.checkRange;
import static net.jpountz.util.SafeUtils.checkRange;
import java.nio.ByteBuffer;
/**
* Fast {@link LZ4FastCompressor}s implemented with JNI bindings to the original C
* implementation of LZ4.

View File

@ -16,7 +16,6 @@ package net.jpountz.lz4;
import java.nio.ByteBuffer;
import net.jpountz.util.ByteBufferUtils;
import net.jpountz.util.SafeUtils;

View File

@ -16,7 +16,6 @@ package net.jpountz.lz4;
import java.nio.ByteBuffer;
import net.jpountz.util.ByteBufferUtils;
import net.jpountz.util.SafeUtils;

View File

@ -2,15 +2,27 @@
package net.jpountz.lz4;
import static net.jpountz.lz4.LZ4Constants.*;
import static net.jpountz.lz4.LZ4Utils.*;
import java.nio.ByteBuffer;
import java.util.Arrays;
import net.jpountz.util.ByteBufferUtils;
import net.jpountz.util.SafeUtils;
import static net.jpountz.lz4.LZ4Constants.HASH_TABLE_SIZE;
import static net.jpountz.lz4.LZ4Constants.HASH_TABLE_SIZE_64K;
import static net.jpountz.lz4.LZ4Constants.LAST_LITERALS;
import static net.jpountz.lz4.LZ4Constants.LZ4_64K_LIMIT;
import static net.jpountz.lz4.LZ4Constants.MAX_DISTANCE;
import static net.jpountz.lz4.LZ4Constants.MF_LIMIT;
import static net.jpountz.lz4.LZ4Constants.MIN_LENGTH;
import static net.jpountz.lz4.LZ4Constants.MIN_MATCH;
import static net.jpountz.lz4.LZ4Constants.ML_BITS;
import static net.jpountz.lz4.LZ4Constants.ML_MASK;
import static net.jpountz.lz4.LZ4Constants.RUN_MASK;
import static net.jpountz.lz4.LZ4Constants.SKIP_STRENGTH;
import static net.jpountz.lz4.LZ4Utils.hash;
import static net.jpountz.lz4.LZ4Utils.hash64k;
/**
* Compressor.
*/

View File

@ -2,13 +2,17 @@
package net.jpountz.lz4;
import static net.jpountz.lz4.LZ4Constants.*;
import java.nio.ByteBuffer;
import net.jpountz.util.ByteBufferUtils;
import net.jpountz.util.SafeUtils;
import static net.jpountz.lz4.LZ4Constants.COPY_LENGTH;
import static net.jpountz.lz4.LZ4Constants.MIN_MATCH;
import static net.jpountz.lz4.LZ4Constants.ML_BITS;
import static net.jpountz.lz4.LZ4Constants.ML_MASK;
import static net.jpountz.lz4.LZ4Constants.RUN_MASK;
/**
* Decompressor.
*/

View File

@ -2,13 +2,17 @@
package net.jpountz.lz4;
import static net.jpountz.lz4.LZ4Constants.*;
import java.nio.ByteBuffer;
import net.jpountz.util.ByteBufferUtils;
import net.jpountz.util.SafeUtils;
import static net.jpountz.lz4.LZ4Constants.COPY_LENGTH;
import static net.jpountz.lz4.LZ4Constants.MIN_MATCH;
import static net.jpountz.lz4.LZ4Constants.ML_BITS;
import static net.jpountz.lz4.LZ4Constants.ML_MASK;
import static net.jpountz.lz4.LZ4Constants.RUN_MASK;
/**
* Decompressor.
*/

View File

@ -2,15 +2,27 @@
package net.jpountz.lz4;
import static net.jpountz.lz4.LZ4Constants.*;
import static net.jpountz.lz4.LZ4Utils.*;
import java.nio.ByteBuffer;
import java.util.Arrays;
import net.jpountz.util.ByteBufferUtils;
import net.jpountz.util.UnsafeUtils;
import static net.jpountz.lz4.LZ4Constants.HASH_TABLE_SIZE;
import static net.jpountz.lz4.LZ4Constants.HASH_TABLE_SIZE_64K;
import static net.jpountz.lz4.LZ4Constants.LAST_LITERALS;
import static net.jpountz.lz4.LZ4Constants.LZ4_64K_LIMIT;
import static net.jpountz.lz4.LZ4Constants.MAX_DISTANCE;
import static net.jpountz.lz4.LZ4Constants.MF_LIMIT;
import static net.jpountz.lz4.LZ4Constants.MIN_LENGTH;
import static net.jpountz.lz4.LZ4Constants.MIN_MATCH;
import static net.jpountz.lz4.LZ4Constants.ML_BITS;
import static net.jpountz.lz4.LZ4Constants.ML_MASK;
import static net.jpountz.lz4.LZ4Constants.RUN_MASK;
import static net.jpountz.lz4.LZ4Constants.SKIP_STRENGTH;
import static net.jpountz.lz4.LZ4Utils.hash;
import static net.jpountz.lz4.LZ4Utils.hash64k;
/**
* Compressor.
*/

View File

@ -2,13 +2,17 @@
package net.jpountz.lz4;
import static net.jpountz.lz4.LZ4Constants.*;
import java.nio.ByteBuffer;
import net.jpountz.util.ByteBufferUtils;
import net.jpountz.util.UnsafeUtils;
import static net.jpountz.lz4.LZ4Constants.COPY_LENGTH;
import static net.jpountz.lz4.LZ4Constants.MIN_MATCH;
import static net.jpountz.lz4.LZ4Constants.ML_BITS;
import static net.jpountz.lz4.LZ4Constants.ML_MASK;
import static net.jpountz.lz4.LZ4Constants.RUN_MASK;
/**
* Decompressor.
*/

View File

@ -2,13 +2,17 @@
package net.jpountz.lz4;
import static net.jpountz.lz4.LZ4Constants.*;
import java.nio.ByteBuffer;
import net.jpountz.util.ByteBufferUtils;
import net.jpountz.util.UnsafeUtils;
import static net.jpountz.lz4.LZ4Constants.COPY_LENGTH;
import static net.jpountz.lz4.LZ4Constants.MIN_MATCH;
import static net.jpountz.lz4.LZ4Constants.ML_BITS;
import static net.jpountz.lz4.LZ4Constants.ML_MASK;
import static net.jpountz.lz4.LZ4Constants.RUN_MASK;
/**
* Decompressor.
*/

View File

@ -1,7 +1,7 @@
package net.jpountz.lz4;
import java.io.OutputStream;
import java.io.IOException;
import java.io.OutputStream;
public class LZ4OutputStream extends OutputStream {
private static final LZ4Factory lz4Factory = LZ4Factory.fastestInstance();

View File

@ -14,11 +14,13 @@ package net.jpountz.lz4;
* limitations under the License.
*/
import net.jpountz.util.SafeUtils;
import static net.jpountz.lz4.LZ4Constants.LAST_LITERALS;
import static net.jpountz.lz4.LZ4Constants.ML_BITS;
import static net.jpountz.lz4.LZ4Constants.ML_MASK;
import static net.jpountz.lz4.LZ4Constants.RUN_MASK;
import net.jpountz.util.SafeUtils;
enum LZ4SafeUtils {
;

View File

@ -1,8 +1,8 @@
package net.jpountz.lz4;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.IOException;
public class LZ4StreamHelper {
static void writeLength(int length, OutputStream os) throws IOException {

View File

@ -1,18 +1,17 @@
package net.jpountz.lz4;
import static junit.framework.Assert.assertEquals;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Random;
import junit.framework.Assert;
import org.junit.Before;
import org.junit.Test;
import static junit.framework.Assert.assertEquals;
public class LZ4StreamTest {
private long seed;

View File

@ -14,6 +14,9 @@ package net.jpountz.lz4;
* limitations under the License.
*/
import java.nio.ByteOrder;
import static net.jpountz.lz4.LZ4Constants.COPY_LENGTH;
import static net.jpountz.lz4.LZ4Constants.LAST_LITERALS;
import static net.jpountz.lz4.LZ4Constants.ML_BITS;
@ -29,8 +32,6 @@ import static net.jpountz.util.UnsafeUtils.writeLong;
import static net.jpountz.util.UnsafeUtils.writeShort;
import static net.jpountz.util.Utils.NATIVE_BYTE_ORDER;
import java.nio.ByteOrder;
enum LZ4UnsafeUtils {
;

View File

@ -17,12 +17,7 @@ package net.jpountz.lz4;
import static net.jpountz.lz4.LZ4Constants.HASH_LOG;
import static net.jpountz.lz4.LZ4Constants.HASH_LOG_64K;
import static net.jpountz.lz4.LZ4Constants.HASH_LOG_HC;
import static net.jpountz.lz4.LZ4Constants.LAST_LITERALS;
import static net.jpountz.lz4.LZ4Constants.MIN_MATCH;
import static net.jpountz.lz4.LZ4Constants.ML_BITS;
import static net.jpountz.lz4.LZ4Constants.ML_MASK;
import static net.jpountz.lz4.LZ4Constants.RUN_MASK;
import net.jpountz.util.SafeUtils;
enum LZ4Utils {
;

View File

@ -71,9 +71,6 @@ public enum Native {
return;
}
String resourceName = resourceName();
System.out.println("NAME: " + resourceName);
System.out.println("WORK: " + Fawe.class.getResourceAsStream("/LICENSE"));
System.out.println("WORK: " + Fawe.class.getResourceAsStream("/win32/amd64/liblz4-java.so"));
InputStream is = Fawe.class.getResourceAsStream(resourceName);
if (is == null) {
throw new UnsupportedOperationException("Unsupported OS/arch, cannot find " + resourceName + ". Please try building from source.");

View File

@ -14,13 +14,13 @@ package net.jpountz.util;
* limitations under the License.
*/
import static net.jpountz.util.Utils.NATIVE_BYTE_ORDER;
import java.lang.reflect.Field;
import java.nio.ByteOrder;
import sun.misc.Unsafe;
import static net.jpountz.util.Utils.NATIVE_BYTE_ORDER;
public enum UnsafeUtils {
;

View File

@ -1,42 +0,0 @@
package net.jpountz.xxhash;
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import static net.jpountz.xxhash.XXHashConstants.PRIME1;
import static net.jpountz.xxhash.XXHashConstants.PRIME2;
abstract class AbstractStreamingXXHash32Java extends StreamingXXHash32 {
int v1, v2, v3, v4, memSize;
long totalLen;
final byte[] memory;
AbstractStreamingXXHash32Java(int seed) {
super(seed);
memory = new byte[16];
reset();
}
@Override
public void reset() {
v1 = seed + PRIME1 + PRIME2;
v2 = seed + PRIME2;
v3 = seed + 0;
v4 = seed - PRIME1;
totalLen = 0;
memSize = 0;
}
}

View File

@ -1,43 +0,0 @@
package net.jpountz.xxhash;
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import static net.jpountz.xxhash.XXHashConstants.PRIME64_1;
import static net.jpountz.xxhash.XXHashConstants.PRIME64_2;
abstract class AbstractStreamingXXHash64Java extends StreamingXXHash64 {
int memSize;
long v1, v2, v3, v4;
long totalLen;
final byte[] memory;
AbstractStreamingXXHash64Java(long seed) {
super(seed);
memory = new byte[32];
reset();
}
@Override
public void reset() {
v1 = seed + PRIME64_1 + PRIME64_2;
v2 = seed + PRIME64_2;
v3 = seed + 0;
v4 = seed - PRIME64_1;
totalLen = 0;
memSize = 0;
}
}

View File

@ -1,111 +0,0 @@
package net.jpountz.xxhash;
import java.util.zip.Checksum;
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Streaming interface for {@link XXHash32}.
* <p>
* This API is compatible with the {@link XXHash32 block API} and the following
* code samples are equivalent:
* <pre class="prettyprint">
* int hash(XXHashFactory xxhashFactory, byte[] buf, int off, int len, int seed) {
* return xxhashFactory.hash32().hash(buf, off, len, seed);
* }
* </pre>
* <pre class="prettyprint">
* int hash(XXHashFactory xxhashFactory, byte[] buf, int off, int len, int seed) {
* StreamingXXHash32 sh32 = xxhashFactory.newStreamingHash32(seed);
* sh32.update(buf, off, len);
* return sh32.getValue();
* }
* </pre>
* <p>
* Instances of this class are <b>not</b> thread-safe.
*/
public abstract class StreamingXXHash32 {
interface Factory {
StreamingXXHash32 newStreamingHash(int seed);
}
final int seed;
StreamingXXHash32(int seed) {
this.seed = seed;
}
/**
* Get the value of the checksum.
*/
public abstract int getValue();
/**
* Update the value of the hash with buf[off:off+len].
*/
public abstract void update(byte[] buf, int off, int len);
/**
* Reset this instance to the state it had right after instantiation. The
* seed remains unchanged.
*/
public abstract void reset();
@Override
public String toString() {
return getClass().getSimpleName() + "(seed=" + seed + ")";
}
/**
* Return a {@link Checksum} view of this instance. Modifications to the view
* will modify this instance too and vice-versa.
*/
public final Checksum asChecksum() {
return new Checksum() {
@Override
public long getValue() {
return StreamingXXHash32.this.getValue() & 0xFFFFFFFL;
}
@Override
public void reset() {
StreamingXXHash32.this.reset();
}
@Override
public void update(int b) {
StreamingXXHash32.this.update(new byte[] {(byte) b}, 0, 1);
}
@Override
public void update(byte[] b, int off, int len) {
StreamingXXHash32.this.update(b, off, len);
}
@Override
public String toString() {
return StreamingXXHash32.this.toString();
}
};
}
}

View File

@ -1,71 +0,0 @@
package net.jpountz.xxhash;
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
final class StreamingXXHash32JNI extends StreamingXXHash32 {
static class Factory implements StreamingXXHash32.Factory {
public static final StreamingXXHash32.Factory INSTANCE = new Factory();
@Override
public StreamingXXHash32 newStreamingHash(int seed) {
return new StreamingXXHash32JNI(seed);
}
}
private long state;
StreamingXXHash32JNI(int seed) {
super(seed);
state = XXHashJNI.XXH32_init(seed);
}
private void checkState() {
if (state == 0) {
throw new AssertionError("Already finalized");
}
}
@Override
public void reset() {
checkState();
XXHashJNI.XXH32_free(state);
state = XXHashJNI.XXH32_init(seed);
}
@Override
public int getValue() {
checkState();
return XXHashJNI.XXH32_digest(state);
}
@Override
public void update(byte[] bytes, int off, int len) {
checkState();
XXHashJNI.XXH32_update(state, bytes, off, len);
}
@Override
protected void finalize() throws Throwable {
super.finalize();
// free memory
XXHashJNI.XXH32_free(state);
state = 0;
}
}

View File

@ -1,111 +0,0 @@
package net.jpountz.xxhash;
import java.util.zip.Checksum;
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Streaming interface for {@link XXHash64}.
* <p>
* This API is compatible with the {@link XXHash64 block API} and the following
* code samples are equivalent:
* <pre class="prettyprint">
* long hash(XXHashFactory xxhashFactory, byte[] buf, int off, int len, long seed) {
* return xxhashFactory.hash64().hash(buf, off, len, seed);
* }
* </pre>
* <pre class="prettyprint">
* long hash(XXHashFactory xxhashFactory, byte[] buf, int off, int len, long seed) {
* StreamingXXHash64 sh64 = xxhashFactory.newStreamingHash64(seed);
* sh64.update(buf, off, len);
* return sh64.getValue();
* }
* </pre>
* <p>
* Instances of this class are <b>not</b> thread-safe.
*/
public abstract class StreamingXXHash64 {
interface Factory {
StreamingXXHash64 newStreamingHash(long seed);
}
final long seed;
StreamingXXHash64(long seed) {
this.seed = seed;
}
/**
* Get the value of the checksum.
*/
public abstract long getValue();
/**
* Update the value of the hash with buf[off:off+len].
*/
public abstract void update(byte[] buf, int off, int len);
/**
* Reset this instance to the state it had right after instantiation. The
* seed remains unchanged.
*/
public abstract void reset();
@Override
public String toString() {
return getClass().getSimpleName() + "(seed=" + seed + ")";
}
/**
* Return a {@link Checksum} view of this instance. Modifications to the view
* will modify this instance too and vice-versa.
*/
public final Checksum asChecksum() {
return new Checksum() {
@Override
public long getValue() {
return StreamingXXHash64.this.getValue();
}
@Override
public void reset() {
StreamingXXHash64.this.reset();
}
@Override
public void update(int b) {
StreamingXXHash64.this.update(new byte[] {(byte) b}, 0, 1);
}
@Override
public void update(byte[] b, int off, int len) {
StreamingXXHash64.this.update(b, off, len);
}
@Override
public String toString() {
return StreamingXXHash64.this.toString();
}
};
}
}

View File

@ -1,71 +0,0 @@
package net.jpountz.xxhash;
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
final class StreamingXXHash64JNI extends StreamingXXHash64 {
static class Factory implements StreamingXXHash64.Factory {
public static final StreamingXXHash64.Factory INSTANCE = new Factory();
@Override
public StreamingXXHash64 newStreamingHash(long seed) {
return new StreamingXXHash64JNI(seed);
}
}
private long state;
StreamingXXHash64JNI(long seed) {
super(seed);
state = XXHashJNI.XXH64_init(seed);
}
private void checkState() {
if (state == 0) {
throw new AssertionError("Already finalized");
}
}
@Override
public void reset() {
checkState();
XXHashJNI.XXH64_free(state);
state = XXHashJNI.XXH64_init(seed);
}
@Override
public long getValue() {
checkState();
return XXHashJNI.XXH64_digest(state);
}
@Override
public void update(byte[] bytes, int off, int len) {
checkState();
XXHashJNI.XXH64_update(state, bytes, off, len);
}
@Override
protected void finalize() throws Throwable {
super.finalize();
// free memory
XXHashJNI.XXH64_free(state);
state = 0;
}
}

View File

@ -1,55 +0,0 @@
package net.jpountz.xxhash;
import java.nio.ByteBuffer;
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* A 32-bits hash.
* <p>
* Instances of this class are thread-safe.
*/
public abstract class XXHash32 {
/**
* Compute the 32-bits hash of <code>buf[off:off+len]</code> using seed
* <code>seed</code>.
*/
public abstract int hash(byte[] buf, int off, int len, int seed);
/**
* Compute the hash of the given slice of the {@link ByteBuffer}.
* {@link ByteBuffer#position() position} and {@link ByteBuffer#limit() limit}
* are not modified.
*/
public abstract int hash(ByteBuffer buf, int off, int len, int seed);
/**
* Compute the hash of the given {@link ByteBuffer}. The
* {@link ByteBuffer#position() position} is moved in order to reflect bytes
* which have been read.
*/
public final int hash(ByteBuffer buf, int seed) {
final int hash = hash(buf, buf.position(), buf.remaining(), seed);
buf.position(buf.limit());
return hash;
}
@Override
public String toString() {
return getClass().getSimpleName();
}
}

View File

@ -1,49 +0,0 @@
package net.jpountz.xxhash;
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import static net.jpountz.util.ByteBufferUtils.checkRange;
import static net.jpountz.util.SafeUtils.checkRange;
import java.nio.ByteBuffer;
final class XXHash32JNI extends XXHash32 {
public static final XXHash32 INSTANCE = new XXHash32JNI();
private static XXHash32 SAFE_INSTANCE;
@Override
public int hash(byte[] buf, int off, int len, int seed) {
checkRange(buf, off, len);
return XXHashJNI.XXH32(buf, off, len, seed);
}
@Override
public int hash(ByteBuffer buf, int off, int len, int seed) {
if (buf.isDirect()) {
checkRange(buf, off, len);
return XXHashJNI.XXH32BB(buf, off, len, seed);
} else if (buf.hasArray()) {
return hash(buf.array(), off + buf.arrayOffset(), len, seed);
} else {
XXHash32 safeInstance = SAFE_INSTANCE;
if (safeInstance == null) {
safeInstance = SAFE_INSTANCE = XXHashFactory.safeInstance().hash32();
}
return safeInstance.hash(buf, off, len, seed);
}
}
}

View File

@ -1,55 +0,0 @@
package net.jpountz.xxhash;
import java.nio.ByteBuffer;
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* A 64-bits hash.
* <p>
* Instances of this class are thread-safe.
*/
public abstract class XXHash64 {
/**
* Compute the 64-bits hash of <code>buf[off:off+len]</code> using seed
* <code>seed</code>.
*/
public abstract long hash(byte[] buf, int off, int len, long seed);
/**
* Compute the hash of the given slice of the {@link ByteBuffer}.
* {@link ByteBuffer#position() position} and {@link ByteBuffer#limit() limit}
* are not modified.
*/
public abstract long hash(ByteBuffer buf, int off, int len, long seed);
/**
* Compute the hash of the given {@link ByteBuffer}. The
* {@link ByteBuffer#position() position} is moved in order to reflect bytes
* which have been read.
*/
public final long hash(ByteBuffer buf, long seed) {
final long hash = hash(buf, buf.position(), buf.remaining(), seed);
buf.position(buf.limit());
return hash;
}
@Override
public String toString() {
return getClass().getSimpleName();
}
}

View File

@ -1,49 +0,0 @@
package net.jpountz.xxhash;
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import static net.jpountz.util.ByteBufferUtils.checkRange;
import static net.jpountz.util.SafeUtils.checkRange;
import java.nio.ByteBuffer;
final class XXHash64JNI extends XXHash64 {
public static final XXHash64 INSTANCE = new XXHash64JNI();
private static XXHash64 SAFE_INSTANCE;
@Override
public long hash(byte[] buf, int off, int len, long seed) {
checkRange(buf, off, len);
return XXHashJNI.XXH64(buf, off, len, seed);
}
@Override
public long hash(ByteBuffer buf, int off, int len, long seed) {
if (buf.isDirect()) {
checkRange(buf, off, len);
return XXHashJNI.XXH64BB(buf, off, len, seed);
} else if (buf.hasArray()) {
return hash(buf.array(), off + buf.arrayOffset(), len, seed);
} else {
XXHash64 safeInstance = SAFE_INSTANCE;
if (safeInstance == null) {
safeInstance = SAFE_INSTANCE = XXHashFactory.safeInstance().hash64();
}
return safeInstance.hash(buf, off, len, seed);
}
}
}

View File

@ -1,31 +0,0 @@
package net.jpountz.xxhash;
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
enum XXHashConstants {
;
static final int PRIME1 = -1640531535;
static final int PRIME2 = -2048144777;
static final int PRIME3 = -1028477379;
static final int PRIME4 = 668265263;
static final int PRIME5 = 374761393;
static final long PRIME64_1 = -7046029288634856825L; //11400714785074694791
static final long PRIME64_2 = -4417276706812531889L; //14029467366897019727
static final long PRIME64_3 = 1609587929392839161L;
static final long PRIME64_4 = -8796714831421723037L; //9650029242287828579
static final long PRIME64_5 = 2870177450012600261L;
}

View File

@ -1,220 +0,0 @@
package net.jpountz.xxhash;
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.lang.reflect.Field;
import java.util.Random;
import net.jpountz.util.Native;
import net.jpountz.util.Utils;
/**
* Entry point to get {@link XXHash32} and {@link StreamingXXHash32} instances.
* <p>
* This class has 3 instances<ul>
* <li>a {@link #nativeInstance() native} instance which is a JNI binding to
* <a href="http://code.google.com/p/xxhash/">the original LZ4 C implementation</a>.
* <li>a {@link #safeInstance() safe Java} instance which is a pure Java port
* of the original C library,</li>
* <li>an {@link #unsafeInstance() unsafe Java} instance which is a Java port
* using the unofficial {@link sun.misc.Unsafe} API.
* </ul>
* <p>
* Only the {@link #safeInstance() safe instance} is guaranteed to work on your
* JVM, as a consequence it is advised to use the {@link #fastestInstance()} or
* {@link #fastestJavaInstance()} to pull a {@link XXHashFactory} instance.
* <p>
* All methods from this class are very costly, so you should get an instance
* once, and then reuse it whenever possible. This is typically done by storing
* a {@link XXHashFactory} instance in a static field.
*/
public final class XXHashFactory {
private static XXHashFactory instance(String impl) {
try {
return new XXHashFactory(impl);
} catch (Exception e) {
throw new AssertionError(e);
}
}
private static XXHashFactory NATIVE_INSTANCE,
JAVA_UNSAFE_INSTANCE,
JAVA_SAFE_INSTANCE;
/** Return a {@link XXHashFactory} that returns {@link XXHash32} instances that
* are native bindings to the original C API.
* <p>
* Please note that this instance has some traps you should be aware of:<ol>
* <li>Upon loading this instance, files will be written to the temporary
* directory of the system. Although these files are supposed to be deleted
* when the JVM exits, they might remain on systems that don't support
* removal of files being used such as Windows.
* <li>The instance can only be loaded once per JVM. This can be a problem
* if your application uses multiple class loaders (such as most servlet
* containers): this instance will only be available to the children of the
* class loader which has loaded it. As a consequence, it is advised to
* either not use this instance in webapps or to put this library in the lib
* directory of your servlet container so that it is loaded by the system
* class loader.
* </ol>
*/
public static synchronized XXHashFactory nativeInstance() {
if (NATIVE_INSTANCE == null) {
NATIVE_INSTANCE = instance("JNI");
}
return NATIVE_INSTANCE;
}
/** Return a {@link XXHashFactory} that returns {@link XXHash32} instances that
* are written with Java's official API. */
public static synchronized XXHashFactory safeInstance() {
if (JAVA_SAFE_INSTANCE == null) {
JAVA_SAFE_INSTANCE = instance("JavaSafe");
}
return JAVA_SAFE_INSTANCE;
}
/** Return a {@link XXHashFactory} that returns {@link XXHash32} instances that
* may use {@link sun.misc.Unsafe} to speed up hashing. */
public static synchronized XXHashFactory unsafeInstance() {
if (JAVA_UNSAFE_INSTANCE == null) {
JAVA_UNSAFE_INSTANCE = instance("JavaUnsafe");
}
return JAVA_UNSAFE_INSTANCE;
}
/**
* Return the fastest available {@link XXHashFactory} instance which does not
* rely on JNI bindings. It first tries to load the
* {@link #unsafeInstance() unsafe instance}, and then the
* {@link #safeInstance() safe Java instance} if the JVM doesn't have a
* working {@link sun.misc.Unsafe}.
*/
public static XXHashFactory fastestJavaInstance() {
if (Utils.isUnalignedAccessAllowed()) {
try {
return unsafeInstance();
} catch (Throwable t) {
return safeInstance();
}
} else {
return safeInstance();
}
}
/**
* Return the fastest available {@link XXHashFactory} instance. If the class
* loader is the system class loader and if the
* {@link #nativeInstance() native instance} loads successfully, then the
* {@link #nativeInstance() native instance} is returned, otherwise the
* {@link #fastestJavaInstance() fastest Java instance} is returned.
* <p>
* Please read {@link #nativeInstance() javadocs of nativeInstance()} before
* using this method.
*/
public static XXHashFactory fastestInstance() {
if (Native.isLoaded()
|| Native.class.getClassLoader() == ClassLoader.getSystemClassLoader()) {
try {
return nativeInstance();
} catch (Throwable t) {
return fastestJavaInstance();
}
} else {
return fastestJavaInstance();
}
}
@SuppressWarnings("unchecked")
private static <T> T classInstance(String cls) throws NoSuchFieldException, SecurityException, ClassNotFoundException, IllegalArgumentException, IllegalAccessException {
ClassLoader loader = XXHashFactory.class.getClassLoader();
loader = loader == null ? ClassLoader.getSystemClassLoader() : loader;
final Class<?> c = loader.loadClass(cls);
Field f = c.getField("INSTANCE");
return (T) f.get(null);
}
private final String impl;
private final XXHash32 hash32;
private final XXHash64 hash64;
private final StreamingXXHash32.Factory streamingHash32Factory;
private final StreamingXXHash64.Factory streamingHash64Factory;
private XXHashFactory(String impl) throws ClassNotFoundException, NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
this.impl = impl;
hash32 = classInstance("net.jpountz.xxhash.XXHash32" + impl);
streamingHash32Factory = classInstance("net.jpountz.xxhash.StreamingXXHash32" + impl + "$Factory");
hash64 = classInstance("net.jpountz.xxhash.XXHash64" + impl);
streamingHash64Factory = classInstance("net.jpountz.xxhash.StreamingXXHash64" + impl + "$Factory");
// make sure it can run
final byte[] bytes = new byte[100];
final Random random = new Random();
random.nextBytes(bytes);
final int seed = random.nextInt();
final int h1 = hash32.hash(bytes, 0, bytes.length, seed);
final StreamingXXHash32 streamingHash32 = newStreamingHash32(seed);
streamingHash32.update(bytes, 0, bytes.length);
final int h2 = streamingHash32.getValue();
final long h3 = hash64.hash(bytes, 0, bytes.length, seed);
final StreamingXXHash64 streamingHash64 = newStreamingHash64(seed);
streamingHash64.update(bytes, 0, bytes.length);
final long h4 = streamingHash64.getValue();
if (h1 != h2) {
throw new AssertionError();
}
if (h3 != h4) {
throw new AssertionError();
}
}
/** Return a {@link XXHash32} instance. */
public XXHash32 hash32() {
return hash32;
}
/** Return a {@link XXHash64} instance. */
public XXHash64 hash64() {
return hash64;
}
/**
* Return a new {@link StreamingXXHash32} instance.
*/
public StreamingXXHash32 newStreamingHash32(int seed) {
return streamingHash32Factory.newStreamingHash(seed);
}
/**
* Return a new {@link StreamingXXHash64} instance.
*/
public StreamingXXHash64 newStreamingHash64(long seed) {
return streamingHash64Factory.newStreamingHash(seed);
}
/** Prints the fastest instance. */
public static void main(String[] args) {
System.out.println("Fastest instance is " + fastestInstance());
System.out.println("Fastest Java instance is " + fastestJavaInstance());
}
@Override
public String toString() {
return getClass().getSimpleName() + ":" + impl;
}
}

View File

@ -1,43 +0,0 @@
package net.jpountz.xxhash;
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.nio.ByteBuffer;
import net.jpountz.util.Native;
enum XXHashJNI {
;
static {
Native.load();
init();
}
private static native void init();
static native int XXH32(byte[] input, int offset, int len, int seed);
static native int XXH32BB(ByteBuffer input, int offset, int len, int seed);
static native long XXH32_init(int seed);
static native void XXH32_update(long state, byte[] input, int offset, int len);
static native int XXH32_digest(long state);
static native void XXH32_free(long state);
static native long XXH64(byte[] input, int offset, int len, long seed);
static native long XXH64BB(ByteBuffer input, int offset, int len, long seed);
static native long XXH64_init(long seed);
static native void XXH64_update(long state, byte[] input, int offset, int len);
static native long XXH64_digest(long state);
static native void XXH64_free(long state);
}

View File

@ -1,65 +0,0 @@
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<!--
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<p>xxhash hashing. This package supports both block hashing via
{@link net.jpountz.xxhash.XXHash32} and streaming hashing via
{@link net.jpountz.xxhash.StreamingXXHash32}. Have a look at
{@link net.jpountz.xxhash.XXHashFactory} to know how to get instances of these
interfaces.</p>
<p>Streaming hashing is a little slower but doesn't require to load the whole
stream into memory.</p>
<p>Sample block usage:</p>
<pre class="prettyprint">
XXHashFactory factory = XXHashFactory.fastestInstance();
byte[] data = "12345345234572".getBytes("UTF-8");
XXHash32 hash32 = factory.hash32();
int seed = 0x9747b28c; // used to initialize the hash value, use whatever
// value you want, but always the same
int hash = hash32.hash(data, 0, data.length, seed);
</pre>
<p>Sample streaming usage:</p>
<pre class="prettyprint">
XXHashFactory factory = XXHashFactory.fastestInstance();
byte[] data = "12345345234572".getBytes("UTF-8");
ByteArrayInputStream in = new ByteArrayInputStream(data);
int seed = 0x9747b28c; // used to initialize the hash value, use whatever
// value you want, but always the same
StreamingXXHash32 hash32 = factory.newStreamingHash32(seed);
byte[] buf = new byte[8]; // for real-world usage, use a larger buffer, like 8192 bytes
for (;;) {
int read = in.read(buf);
if (read == -1) {
break;
}
hash32.update(buf, 0, read);
}
int hash = hash32.getValue();
</pre>
</body>
</html>

View File

@ -0,0 +1,89 @@
#################################################
ForgeGradle 2.1-SNAPSHOT-unknown
https://github.com/MinecraftForge/ForgeGradle
#################################################
Powered by MCP unknown
http://modcoderpack.com
by: Searge, ProfMobius, Fesh0r,
R4wk, ZeuX, IngisKahn, bspkrs
#################################################
Version string 'unspecified' does not match SemVer specification
You should try SemVer : http://semver.org/
:core:compileJava
:forge:deobfCompileDummyTask
:forge:deobfProvidedDummyTask
:forge:extractDependencyATs SKIPPED
:forge:extractMcpData
:core:compileJava UP-TO-DATE
:core:processResources UP-TO-DATE
:core:classes UP-TO-DATE
:core:jar UP-TO-DATE
:forge:extractMcpData SKIPPED
:forge:extractMcpMappings SKIPPED
:forge:genSrgs SKIPPED
:forge:getVersionJson
:forge:downloadServer SKIPPED
:forge:splitServerJar SKIPPED
:forge:deobfMcMCP SKIPPED
:forge:sourceApiJava UP-TO-DATE
:forge:compileApiJava UP-TO-DATE
:forge:processApiResources UP-TO-DATE
:forge:apiClasses UP-TO-DATE
:forge:sourceMainJava
:forge:compileJavaC:\Users\Jesse\.gradle\caches\modules-2\files-2.1\com.sk89q.worldedit\worldedit-forge-mc1.8.9\6.1.1\dffd7e1882eba256eb2132fe315682c1d26522b1\worldedit-forge-mc1.8.9-6.1.1.jar(com/sk89q/worldedit/forge/ForgeWorldEdit.class): warning: Cannot find annotation method 'modid()' in type 'Mod': class file for net.minecraftforge.fml.common.Mod not found
C:\Users\Jesse\.gradle\caches\modules-2\files-2.1\com.sk89q.worldedit\worldedit-forge-mc1.8.9\6.1.1\dffd7e1882eba256eb2132fe315682c1d26522b1\worldedit-forge-mc1.8.9-6.1.1.jar(com/sk89q/worldedit/forge/ForgeWorldEdit.class): warning: Cannot find annotation method 'name()' in type 'Mod'
C:\Users\Jesse\.gradle\caches\modules-2\files-2.1\com.sk89q.worldedit\worldedit-forge-mc1.8.9\6.1.1\dffd7e1882eba256eb2132fe315682c1d26522b1\worldedit-forge-mc1.8.9-6.1.1.jar(com/sk89q/worldedit/forge/ForgeWorldEdit.class): warning: Cannot find annotation method 'version()' in type 'Mod'
C:\Users\Jesse\.gradle\caches\modules-2\files-2.1\com.sk89q.worldedit\worldedit-forge-mc1.8.9\6.1.1\dffd7e1882eba256eb2132fe315682c1d26522b1\worldedit-forge-mc1.8.9-6.1.1.jar(com/sk89q/worldedit/forge/ForgeWorldEdit.class): warning: Cannot find annotation method 'acceptableRemoteVersions()' in type 'Mod'
C:\Users\Jesse\.gradle\caches\modules-2\files-2.1\com.sk89q.worldedit\worldedit-forge-mc1.8.9\6.1.1\dffd7e1882eba256eb2132fe315682c1d26522b1\worldedit-forge-mc1.8.9-6.1.1.jar(com/sk89q/worldedit/forge/ForgeWorldEdit.class): warning: Cannot find annotation method 'dependencies()' in type 'Mod'
C:\Users\Jesse\.gradle\caches\modules-2\files-2.1\com.sk89q.worldedit\worldedit-forge-mc1.8.9\6.1.1\dffd7e1882eba256eb2132fe315682c1d26522b1\worldedit-forge-mc1.8.9-6.1.1.jar(com/sk89q/worldedit/forge/ForgeWorldEdit.class): warning: Cannot find annotation method 'acceptedMinecraftVersions()' in type 'Mod'
C:\Users\Jesse\.gradle\caches\modules-2\files-2.1\com.sk89q.worldedit\worldedit-forge-mc1.8.9\6.1.1\dffd7e1882eba256eb2132fe315682c1d26522b1\worldedit-forge-mc1.8.9-6.1.1.jar(com/sk89q/worldedit/forge/ForgeWorldEdit.class): warning: Cannot find annotation method 'value()' in type 'Instance': class file for net.minecraftforge.fml.common.Mod$Instance not found
C:\Users\Jesse\.gradle\caches\modules-2\files-2.1\com.sk89q.worldedit\worldedit-forge-mc1.8.9\6.1.1\dffd7e1882eba256eb2132fe315682c1d26522b1\worldedit-forge-mc1.8.9-6.1.1.jar(com/sk89q/worldedit/forge/ForgeWorldEdit.class): warning: Cannot find annotation method 'serverSide()' in type 'SidedProxy': class file for net.minecraftforge.fml.common.SidedProxy not found
C:\Users\Jesse\.gradle\caches\modules-2\files-2.1\com.sk89q.worldedit\worldedit-forge-mc1.8.9\6.1.1\dffd7e1882eba256eb2132fe315682c1d26522b1\worldedit-forge-mc1.8.9-6.1.1.jar(com/sk89q/worldedit/forge/ForgeWorldEdit.class): warning: Cannot find annotation method 'clientSide()' in type 'SidedProxy'
C:\Users\Jesse\.gradle\caches\modules-2\files-2.1\com.sk89q.worldedit\worldedit-forge-mc1.8.9\6.1.1\dffd7e1882eba256eb2132fe315682c1d26522b1\worldedit-forge-mc1.8.9-6.1.1.jar(com/sk89q/worldedit/forge/ForgeWorldEdit.class): warning: Cannot find annotation method 'modid()' in type 'Mod': class file for net.minecraftforge.fml.common.Mod not found
C:\Users\Jesse\.gradle\caches\modules-2\files-2.1\com.sk89q.worldedit\worldedit-forge-mc1.8.9\6.1.1\dffd7e1882eba256eb2132fe315682c1d26522b1\worldedit-forge-mc1.8.9-6.1.1.jar(com/sk89q/worldedit/forge/ForgeWorldEdit.class): warning: Cannot find annotation method 'name()' in type 'Mod'
C:\Users\Jesse\.gradle\caches\modules-2\files-2.1\com.sk89q.worldedit\worldedit-forge-mc1.8.9\6.1.1\dffd7e1882eba256eb2132fe315682c1d26522b1\worldedit-forge-mc1.8.9-6.1.1.jar(com/sk89q/worldedit/forge/ForgeWorldEdit.class): warning: Cannot find annotation method 'version()' in type 'Mod'
C:\Users\Jesse\.gradle\caches\modules-2\files-2.1\com.sk89q.worldedit\worldedit-forge-mc1.8.9\6.1.1\dffd7e1882eba256eb2132fe315682c1d26522b1\worldedit-forge-mc1.8.9-6.1.1.jar(com/sk89q/worldedit/forge/ForgeWorldEdit.class): warning: Cannot find annotation method 'acceptableRemoteVersions()' in type 'Mod'
C:\Users\Jesse\.gradle\caches\modules-2\files-2.1\com.sk89q.worldedit\worldedit-forge-mc1.8.9\6.1.1\dffd7e1882eba256eb2132fe315682c1d26522b1\worldedit-forge-mc1.8.9-6.1.1.jar(com/sk89q/worldedit/forge/ForgeWorldEdit.class): warning: Cannot find annotation method 'dependencies()' in type 'Mod'
C:\Users\Jesse\.gradle\caches\modules-2\files-2.1\com.sk89q.worldedit\worldedit-forge-mc1.8.9\6.1.1\dffd7e1882eba256eb2132fe315682c1d26522b1\worldedit-forge-mc1.8.9-6.1.1.jar(com/sk89q/worldedit/forge/ForgeWorldEdit.class): warning: Cannot find annotation method 'acceptedMinecraftVersions()' in type 'Mod'
C:\Users\Jesse\.gradle\caches\modules-2\files-2.1\com.sk89q.worldedit\worldedit-forge-mc1.8.9\6.1.1\dffd7e1882eba256eb2132fe315682c1d26522b1\worldedit-forge-mc1.8.9-6.1.1.jar(com/sk89q/worldedit/forge/ForgeWorldEdit.class): warning: Cannot find annotation method 'value()' in type 'Instance': class file for net.minecraftforge.fml.common.Mod$Instance not found
C:\Users\Jesse\.gradle\caches\modules-2\files-2.1\com.sk89q.worldedit\worldedit-forge-mc1.8.9\6.1.1\dffd7e1882eba256eb2132fe315682c1d26522b1\worldedit-forge-mc1.8.9-6.1.1.jar(com/sk89q/worldedit/forge/ForgeWorldEdit.class): warning: Cannot find annotation method 'serverSide()' in type 'SidedProxy': class file for net.minecraftforge.fml.common.SidedProxy not found
C:\Users\Jesse\.gradle\caches\modules-2\files-2.1\com.sk89q.worldedit\worldedit-forge-mc1.8.9\6.1.1\dffd7e1882eba256eb2132fe315682c1d26522b1\worldedit-forge-mc1.8.9-6.1.1.jar(com/sk89q/worldedit/forge/ForgeWorldEdit.class): warning: Cannot find annotation method 'clientSide()' in type 'SidedProxy'
Note: Writing plugin metadata to file:/C:/Users/Jesse/Desktop/OTHER/GitHub/FastAsyncWorldEdit/forge/build/classes/main/mcmod.info
C:\Users\Jesse\.gradle\caches\modules-2\files-2.1\com.sk89q.worldedit\worldedit-forge-mc1.8.9\6.1.1\dffd7e1882eba256eb2132fe315682c1d26522b1\worldedit-forge-mc1.8.9-6.1.1.jar(com/sk89q/worldedit/forge/ForgeWorldEdit.class): warning: Cannot find annotation method 'modid()' in type 'Mod': class file for net.minecraftforge.fml.common.Mod not found
C:\Users\Jesse\.gradle\caches\modules-2\files-2.1\com.sk89q.worldedit\worldedit-forge-mc1.8.9\6.1.1\dffd7e1882eba256eb2132fe315682c1d26522b1\worldedit-forge-mc1.8.9-6.1.1.jar(com/sk89q/worldedit/forge/ForgeWorldEdit.class): warning: Cannot find annotation method 'name()' in type 'Mod'
C:\Users\Jesse\.gradle\caches\modules-2\files-2.1\com.sk89q.worldedit\worldedit-forge-mc1.8.9\6.1.1\dffd7e1882eba256eb2132fe315682c1d26522b1\worldedit-forge-mc1.8.9-6.1.1.jar(com/sk89q/worldedit/forge/ForgeWorldEdit.class): warning: Cannot find annotation method 'version()' in type 'Mod'
C:\Users\Jesse\.gradle\caches\modules-2\files-2.1\com.sk89q.worldedit\worldedit-forge-mc1.8.9\6.1.1\dffd7e1882eba256eb2132fe315682c1d26522b1\worldedit-forge-mc1.8.9-6.1.1.jar(com/sk89q/worldedit/forge/ForgeWorldEdit.class): warning: Cannot find annotation method 'acceptableRemoteVersions()' in type 'Mod'
C:\Users\Jesse\.gradle\caches\modules-2\files-2.1\com.sk89q.worldedit\worldedit-forge-mc1.8.9\6.1.1\dffd7e1882eba256eb2132fe315682c1d26522b1\worldedit-forge-mc1.8.9-6.1.1.jar(com/sk89q/worldedit/forge/ForgeWorldEdit.class): warning: Cannot find annotation method 'dependencies()' in type 'Mod'
C:\Users\Jesse\.gradle\caches\modules-2\files-2.1\com.sk89q.worldedit\worldedit-forge-mc1.8.9\6.1.1\dffd7e1882eba256eb2132fe315682c1d26522b1\worldedit-forge-mc1.8.9-6.1.1.jar(com/sk89q/worldedit/forge/ForgeWorldEdit.class): warning: Cannot find annotation method 'acceptedMinecraftVersions()' in type 'Mod'
C:\Users\Jesse\.gradle\caches\modules-2\files-2.1\com.sk89q.worldedit\worldedit-forge-mc1.8.9\6.1.1\dffd7e1882eba256eb2132fe315682c1d26522b1\worldedit-forge-mc1.8.9-6.1.1.jar(com/sk89q/worldedit/forge/ForgeWorldEdit.class): warning: Cannot find annotation method 'value()' in type 'Instance': class file for net.minecraftforge.fml.common.Mod$Instance not found
C:\Users\Jesse\.gradle\caches\modules-2\files-2.1\com.sk89q.worldedit\worldedit-forge-mc1.8.9\6.1.1\dffd7e1882eba256eb2132fe315682c1d26522b1\worldedit-forge-mc1.8.9-6.1.1.jar(com/sk89q/worldedit/forge/ForgeWorldEdit.class): warning: Cannot find annotation method 'serverSide()' in type 'SidedProxy': class file for net.minecraftforge.fml.common.SidedProxy not found
C:\Users\Jesse\.gradle\caches\modules-2\files-2.1\com.sk89q.worldedit\worldedit-forge-mc1.8.9\6.1.1\dffd7e1882eba256eb2132fe315682c1d26522b1\worldedit-forge-mc1.8.9-6.1.1.jar(com/sk89q/worldedit/forge/ForgeWorldEdit.class): warning: Cannot find annotation method 'clientSide()' in type 'SidedProxy'
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
27 warnings
:forge:processResources UP-TO-DATE
:forge:classes
:forge:jar
:forge:sourceTestJava UP-TO-DATE
:forge:compileTestJava UP-TO-DATE
:forge:processTestResources UP-TO-DATE
:forge:testClasses UP-TO-DATE
:forge:test UP-TO-DATE
:forge:reobfJar
:forge:shadowJar
:forge:reobfShadowJar
:forge:extractRangemapReplacedMain
C:\Users\Jesse\Desktop\OTHER\GitHub\FastAsyncWorldEdit\forge\build\sources\main\java
:forge:retromapReplacedMain
remapping source...
:forge:sourceJar
:forge:assemble
:forge:check UP-TO-DATE
:forge:build
BUILD SUCCESSFUL
Total time: 36.523 secs

View File

@ -7,6 +7,7 @@ import com.sk89q.worldedit.world.biome.BaseBiome;
import java.util.Arrays;
import org.spongepowered.api.Sponge;
import org.spongepowered.api.world.Chunk;
import org.spongepowered.api.world.World;
public class SpongeChunk_1_8 extends FaweChunk<Chunk> {
@ -29,7 +30,8 @@ public class SpongeChunk_1_8 extends FaweChunk<Chunk> {
@Override
public Chunk getChunk() {
if (this.chunk == null) {
this.chunk = Sponge.getServer().getWorld(getParent().world).get().getChunk(getX(), 0, getZ()).get();
World world = Sponge.getServer().getWorld(getParent().world).get();
this.chunk = world.loadChunk(getX(), 0, getZ(), true).get();
}
return this.chunk;
}