diff --git a/.gitignore b/.gitignore index 225e40f1..21b1008d 100644 --- a/.gitignore +++ b/.gitignore @@ -11,4 +11,5 @@ /.gradle /.idea /forge/build -forge/.gradle/gradle.log \ No newline at end of file +forge/.gradle/gradle.log +*.log \ No newline at end of file diff --git a/bukkit/src/main/java/com/boydti/fawe/bukkit/BukkitCommand.java b/bukkit/src/main/java/com/boydti/fawe/bukkit/BukkitCommand.java index 8f07a10d..66ed2d63 100644 --- a/bukkit/src/main/java/com/boydti/fawe/bukkit/BukkitCommand.java +++ b/bukkit/src/main/java/com/boydti/fawe/bukkit/BukkitCommand.java @@ -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 { diff --git a/bukkit/src/main/java/com/boydti/fawe/bukkit/BukkitTaskMan.java b/bukkit/src/main/java/com/boydti/fawe/bukkit/BukkitTaskMan.java index 56c634bb..34134d66 100644 --- a/bukkit/src/main/java/com/boydti/fawe/bukkit/BukkitTaskMan.java +++ b/bukkit/src/main/java/com/boydti/fawe/bukkit/BukkitTaskMan.java @@ -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; diff --git a/bukkit/src/main/java/com/boydti/fawe/bukkit/FaweBukkit.java b/bukkit/src/main/java/com/boydti/fawe/bukkit/FaweBukkit.java index fd20bfd2..ee8eba0b 100644 --- a/bukkit/src/main/java/com/boydti/fawe/bukkit/FaweBukkit.java +++ b/bukkit/src/main/java/com/boydti/fawe/bukkit/FaweBukkit.java @@ -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 { diff --git a/bukkit/src/main/java/com/boydti/fawe/bukkit/VaultUtil.java b/bukkit/src/main/java/com/boydti/fawe/bukkit/VaultUtil.java index 5deda5f8..dff828e4 100644 --- a/bukkit/src/main/java/com/boydti/fawe/bukkit/VaultUtil.java +++ b/bukkit/src/main/java/com/boydti/fawe/bukkit/VaultUtil.java @@ -1,7 +1,6 @@ package com.boydti.fawe.bukkit; import net.milkbowl.vault.permission.Permission; - import org.bukkit.Bukkit; import org.bukkit.plugin.RegisteredServiceProvider; diff --git a/bukkit/src/main/java/com/boydti/fawe/bukkit/WEListener.java b/bukkit/src/main/java/com/boydti/fawe/bukkit/WEListener.java index ece78735..c404ff26 100644 --- a/bukkit/src/main/java/com/boydti/fawe/bukkit/WEListener.java +++ b/bukkit/src/main/java/com/boydti/fawe/bukkit/WEListener.java @@ -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
diff --git a/bukkit/src/main/java/com/boydti/fawe/bukkit/regions/BukkitMaskManager.java b/bukkit/src/main/java/com/boydti/fawe/bukkit/regions/BukkitMaskManager.java index 4a78360d..284cf4fe 100644 --- a/bukkit/src/main/java/com/boydti/fawe/bukkit/regions/BukkitMaskManager.java +++ b/bukkit/src/main/java/com/boydti/fawe/bukkit/regions/BukkitMaskManager.java @@ -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 { diff --git a/bukkit/src/main/java/com/boydti/fawe/bukkit/regions/FactionsFeature.java b/bukkit/src/main/java/com/boydti/fawe/bukkit/regions/FactionsFeature.java index d786422e..02d66509 100644 --- a/bukkit/src/main/java/com/boydti/fawe/bukkit/regions/FactionsFeature.java +++ b/bukkit/src/main/java/com/boydti/fawe/bukkit/regions/FactionsFeature.java @@ -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; diff --git a/bukkit/src/main/java/com/boydti/fawe/bukkit/regions/FactionsUUIDFeature.java b/bukkit/src/main/java/com/boydti/fawe/bukkit/regions/FactionsUUIDFeature.java index 746e63d3..9ab5668c 100644 --- a/bukkit/src/main/java/com/boydti/fawe/bukkit/regions/FactionsUUIDFeature.java +++ b/bukkit/src/main/java/com/boydti/fawe/bukkit/regions/FactionsUUIDFeature.java @@ -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; diff --git a/bukkit/src/main/java/com/boydti/fawe/bukkit/regions/GriefPreventionFeature.java b/bukkit/src/main/java/com/boydti/fawe/bukkit/regions/GriefPreventionFeature.java index 7e911489..920830f8 100644 --- a/bukkit/src/main/java/com/boydti/fawe/bukkit/regions/GriefPreventionFeature.java +++ b/bukkit/src/main/java/com/boydti/fawe/bukkit/regions/GriefPreventionFeature.java @@ -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; diff --git a/bukkit/src/main/java/com/boydti/fawe/bukkit/regions/PlotMeFeature.java b/bukkit/src/main/java/com/boydti/fawe/bukkit/regions/PlotMeFeature.java index c233a5da..5c6c7911 100644 --- a/bukkit/src/main/java/com/boydti/fawe/bukkit/regions/PlotMeFeature.java +++ b/bukkit/src/main/java/com/boydti/fawe/bukkit/regions/PlotMeFeature.java @@ -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; diff --git a/bukkit/src/main/java/com/boydti/fawe/bukkit/regions/PlotSquaredFeature.java b/bukkit/src/main/java/com/boydti/fawe/bukkit/regions/PlotSquaredFeature.java deleted file mode 100644 index fc16c777..00000000 --- a/bukkit/src/main/java/com/boydti/fawe/bukkit/regions/PlotSquaredFeature.java +++ /dev/null @@ -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 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 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 faweRegions = new HashSet(); - 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 getRegions() { - return faweRegions; - } - }; - } - } - } - return null; - } -} diff --git a/bukkit/src/main/java/com/boydti/fawe/bukkit/regions/PreciousStonesFeature.java b/bukkit/src/main/java/com/boydti/fawe/bukkit/regions/PreciousStonesFeature.java index 80e5dbe7..7682d9c6 100644 --- a/bukkit/src/main/java/com/boydti/fawe/bukkit/regions/PreciousStonesFeature.java +++ b/bukkit/src/main/java/com/boydti/fawe/bukkit/regions/PreciousStonesFeature.java @@ -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; diff --git a/bukkit/src/main/java/com/boydti/fawe/bukkit/regions/ResidenceFeature.java b/bukkit/src/main/java/com/boydti/fawe/bukkit/regions/ResidenceFeature.java index 8e439010..018019cc 100644 --- a/bukkit/src/main/java/com/boydti/fawe/bukkit/regions/ResidenceFeature.java +++ b/bukkit/src/main/java/com/boydti/fawe/bukkit/regions/ResidenceFeature.java @@ -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; diff --git a/bukkit/src/main/java/com/boydti/fawe/bukkit/regions/TownyFeature.java b/bukkit/src/main/java/com/boydti/fawe/bukkit/regions/TownyFeature.java index ddbcc479..c67d3474 100644 --- a/bukkit/src/main/java/com/boydti/fawe/bukkit/regions/TownyFeature.java +++ b/bukkit/src/main/java/com/boydti/fawe/bukkit/regions/TownyFeature.java @@ -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; diff --git a/bukkit/src/main/java/com/boydti/fawe/bukkit/regions/Worldguard.java b/bukkit/src/main/java/com/boydti/fawe/bukkit/regions/Worldguard.java index 59461bc9..f033be75 100644 --- a/bukkit/src/main/java/com/boydti/fawe/bukkit/regions/Worldguard.java +++ b/bukkit/src/main/java/com/boydti/fawe/bukkit/regions/Worldguard.java @@ -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; diff --git a/bukkit/src/main/java/com/boydti/fawe/bukkit/v1_8/BukkitEditSessionWrapper_1_8.java b/bukkit/src/main/java/com/boydti/fawe/bukkit/v1_8/BukkitEditSessionWrapper_1_8.java index af5df568..41768306 100644 --- a/bukkit/src/main/java/com/boydti/fawe/bukkit/v1_8/BukkitEditSessionWrapper_1_8.java +++ b/bukkit/src/main/java/com/boydti/fawe/bukkit/v1_8/BukkitEditSessionWrapper_1_8.java @@ -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 { diff --git a/core/src/main/java/com/boydti/fawe/Fawe.java b/core/src/main/java/com/boydti/fawe/Fawe.java index ac2a4e4e..3c45b953 100644 --- a/core/src/main/java/com/boydti/fawe/Fawe.java +++ b/core/src/main/java/com/boydti/fawe/Fawe.java @@ -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() { diff --git a/core/src/main/java/com/boydti/fawe/command/Stream.java b/core/src/main/java/com/boydti/fawe/command/Stream.java index 2a28981e..50f9c695 100644 --- a/core/src/main/java/com/boydti/fawe/command/Stream.java +++ b/core/src/main/java/com/boydti/fawe/command/Stream.java @@ -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 { diff --git a/core/src/main/java/com/boydti/fawe/config/BBC.java b/core/src/main/java/com/boydti/fawe/config/BBC.java index c5131a81..cb245ea3 100644 --- a/core/src/main/java/com/boydti/fawe/config/BBC.java +++ b/core/src/main/java/com/boydti/fawe/config/BBC.java @@ -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 { diff --git a/core/src/main/java/com/boydti/fawe/config/Settings.java b/core/src/main/java/com/boydti/fawe/config/Settings.java index 0041ab76..1dce84f5 100644 --- a/core/src/main/java/com/boydti/fawe/config/Settings.java +++ b/core/src/main/java/com/boydti/fawe/config/Settings.java @@ -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) { diff --git a/core/src/main/java/com/boydti/fawe/configuration/Configuration.java b/core/src/main/java/com/boydti/fawe/configuration/Configuration.java index 2b57cdfa..680434c8 100644 --- a/core/src/main/java/com/boydti/fawe/configuration/Configuration.java +++ b/core/src/main/java/com/boydti/fawe/configuration/Configuration.java @@ -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; /** diff --git a/core/src/main/java/com/boydti/fawe/configuration/ConfigurationOptions.java b/core/src/main/java/com/boydti/fawe/configuration/ConfigurationOptions.java index a5270836..3a6b815a 100644 --- a/core/src/main/java/com/boydti/fawe/configuration/ConfigurationOptions.java +++ b/core/src/main/java/com/boydti/fawe/configuration/ConfigurationOptions.java @@ -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} diff --git a/core/src/main/java/com/boydti/fawe/configuration/ConfigurationSection.java b/core/src/main/java/com/boydti/fawe/configuration/ConfigurationSection.java index 7b21e8ec..4c59e318 100644 --- a/core/src/main/java/com/boydti/fawe/configuration/ConfigurationSection.java +++ b/core/src/main/java/com/boydti/fawe/configuration/ConfigurationSection.java @@ -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; diff --git a/core/src/main/java/com/boydti/fawe/configuration/MemoryConfiguration.java b/core/src/main/java/com/boydti/fawe/configuration/MemoryConfiguration.java index d4360ea2..b097c5e8 100644 --- a/core/src/main/java/com/boydti/fawe/configuration/MemoryConfiguration.java +++ b/core/src/main/java/com/boydti/fawe/configuration/MemoryConfiguration.java @@ -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; /** diff --git a/core/src/main/java/com/boydti/fawe/configuration/MemoryConfigurationOptions.java b/core/src/main/java/com/boydti/fawe/configuration/MemoryConfigurationOptions.java index 3d08a362..2cbefce9 100644 --- a/core/src/main/java/com/boydti/fawe/configuration/MemoryConfigurationOptions.java +++ b/core/src/main/java/com/boydti/fawe/configuration/MemoryConfigurationOptions.java @@ -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} diff --git a/core/src/main/java/com/boydti/fawe/configuration/MemorySection.java b/core/src/main/java/com/boydti/fawe/configuration/MemorySection.java index a6f7a4ee..0dc4c061 100644 --- a/core/src/main/java/com/boydti/fawe/configuration/MemorySection.java +++ b/core/src/main/java/com/boydti/fawe/configuration/MemorySection.java @@ -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; diff --git a/core/src/main/java/com/boydti/fawe/configuration/file/FileConfiguration.java b/core/src/main/java/com/boydti/fawe/configuration/file/FileConfiguration.java index 4c0ad7cf..bb4d62cc 100644 --- a/core/src/main/java/com/boydti/fawe/configuration/file/FileConfiguration.java +++ b/core/src/main/java/com/boydti/fawe/configuration/file/FileConfiguration.java @@ -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; diff --git a/core/src/main/java/com/boydti/fawe/configuration/file/YamlConfigurationOptions.java b/core/src/main/java/com/boydti/fawe/configuration/file/YamlConfigurationOptions.java index d30195ce..c60f9578 100644 --- a/core/src/main/java/com/boydti/fawe/configuration/file/YamlConfigurationOptions.java +++ b/core/src/main/java/com/boydti/fawe/configuration/file/YamlConfigurationOptions.java @@ -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} diff --git a/core/src/main/java/com/boydti/fawe/configuration/serialization/ConfigurationSerialization.java b/core/src/main/java/com/boydti/fawe/configuration/serialization/ConfigurationSerialization.java index a5e15dee..2378d702 100644 --- a/core/src/main/java/com/boydti/fawe/configuration/serialization/ConfigurationSerialization.java +++ b/core/src/main/java/com/boydti/fawe/configuration/serialization/ConfigurationSerialization.java @@ -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; diff --git a/core/src/main/java/com/boydti/fawe/configuration/serialization/DelegateDeserialization.java b/core/src/main/java/com/boydti/fawe/configuration/serialization/DelegateDeserialization.java index 2d033ea5..dfe31006 100644 --- a/core/src/main/java/com/boydti/fawe/configuration/serialization/DelegateDeserialization.java +++ b/core/src/main/java/com/boydti/fawe/configuration/serialization/DelegateDeserialization.java @@ -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; diff --git a/core/src/main/java/com/boydti/fawe/object/FawePlayer.java b/core/src/main/java/com/boydti/fawe/object/FawePlayer.java index 6484a888..b65aeeb9 100644 --- a/core/src/main/java/com/boydti/fawe/object/FawePlayer.java +++ b/core/src/main/java/com/boydti/fawe/object/FawePlayer.java @@ -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 { @@ -30,6 +36,35 @@ public abstract class FawePlayer { 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 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 { } 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 getCurrentRegions() { diff --git a/core/src/main/java/com/boydti/fawe/object/changeset/DiskStorageHistory.java b/core/src/main/java/com/boydti/fawe/object/changeset/DiskStorageHistory.java index cae52100..aab483d3 100644 --- a/core/src/main/java/com/boydti/fawe/object/changeset/DiskStorageHistory.java +++ b/core/src/main/java/com/boydti/fawe/object/changeset/DiskStorageHistory.java @@ -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; - - public DiskStorageHistory(String name) { + private AtomicInteger size = new AtomicInteger(); + private World world; + + 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()) { - 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; + 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"); + } + + 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() { 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(); } - } diff --git a/core/src/main/java/com/boydti/fawe/object/extent/NullExtent.java b/core/src/main/java/com/boydti/fawe/object/extent/NullExtent.java index 8f2eb050..8da384f9 100644 --- a/core/src/main/java/com/boydti/fawe/object/extent/NullExtent.java +++ b/core/src/main/java/com/boydti/fawe/object/extent/NullExtent.java @@ -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 { diff --git a/core/src/main/java/com/boydti/fawe/regions/FaweMask.java b/core/src/main/java/com/boydti/fawe/regions/FaweMask.java index 7c6b2116..7da727c9 100644 --- a/core/src/main/java/com/boydti/fawe/regions/FaweMask.java +++ b/core/src/main/java/com/boydti/fawe/regions/FaweMask.java @@ -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; diff --git a/core/src/main/java/com/boydti/fawe/util/MemUtil.java b/core/src/main/java/com/boydti/fawe/util/MemUtil.java index c5b8eaf6..31548bc4 100644 --- a/core/src/main/java/com/boydti/fawe/util/MemUtil.java +++ b/core/src/main/java/com/boydti/fawe/util/MemUtil.java @@ -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 { diff --git a/core/src/main/java/com/sk89q/worldedit/EditSession.java b/core/src/main/java/com/sk89q/worldedit/EditSession.java index 8380d514..d022080f 100644 --- a/core/src/main/java/com/sk89q/worldedit/EditSession.java +++ b/core/src/main/java/com/sk89q/worldedit/EditSession.java @@ -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 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); - } } /** diff --git a/core/src/main/java/com/sk89q/worldedit/LocalSession.java b/core/src/main/java/com/sk89q/worldedit/LocalSession.java index da6cee2d..d3f190c7 100644 --- a/core/src/main/java/com/sk89q/worldedit/LocalSession.java +++ b/core/src/main/java/com/sk89q/worldedit/LocalSession.java @@ -278,6 +278,10 @@ public class LocalSession { return null; } + public int getSize() { + return history.size(); + } + /** * Get the default region selector. * diff --git a/core/src/main/java/com/sk89q/worldedit/command/FlattenedClipboardTransform.java b/core/src/main/java/com/sk89q/worldedit/command/FlattenedClipboardTransform.java index bb534b61..66b5185b 100644 --- a/core/src/main/java/com/sk89q/worldedit/command/FlattenedClipboardTransform.java +++ b/core/src/main/java/com/sk89q/worldedit/command/FlattenedClipboardTransform.java @@ -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. * diff --git a/core/src/main/java/com/sk89q/worldedit/command/SchematicCommands.java b/core/src/main/java/com/sk89q/worldedit/command/SchematicCommands.java index 1f750c70..96f206d7 100644 --- a/core/src/main/java/com/sk89q/worldedit/command/SchematicCommands.java +++ b/core/src/main/java/com/sk89q/worldedit/command/SchematicCommands.java @@ -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. diff --git a/core/src/main/java/com/sk89q/worldedit/command/ScriptingCommands.java b/core/src/main/java/com/sk89q/worldedit/command/ScriptingCommands.java index 331dcb81..0b687c37 100644 --- a/core/src/main/java/com/sk89q/worldedit/command/ScriptingCommands.java +++ b/core/src/main/java/com/sk89q/worldedit/command/ScriptingCommands.java @@ -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. diff --git a/core/src/main/java/com/sk89q/worldedit/function/visitor/BreadthFirstSearch.java b/core/src/main/java/com/sk89q/worldedit/function/visitor/BreadthFirstSearch.java index 02705e91..757f6110 100644 --- a/core/src/main/java/com/sk89q/worldedit/function/visitor/BreadthFirstSearch.java +++ b/core/src/main/java/com/sk89q/worldedit/function/visitor/BreadthFirstSearch.java @@ -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 diff --git a/core/src/main/java/com/sk89q/worldedit/function/visitor/DownwardVisitor.java b/core/src/main/java/com/sk89q/worldedit/function/visitor/DownwardVisitor.java index aa29cefa..9e0b844e 100644 --- a/core/src/main/java/com/sk89q/worldedit/function/visitor/DownwardVisitor.java +++ b/core/src/main/java/com/sk89q/worldedit/function/visitor/DownwardVisitor.java @@ -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 diff --git a/core/src/main/java/com/sk89q/worldedit/function/visitor/EntityVisitor.java b/core/src/main/java/com/sk89q/worldedit/function/visitor/EntityVisitor.java index 9adc74d7..b75a8f8e 100644 --- a/core/src/main/java/com/sk89q/worldedit/function/visitor/EntityVisitor.java +++ b/core/src/main/java/com/sk89q/worldedit/function/visitor/EntityVisitor.java @@ -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}. diff --git a/core/src/main/java/com/sk89q/worldedit/function/visitor/FlatRegionVisitor.java b/core/src/main/java/com/sk89q/worldedit/function/visitor/FlatRegionVisitor.java index 544d771e..2e7d6d84 100644 --- a/core/src/main/java/com/sk89q/worldedit/function/visitor/FlatRegionVisitor.java +++ b/core/src/main/java/com/sk89q/worldedit/function/visitor/FlatRegionVisitor.java @@ -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}. diff --git a/core/src/main/java/com/sk89q/worldedit/function/visitor/LayerVisitor.java b/core/src/main/java/com/sk89q/worldedit/function/visitor/LayerVisitor.java index 873f002c..f98d1338 100644 --- a/core/src/main/java/com/sk89q/worldedit/function/visitor/LayerVisitor.java +++ b/core/src/main/java/com/sk89q/worldedit/function/visitor/LayerVisitor.java @@ -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. diff --git a/core/src/main/java/com/sk89q/worldedit/function/visitor/NonRisingVisitor.java b/core/src/main/java/com/sk89q/worldedit/function/visitor/NonRisingVisitor.java index e1f2720d..1823e4a1 100644 --- a/core/src/main/java/com/sk89q/worldedit/function/visitor/NonRisingVisitor.java +++ b/core/src/main/java/com/sk89q/worldedit/function/visitor/NonRisingVisitor.java @@ -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. diff --git a/core/src/main/java/com/sk89q/worldedit/function/visitor/RecursiveVisitor.java b/core/src/main/java/com/sk89q/worldedit/function/visitor/RecursiveVisitor.java index 56713b26..1d0fa6c3 100644 --- a/core/src/main/java/com/sk89q/worldedit/function/visitor/RecursiveVisitor.java +++ b/core/src/main/java/com/sk89q/worldedit/function/visitor/RecursiveVisitor.java @@ -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. diff --git a/core/src/main/java/com/sk89q/worldedit/function/visitor/RegionVisitor.java b/core/src/main/java/com/sk89q/worldedit/function/visitor/RegionVisitor.java index 2f6a523d..d9898a07 100644 --- a/core/src/main/java/com/sk89q/worldedit/function/visitor/RegionVisitor.java +++ b/core/src/main/java/com/sk89q/worldedit/function/visitor/RegionVisitor.java @@ -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}. diff --git a/core/src/main/java/com/sk89q/worldedit/history/change/EntityCreate.java b/core/src/main/java/com/sk89q/worldedit/history/change/EntityCreate.java index 71efd823..bf869c4a 100644 --- a/core/src/main/java/com/sk89q/worldedit/history/change/EntityCreate.java +++ b/core/src/main/java/com/sk89q/worldedit/history/change/EntityCreate.java @@ -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. */ diff --git a/core/src/main/java/com/sk89q/worldedit/history/change/EntityRemove.java b/core/src/main/java/com/sk89q/worldedit/history/change/EntityRemove.java index 0ac942e3..d566e018 100644 --- a/core/src/main/java/com/sk89q/worldedit/history/change/EntityRemove.java +++ b/core/src/main/java/com/sk89q/worldedit/history/change/EntityRemove.java @@ -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. */ diff --git a/core/src/main/java/net/jpountz/lz4/LZ4BlockInputStream.java b/core/src/main/java/net/jpountz/lz4/LZ4BlockInputStream.java deleted file mode 100644 index 95ca3f42..00000000 --- a/core/src/main/java/net/jpountz/lz4/LZ4BlockInputStream.java +++ /dev/null @@ -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 + ")"; - } - -} diff --git a/core/src/main/java/net/jpountz/lz4/LZ4BlockOutputStream.java b/core/src/main/java/net/jpountz/lz4/LZ4BlockOutputStream.java deleted file mode 100644 index 86e172b0..00000000 --- a/core/src/main/java/net/jpountz/lz4/LZ4BlockOutputStream.java +++ /dev/null @@ -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. - *

- * 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 syncFlush=true, 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 + ")"; - } - -} diff --git a/core/src/main/java/net/jpountz/lz4/LZ4ByteBufferUtils.java b/core/src/main/java/net/jpountz/lz4/LZ4ByteBufferUtils.java index 3c0b9ac6..44e707ff 100644 --- a/core/src/main/java/net/jpountz/lz4/LZ4ByteBufferUtils.java +++ b/core/src/main/java/net/jpountz/lz4/LZ4ByteBufferUtils.java @@ -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) { diff --git a/core/src/main/java/net/jpountz/lz4/LZ4Factory.java b/core/src/main/java/net/jpountz/lz4/LZ4Factory.java index 7d1cf271..6f88a707 100644 --- a/core/src/main/java/net/jpountz/lz4/LZ4Factory.java +++ b/core/src/main/java/net/jpountz/lz4/LZ4Factory.java @@ -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; diff --git a/core/src/main/java/net/jpountz/lz4/LZ4HCJNICompressor.java b/core/src/main/java/net/jpountz/lz4/LZ4HCJNICompressor.java index da721e31..aa2d1fe0 100644 --- a/core/src/main/java/net/jpountz/lz4/LZ4HCJNICompressor.java +++ b/core/src/main/java/net/jpountz/lz4/LZ4HCJNICompressor.java @@ -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. diff --git a/core/src/main/java/net/jpountz/lz4/LZ4HCJavaSafeCompressor.java b/core/src/main/java/net/jpountz/lz4/LZ4HCJavaSafeCompressor.java index f4ec3bd8..155497df 100644 --- a/core/src/main/java/net/jpountz/lz4/LZ4HCJavaSafeCompressor.java +++ b/core/src/main/java/net/jpountz/lz4/LZ4HCJavaSafeCompressor.java @@ -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. */ diff --git a/core/src/main/java/net/jpountz/lz4/LZ4HCJavaUnsafeCompressor.java b/core/src/main/java/net/jpountz/lz4/LZ4HCJavaUnsafeCompressor.java index 0f503221..71552c84 100644 --- a/core/src/main/java/net/jpountz/lz4/LZ4HCJavaUnsafeCompressor.java +++ b/core/src/main/java/net/jpountz/lz4/LZ4HCJavaUnsafeCompressor.java @@ -2,549 +2,559 @@ 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. */ final class LZ4HCJavaUnsafeCompressor extends LZ4Compressor { - public static final LZ4Compressor INSTANCE = new LZ4HCJavaUnsafeCompressor(); + public static final LZ4Compressor INSTANCE = new LZ4HCJavaUnsafeCompressor(); - private final int maxAttempts; - final int compressionLevel; - - LZ4HCJavaUnsafeCompressor() { this(DEFAULT_COMPRESSION_LEVEL); } - LZ4HCJavaUnsafeCompressor(int compressionLevel) { - this.maxAttempts = 1<<(compressionLevel-1); - this.compressionLevel = compressionLevel; - } + private final int maxAttempts; + final int compressionLevel; - private class HashTable { - static final int MASK = MAX_DISTANCE - 1; - int nextToUpdate; - private final int base; - private final int[] hashTable; - private final short[] chainTable; - - HashTable(int base) { - this.base = base; - nextToUpdate = base; - hashTable = new int[HASH_TABLE_SIZE_HC]; - Arrays.fill(hashTable, -1); - chainTable = new short[MAX_DISTANCE]; + LZ4HCJavaUnsafeCompressor() { + this(DEFAULT_COMPRESSION_LEVEL); } - private int hashPointer(byte[] bytes, int off) { - final int v = UnsafeUtils.readInt(bytes, off); - return hashPointer(v); + LZ4HCJavaUnsafeCompressor(int compressionLevel) { + this.maxAttempts = 1 << (compressionLevel - 1); + this.compressionLevel = compressionLevel; } - private int hashPointer(ByteBuffer bytes, int off) { - final int v = ByteBufferUtils.readInt(bytes, off); - return hashPointer(v); - } + private class HashTable { + static final int MASK = MAX_DISTANCE - 1; + int nextToUpdate; + private final int base; + private final int[] hashTable; + private final short[] chainTable; - private int hashPointer(int v) { - final int h = hashHC(v); - return hashTable[h]; - } - - private int next(int off) { - return off - (chainTable[off & MASK] & 0xFFFF); - } - - private void addHash(byte[] bytes, int off) { - final int v = UnsafeUtils.readInt(bytes, off); - addHash(v, off); - } - - private void addHash(ByteBuffer bytes, int off) { - final int v = ByteBufferUtils.readInt(bytes, off); - addHash(v, off); - } - - private void addHash(int v, int off) { - final int h = hashHC(v); - int delta = off - hashTable[h]; - assert delta > 0 : delta; - if (delta >= MAX_DISTANCE) { - delta = MAX_DISTANCE - 1; - } - chainTable[off & MASK] = (short) delta; - hashTable[h] = off; - } - - void insert(int off, byte[] bytes) { - for (; nextToUpdate < off; ++nextToUpdate) { - addHash(bytes, nextToUpdate); - } - } - - void insert(int off, ByteBuffer bytes) { - for (; nextToUpdate < off; ++nextToUpdate) { - addHash(bytes, nextToUpdate); - } - } - - - - boolean insertAndFindBestMatch(byte[] buf, int off, int matchLimit, Match match) { - match.start = off; - match.len = 0; - int delta = 0; - int repl = 0; - - insert(off, buf); - - int ref = hashPointer(buf, off); - - if (ref >= off - 4 && ref <= off && ref >= base) { // potential repetition - if (LZ4UnsafeUtils.readIntEquals(buf, ref, off)) { // confirmed - delta = off - ref; - repl = match.len = MIN_MATCH + LZ4UnsafeUtils.commonBytes(buf, ref + MIN_MATCH, off + MIN_MATCH, matchLimit); - match.ref = ref; - } - ref = next(ref); - } - - for (int i = 0; i < maxAttempts; ++i) { - if (ref < Math.max(base, off - MAX_DISTANCE + 1) || ref > off) { - break; - } - if (LZ4UnsafeUtils.readIntEquals(buf, ref, off)) { - final int matchLen = MIN_MATCH + LZ4UnsafeUtils.commonBytes(buf, ref + MIN_MATCH, off + MIN_MATCH, matchLimit); - if (matchLen > match.len) { - match.ref = ref; - match.len = matchLen; - } - } - ref = next(ref); - } - - if (repl != 0) { - int ptr = off; - final int end = off + repl - (MIN_MATCH - 1); - while (ptr < end - delta) { - chainTable[ptr & MASK] = (short) delta; // pre load - ++ptr; - } - do { - chainTable[ptr & MASK] = (short) delta; - hashTable[hashHC(UnsafeUtils.readInt(buf, ptr))] = ptr; - ++ptr; - } while (ptr < end); - nextToUpdate = end; - } - - return match.len != 0; - } - - boolean insertAndFindWiderMatch(byte[] buf, int off, int startLimit, int matchLimit, int minLen, Match match) { - match.len = minLen; - - insert(off, buf); - - final int delta = off - startLimit; - int ref = hashPointer(buf, off); - for (int i = 0; i < maxAttempts; ++i) { - if (ref < Math.max(base, off - MAX_DISTANCE + 1) || ref > off) { - break; - } - if (LZ4UnsafeUtils.readIntEquals(buf, ref, off)) { - 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) { - match.len = matchLen; - match.ref = ref - matchLenBackward; - match.start = off - matchLenBackward; - } - } - ref = next(ref); - } - - return match.len > minLen; - } - - - boolean insertAndFindBestMatch(ByteBuffer buf, int off, int matchLimit, Match match) { - match.start = off; - match.len = 0; - int delta = 0; - int repl = 0; - - insert(off, buf); - - int ref = hashPointer(buf, off); - - if (ref >= off - 4 && ref <= off && ref >= base) { // potential repetition - if (LZ4ByteBufferUtils.readIntEquals(buf, ref, off)) { // confirmed - delta = off - ref; - repl = match.len = MIN_MATCH + LZ4ByteBufferUtils.commonBytes(buf, ref + MIN_MATCH, off + MIN_MATCH, matchLimit); - match.ref = ref; - } - ref = next(ref); - } - - for (int i = 0; i < maxAttempts; ++i) { - if (ref < Math.max(base, off - MAX_DISTANCE + 1) || ref > off) { - break; - } - if (LZ4ByteBufferUtils.readIntEquals(buf, ref, off)) { - final int matchLen = MIN_MATCH + LZ4ByteBufferUtils.commonBytes(buf, ref + MIN_MATCH, off + MIN_MATCH, matchLimit); - if (matchLen > match.len) { - match.ref = ref; - match.len = matchLen; - } - } - ref = next(ref); - } - - if (repl != 0) { - int ptr = off; - final int end = off + repl - (MIN_MATCH - 1); - while (ptr < end - delta) { - chainTable[ptr & MASK] = (short) delta; // pre load - ++ptr; - } - do { - chainTable[ptr & MASK] = (short) delta; - hashTable[hashHC(ByteBufferUtils.readInt(buf, ptr))] = ptr; - ++ptr; - } while (ptr < end); - nextToUpdate = end; - } - - return match.len != 0; - } - - boolean insertAndFindWiderMatch(ByteBuffer buf, int off, int startLimit, int matchLimit, int minLen, Match match) { - match.len = minLen; - - insert(off, buf); - - final int delta = off - startLimit; - int ref = hashPointer(buf, off); - for (int i = 0; i < maxAttempts; ++i) { - if (ref < Math.max(base, off - MAX_DISTANCE + 1) || ref > off) { - break; - } - if (LZ4ByteBufferUtils.readIntEquals(buf, ref, off)) { - 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) { - match.len = matchLen; - match.ref = ref - matchLenBackward; - match.start = off - matchLenBackward; - } - } - ref = next(ref); - } - - return match.len > minLen; - } - - - } - - @Override - public int compress(byte[] src, int srcOff, int srcLen, byte[] dest, int destOff, int maxDestLen) { - - UnsafeUtils.checkRange(src, srcOff, srcLen); - UnsafeUtils.checkRange(dest, destOff, maxDestLen); - - final int srcEnd = srcOff + srcLen; - final int destEnd = destOff + maxDestLen; - final int mfLimit = srcEnd - MF_LIMIT; - final int matchLimit = srcEnd - LAST_LITERALS; - - int sOff = srcOff; - int dOff = destOff; - int anchor = sOff++; - - final HashTable ht = new HashTable(srcOff); - final Match match0 = new Match(); - final Match match1 = new Match(); - final Match match2 = new Match(); - final Match match3 = new Match(); - - main: - while (sOff < mfLimit) { - if (!ht.insertAndFindBestMatch(src, sOff, matchLimit, match1)) { - ++sOff; - continue; - } - - // saved, in case we would skip too much - copyTo(match1, match0); - - search2: - while (true) { - assert match1.start >= anchor; - if (match1.end() >= mfLimit - || !ht.insertAndFindWiderMatch(src, match1.end() - 2, match1.start + 1, matchLimit, match1.len, match2)) { - // no better match - dOff = LZ4UnsafeUtils.encodeSequence(src, anchor, match1.start, match1.ref, match1.len, dest, dOff, destEnd); - anchor = sOff = match1.end(); - continue main; + HashTable(int base) { + this.base = base; + nextToUpdate = base; + hashTable = new int[HASH_TABLE_SIZE_HC]; + Arrays.fill(hashTable, -1); + chainTable = new short[MAX_DISTANCE]; } - if (match0.start < match1.start) { - if (match2.start < match1.start + match0.len) { // empirical - copyTo(match0, match1); - } - } - assert match2.start > match1.start; - - if (match2.start - match1.start < 3) { // First Match too small : removed - copyTo(match2, match1); - continue search2; + private int hashPointer(byte[] bytes, int off) { + final int v = UnsafeUtils.readInt(bytes, off); + return hashPointer(v); } - search3: - while (true) { - if (match2.start - match1.start < OPTIMAL_ML) { - int newMatchLen = match1.len; - if (newMatchLen > OPTIMAL_ML) { - newMatchLen = OPTIMAL_ML; + private int hashPointer(ByteBuffer bytes, int off) { + final int v = ByteBufferUtils.readInt(bytes, off); + return hashPointer(v); + } + + private int hashPointer(int v) { + final int h = hashHC(v); + return hashTable[h]; + } + + private int next(int off) { + return off - (chainTable[off & MASK] & 0xFFFF); + } + + private void addHash(byte[] bytes, int off) { + final int v = UnsafeUtils.readInt(bytes, off); + addHash(v, off); + } + + private void addHash(ByteBuffer bytes, int off) { + final int v = ByteBufferUtils.readInt(bytes, off); + addHash(v, off); + } + + private void addHash(int v, int off) { + final int h = hashHC(v); + int delta = off - hashTable[h]; + assert delta > 0 : delta; + if (delta >= MAX_DISTANCE) { + delta = MAX_DISTANCE - 1; } - if (match1.start + newMatchLen > match2.end() - MIN_MATCH) { - newMatchLen = match2.start - match1.start + match2.len - MIN_MATCH; - } - final int correction = newMatchLen - (match2.start - match1.start); - if (correction > 0) { - match2.fix(correction); - } - } + chainTable[off & MASK] = (short) delta; + hashTable[h] = off; + } - if (match2.start + match2.len >= mfLimit - || !ht.insertAndFindWiderMatch(src, match2.end() - 3, match2.start, matchLimit, match2.len, match3)) { - // no better match -> 2 sequences to encode - if (match2.start < match1.end()) { - match1.len = match2.start - match1.start; + void insert(int off, byte[] bytes) { + for (; nextToUpdate < off; ++nextToUpdate) { + addHash(bytes, nextToUpdate); } - // encode seq 1 - dOff = LZ4UnsafeUtils.encodeSequence(src, anchor, match1.start, match1.ref, match1.len, dest, dOff, destEnd); - anchor = sOff = match1.end(); - // encode seq 2 - dOff = LZ4UnsafeUtils.encodeSequence(src, anchor, match2.start, match2.ref, match2.len, dest, dOff, destEnd); - anchor = sOff = match2.end(); - continue main; - } + } - if (match3.start < match1.end() + 3) { // Not enough space for match 2 : remove it - if (match3.start >= match1.end()) { // // can write Seq1 immediately ==> Seq2 is removed, so Seq3 becomes Seq1 - if (match2.start < match1.end()) { - final int correction = match1.end() - match2.start; - match2.fix(correction); - if (match2.len < MIN_MATCH) { - copyTo(match3, match2); + void insert(int off, ByteBuffer bytes) { + for (; nextToUpdate < off; ++nextToUpdate) { + addHash(bytes, nextToUpdate); + } + } + + + boolean insertAndFindBestMatch(byte[] buf, int off, int matchLimit, Match match) { + match.start = off; + match.len = 0; + int delta = 0; + int repl = 0; + + insert(off, buf); + + int ref = hashPointer(buf, off); + + if (ref >= off - 4 && ref <= off && ref >= base) { // potential repetition + if (LZ4UnsafeUtils.readIntEquals(buf, ref, off)) { // confirmed + delta = off - ref; + repl = match.len = MIN_MATCH + LZ4UnsafeUtils.commonBytes(buf, ref + MIN_MATCH, off + MIN_MATCH, matchLimit); + match.ref = ref; } - } - - dOff = LZ4UnsafeUtils.encodeSequence(src, anchor, match1.start, match1.ref, match1.len, dest, dOff, destEnd); - anchor = sOff = match1.end(); - - copyTo(match3, match1); - copyTo(match2, match0); - - continue search2; + ref = next(ref); } - copyTo(match3, match2); - continue search3; - } - - // OK, now we have 3 ascending matches; let's write at least the first one - if (match2.start < match1.end()) { - if (match2.start - match1.start < ML_MASK) { - if (match1.len > OPTIMAL_ML) { - match1.len = OPTIMAL_ML; - } - if (match1.end() > match2.end() - MIN_MATCH) { - match1.len = match2.end() - match1.start - MIN_MATCH; - } - final int correction = match1.end() - match2.start; - match2.fix(correction); - } else { - match1.len = match2.start - match1.start; - } - } - - dOff = LZ4UnsafeUtils.encodeSequence(src, anchor, match1.start, match1.ref, match1.len, dest, dOff, destEnd); - anchor = sOff = match1.end(); - - copyTo(match2, match1); - copyTo(match3, match2); - - continue search3; - } - - } - - } - - dOff = LZ4UnsafeUtils.lastLiterals(src, anchor, srcEnd - anchor, dest, dOff, destEnd); - return dOff - destOff; - } - - - @Override - public int compress(ByteBuffer src, int srcOff, int srcLen, ByteBuffer dest, int destOff, int maxDestLen) { - - if (src.hasArray() && dest.hasArray()) { - return compress(src.array(), srcOff + src.arrayOffset(), srcLen, dest.array(), destOff + dest.arrayOffset(), maxDestLen); - } - src = ByteBufferUtils.inNativeByteOrder(src); - dest = ByteBufferUtils.inNativeByteOrder(dest); - - ByteBufferUtils.checkRange(src, srcOff, srcLen); - ByteBufferUtils.checkRange(dest, destOff, maxDestLen); - - final int srcEnd = srcOff + srcLen; - final int destEnd = destOff + maxDestLen; - final int mfLimit = srcEnd - MF_LIMIT; - final int matchLimit = srcEnd - LAST_LITERALS; - - int sOff = srcOff; - int dOff = destOff; - int anchor = sOff++; - - final HashTable ht = new HashTable(srcOff); - final Match match0 = new Match(); - final Match match1 = new Match(); - final Match match2 = new Match(); - final Match match3 = new Match(); - - main: - while (sOff < mfLimit) { - if (!ht.insertAndFindBestMatch(src, sOff, matchLimit, match1)) { - ++sOff; - continue; - } - - // saved, in case we would skip too much - copyTo(match1, match0); - - search2: - while (true) { - assert match1.start >= anchor; - if (match1.end() >= mfLimit - || !ht.insertAndFindWiderMatch(src, match1.end() - 2, match1.start + 1, matchLimit, match1.len, match2)) { - // no better match - dOff = LZ4ByteBufferUtils.encodeSequence(src, anchor, match1.start, match1.ref, match1.len, dest, dOff, destEnd); - anchor = sOff = match1.end(); - continue main; - } - - if (match0.start < match1.start) { - if (match2.start < match1.start + match0.len) { // empirical - copyTo(match0, match1); - } - } - assert match2.start > match1.start; - - if (match2.start - match1.start < 3) { // First Match too small : removed - copyTo(match2, match1); - continue search2; - } - - search3: - while (true) { - if (match2.start - match1.start < OPTIMAL_ML) { - int newMatchLen = match1.len; - if (newMatchLen > OPTIMAL_ML) { - newMatchLen = OPTIMAL_ML; - } - if (match1.start + newMatchLen > match2.end() - MIN_MATCH) { - newMatchLen = match2.start - match1.start + match2.len - MIN_MATCH; - } - final int correction = newMatchLen - (match2.start - match1.start); - if (correction > 0) { - match2.fix(correction); - } - } - - if (match2.start + match2.len >= mfLimit - || !ht.insertAndFindWiderMatch(src, match2.end() - 3, match2.start, matchLimit, match2.len, match3)) { - // no better match -> 2 sequences to encode - if (match2.start < match1.end()) { - match1.len = match2.start - match1.start; - } - // encode seq 1 - dOff = LZ4ByteBufferUtils.encodeSequence(src, anchor, match1.start, match1.ref, match1.len, dest, dOff, destEnd); - anchor = sOff = match1.end(); - // encode seq 2 - dOff = LZ4ByteBufferUtils.encodeSequence(src, anchor, match2.start, match2.ref, match2.len, dest, dOff, destEnd); - anchor = sOff = match2.end(); - continue main; - } - - if (match3.start < match1.end() + 3) { // Not enough space for match 2 : remove it - if (match3.start >= match1.end()) { // // can write Seq1 immediately ==> Seq2 is removed, so Seq3 becomes Seq1 - if (match2.start < match1.end()) { - final int correction = match1.end() - match2.start; - match2.fix(correction); - if (match2.len < MIN_MATCH) { - copyTo(match3, match2); + for (int i = 0; i < maxAttempts; ++i) { + if (ref < Math.max(base, off - MAX_DISTANCE + 1) || ref > off) { + break; } - } - - dOff = LZ4ByteBufferUtils.encodeSequence(src, anchor, match1.start, match1.ref, match1.len, dest, dOff, destEnd); - anchor = sOff = match1.end(); - - copyTo(match3, match1); - copyTo(match2, match0); - - continue search2; + if (LZ4UnsafeUtils.readIntEquals(buf, ref, off)) { + final int matchLen = MIN_MATCH + LZ4UnsafeUtils.commonBytes(buf, ref + MIN_MATCH, off + MIN_MATCH, matchLimit); + if (matchLen > match.len) { + match.ref = ref; + match.len = matchLen; + } + } + ref = next(ref); } - copyTo(match3, match2); - continue search3; - } - - // OK, now we have 3 ascending matches; let's write at least the first one - if (match2.start < match1.end()) { - if (match2.start - match1.start < ML_MASK) { - if (match1.len > OPTIMAL_ML) { - match1.len = OPTIMAL_ML; - } - if (match1.end() > match2.end() - MIN_MATCH) { - match1.len = match2.end() - match1.start - MIN_MATCH; - } - final int correction = match1.end() - match2.start; - match2.fix(correction); - } else { - match1.len = match2.start - match1.start; + if (repl != 0) { + int ptr = off; + final int end = off + repl - (MIN_MATCH - 1); + while (ptr < end - delta) { + chainTable[ptr & MASK] = (short) delta; // pre load + ++ptr; + } + do { + chainTable[ptr & MASK] = (short) delta; + hashTable[hashHC(UnsafeUtils.readInt(buf, ptr))] = ptr; + ++ptr; + } while (ptr < end); + nextToUpdate = end; } - } - dOff = LZ4ByteBufferUtils.encodeSequence(src, anchor, match1.start, match1.ref, match1.len, dest, dOff, destEnd); - anchor = sOff = match1.end(); - - copyTo(match2, match1); - copyTo(match3, match2); - - continue search3; + return match.len != 0; + } + + boolean insertAndFindWiderMatch(byte[] buf, int off, int startLimit, int matchLimit, int minLen, Match match) { + match.len = minLen; + + insert(off, buf); + + final int delta = off - startLimit; + int ref = hashPointer(buf, off); + for (int i = 0; i < maxAttempts; ++i) { + if (ref < Math.max(base, off - MAX_DISTANCE + 1) || ref > off) { + break; + } + if (LZ4UnsafeUtils.readIntEquals(buf, ref, off)) { + 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) { + match.len = matchLen; + match.ref = ref - matchLenBackward; + match.start = off - matchLenBackward; + } + } + ref = next(ref); + } + + return match.len > minLen; + } + + + boolean insertAndFindBestMatch(ByteBuffer buf, int off, int matchLimit, Match match) { + match.start = off; + match.len = 0; + int delta = 0; + int repl = 0; + + insert(off, buf); + + int ref = hashPointer(buf, off); + + if (ref >= off - 4 && ref <= off && ref >= base) { // potential repetition + if (LZ4ByteBufferUtils.readIntEquals(buf, ref, off)) { // confirmed + delta = off - ref; + repl = match.len = MIN_MATCH + LZ4ByteBufferUtils.commonBytes(buf, ref + MIN_MATCH, off + MIN_MATCH, matchLimit); + match.ref = ref; + } + ref = next(ref); + } + + for (int i = 0; i < maxAttempts; ++i) { + if (ref < Math.max(base, off - MAX_DISTANCE + 1) || ref > off) { + break; + } + if (LZ4ByteBufferUtils.readIntEquals(buf, ref, off)) { + final int matchLen = MIN_MATCH + LZ4ByteBufferUtils.commonBytes(buf, ref + MIN_MATCH, off + MIN_MATCH, matchLimit); + if (matchLen > match.len) { + match.ref = ref; + match.len = matchLen; + } + } + ref = next(ref); + } + + if (repl != 0) { + int ptr = off; + final int end = off + repl - (MIN_MATCH - 1); + while (ptr < end - delta) { + chainTable[ptr & MASK] = (short) delta; // pre load + ++ptr; + } + do { + chainTable[ptr & MASK] = (short) delta; + hashTable[hashHC(ByteBufferUtils.readInt(buf, ptr))] = ptr; + ++ptr; + } while (ptr < end); + nextToUpdate = end; + } + + return match.len != 0; + } + + boolean insertAndFindWiderMatch(ByteBuffer buf, int off, int startLimit, int matchLimit, int minLen, Match match) { + match.len = minLen; + + insert(off, buf); + + final int delta = off - startLimit; + int ref = hashPointer(buf, off); + for (int i = 0; i < maxAttempts; ++i) { + if (ref < Math.max(base, off - MAX_DISTANCE + 1) || ref > off) { + break; + } + if (LZ4ByteBufferUtils.readIntEquals(buf, ref, off)) { + 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) { + match.len = matchLen; + match.ref = ref - matchLenBackward; + match.start = off - matchLenBackward; + } + } + ref = next(ref); + } + + return match.len > minLen; } - } } - dOff = LZ4ByteBufferUtils.lastLiterals(src, anchor, srcEnd - anchor, dest, dOff, destEnd); - return dOff - destOff; - } + @Override + public int compress(byte[] src, int srcOff, int srcLen, byte[] dest, int destOff, int maxDestLen) { + + UnsafeUtils.checkRange(src, srcOff, srcLen); + UnsafeUtils.checkRange(dest, destOff, maxDestLen); + + final int srcEnd = srcOff + srcLen; + final int destEnd = destOff + maxDestLen; + final int mfLimit = srcEnd - MF_LIMIT; + final int matchLimit = srcEnd - LAST_LITERALS; + + int sOff = srcOff; + int dOff = destOff; + int anchor = sOff++; + + final HashTable ht = new HashTable(srcOff); + final Match match0 = new Match(); + final Match match1 = new Match(); + final Match match2 = new Match(); + final Match match3 = new Match(); + + main: + while (sOff < mfLimit) { + if (!ht.insertAndFindBestMatch(src, sOff, matchLimit, match1)) { + ++sOff; + continue; + } + + // saved, in case we would skip too much + copyTo(match1, match0); + + search2: + while (true) { + assert match1.start >= anchor; + if (match1.end() >= mfLimit + || !ht.insertAndFindWiderMatch(src, match1.end() - 2, match1.start + 1, matchLimit, match1.len, match2)) { + // no better match + dOff = LZ4UnsafeUtils.encodeSequence(src, anchor, match1.start, match1.ref, match1.len, dest, dOff, destEnd); + anchor = sOff = match1.end(); + continue main; + } + + if (match0.start < match1.start) { + if (match2.start < match1.start + match0.len) { // empirical + copyTo(match0, match1); + } + } + assert match2.start > match1.start; + + if (match2.start - match1.start < 3) { // First Match too small : removed + copyTo(match2, match1); + continue search2; + } + + search3: + while (true) { + if (match2.start - match1.start < OPTIMAL_ML) { + int newMatchLen = match1.len; + if (newMatchLen > OPTIMAL_ML) { + newMatchLen = OPTIMAL_ML; + } + if (match1.start + newMatchLen > match2.end() - MIN_MATCH) { + newMatchLen = match2.start - match1.start + match2.len - MIN_MATCH; + } + final int correction = newMatchLen - (match2.start - match1.start); + if (correction > 0) { + match2.fix(correction); + } + } + + if (match2.start + match2.len >= mfLimit + || !ht.insertAndFindWiderMatch(src, match2.end() - 3, match2.start, matchLimit, match2.len, match3)) { + // no better match -> 2 sequences to encode + if (match2.start < match1.end()) { + match1.len = match2.start - match1.start; + } + // encode seq 1 + dOff = LZ4UnsafeUtils.encodeSequence(src, anchor, match1.start, match1.ref, match1.len, dest, dOff, destEnd); + anchor = sOff = match1.end(); + // encode seq 2 + dOff = LZ4UnsafeUtils.encodeSequence(src, anchor, match2.start, match2.ref, match2.len, dest, dOff, destEnd); + anchor = sOff = match2.end(); + continue main; + } + + if (match3.start < match1.end() + 3) { // Not enough space for match 2 : remove it + if (match3.start >= match1.end()) { // // can write Seq1 immediately ==> Seq2 is removed, so Seq3 becomes Seq1 + if (match2.start < match1.end()) { + final int correction = match1.end() - match2.start; + match2.fix(correction); + if (match2.len < MIN_MATCH) { + copyTo(match3, match2); + } + } + + dOff = LZ4UnsafeUtils.encodeSequence(src, anchor, match1.start, match1.ref, match1.len, dest, dOff, destEnd); + anchor = sOff = match1.end(); + + copyTo(match3, match1); + copyTo(match2, match0); + + continue search2; + } + + copyTo(match3, match2); + continue search3; + } + + // OK, now we have 3 ascending matches; let's write at least the first one + if (match2.start < match1.end()) { + if (match2.start - match1.start < ML_MASK) { + if (match1.len > OPTIMAL_ML) { + match1.len = OPTIMAL_ML; + } + if (match1.end() > match2.end() - MIN_MATCH) { + match1.len = match2.end() - match1.start - MIN_MATCH; + } + final int correction = match1.end() - match2.start; + match2.fix(correction); + } else { + match1.len = match2.start - match1.start; + } + } + + dOff = LZ4UnsafeUtils.encodeSequence(src, anchor, match1.start, match1.ref, match1.len, dest, dOff, destEnd); + anchor = sOff = match1.end(); + + copyTo(match2, match1); + copyTo(match3, match2); + + continue search3; + } + + } + + } + + dOff = LZ4UnsafeUtils.lastLiterals(src, anchor, srcEnd - anchor, dest, dOff, destEnd); + return dOff - destOff; + } + + + @Override + public int compress(ByteBuffer src, int srcOff, int srcLen, ByteBuffer dest, int destOff, int maxDestLen) { + + if (src.hasArray() && dest.hasArray()) { + return compress(src.array(), srcOff + src.arrayOffset(), srcLen, dest.array(), destOff + dest.arrayOffset(), maxDestLen); + } + src = ByteBufferUtils.inNativeByteOrder(src); + dest = ByteBufferUtils.inNativeByteOrder(dest); + + ByteBufferUtils.checkRange(src, srcOff, srcLen); + ByteBufferUtils.checkRange(dest, destOff, maxDestLen); + + final int srcEnd = srcOff + srcLen; + final int destEnd = destOff + maxDestLen; + final int mfLimit = srcEnd - MF_LIMIT; + final int matchLimit = srcEnd - LAST_LITERALS; + + int sOff = srcOff; + int dOff = destOff; + int anchor = sOff++; + + final HashTable ht = new HashTable(srcOff); + final Match match0 = new Match(); + final Match match1 = new Match(); + final Match match2 = new Match(); + final Match match3 = new Match(); + + main: + while (sOff < mfLimit) { + if (!ht.insertAndFindBestMatch(src, sOff, matchLimit, match1)) { + ++sOff; + continue; + } + + // saved, in case we would skip too much + copyTo(match1, match0); + + search2: + while (true) { + assert match1.start >= anchor; + if (match1.end() >= mfLimit + || !ht.insertAndFindWiderMatch(src, match1.end() - 2, match1.start + 1, matchLimit, match1.len, match2)) { + // no better match + dOff = LZ4ByteBufferUtils.encodeSequence(src, anchor, match1.start, match1.ref, match1.len, dest, dOff, destEnd); + anchor = sOff = match1.end(); + continue main; + } + + if (match0.start < match1.start) { + if (match2.start < match1.start + match0.len) { // empirical + copyTo(match0, match1); + } + } + assert match2.start > match1.start; + + if (match2.start - match1.start < 3) { // First Match too small : removed + copyTo(match2, match1); + continue search2; + } + + search3: + while (true) { + if (match2.start - match1.start < OPTIMAL_ML) { + int newMatchLen = match1.len; + if (newMatchLen > OPTIMAL_ML) { + newMatchLen = OPTIMAL_ML; + } + if (match1.start + newMatchLen > match2.end() - MIN_MATCH) { + newMatchLen = match2.start - match1.start + match2.len - MIN_MATCH; + } + final int correction = newMatchLen - (match2.start - match1.start); + if (correction > 0) { + match2.fix(correction); + } + } + + if (match2.start + match2.len >= mfLimit + || !ht.insertAndFindWiderMatch(src, match2.end() - 3, match2.start, matchLimit, match2.len, match3)) { + // no better match -> 2 sequences to encode + if (match2.start < match1.end()) { + match1.len = match2.start - match1.start; + } + // encode seq 1 + dOff = LZ4ByteBufferUtils.encodeSequence(src, anchor, match1.start, match1.ref, match1.len, dest, dOff, destEnd); + anchor = sOff = match1.end(); + // encode seq 2 + dOff = LZ4ByteBufferUtils.encodeSequence(src, anchor, match2.start, match2.ref, match2.len, dest, dOff, destEnd); + anchor = sOff = match2.end(); + continue main; + } + + if (match3.start < match1.end() + 3) { // Not enough space for match 2 : remove it + if (match3.start >= match1.end()) { // // can write Seq1 immediately ==> Seq2 is removed, so Seq3 becomes Seq1 + if (match2.start < match1.end()) { + final int correction = match1.end() - match2.start; + match2.fix(correction); + if (match2.len < MIN_MATCH) { + copyTo(match3, match2); + } + } + + dOff = LZ4ByteBufferUtils.encodeSequence(src, anchor, match1.start, match1.ref, match1.len, dest, dOff, destEnd); + anchor = sOff = match1.end(); + + copyTo(match3, match1); + copyTo(match2, match0); + + continue search2; + } + + copyTo(match3, match2); + continue search3; + } + + // OK, now we have 3 ascending matches; let's write at least the first one + if (match2.start < match1.end()) { + if (match2.start - match1.start < ML_MASK) { + if (match1.len > OPTIMAL_ML) { + match1.len = OPTIMAL_ML; + } + if (match1.end() > match2.end() - MIN_MATCH) { + match1.len = match2.end() - match1.start - MIN_MATCH; + } + final int correction = match1.end() - match2.start; + match2.fix(correction); + } else { + match1.len = match2.start - match1.start; + } + } + + dOff = LZ4ByteBufferUtils.encodeSequence(src, anchor, match1.start, match1.ref, match1.len, dest, dOff, destEnd); + anchor = sOff = match1.end(); + + copyTo(match2, match1); + copyTo(match3, match2); + + continue search3; + } + + } + + } + + dOff = LZ4ByteBufferUtils.lastLiterals(src, anchor, srcEnd - anchor, dest, dOff, destEnd); + return dOff - destOff; + } } diff --git a/core/src/main/java/net/jpountz/lz4/LZ4JNI.java b/core/src/main/java/net/jpountz/lz4/LZ4JNI.java index f083319a..9ca38667 100644 --- a/core/src/main/java/net/jpountz/lz4/LZ4JNI.java +++ b/core/src/main/java/net/jpountz/lz4/LZ4JNI.java @@ -15,7 +15,6 @@ package net.jpountz.lz4; */ import java.nio.ByteBuffer; - import net.jpountz.util.Native; diff --git a/core/src/main/java/net/jpountz/lz4/LZ4JNICompressor.java b/core/src/main/java/net/jpountz/lz4/LZ4JNICompressor.java index 18971a33..ba0c047d 100644 --- a/core/src/main/java/net/jpountz/lz4/LZ4JNICompressor.java +++ b/core/src/main/java/net/jpountz/lz4/LZ4JNICompressor.java @@ -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. diff --git a/core/src/main/java/net/jpountz/lz4/LZ4JNIFastDecompressor.java b/core/src/main/java/net/jpountz/lz4/LZ4JNIFastDecompressor.java index 5c355d85..6bffba08 100644 --- a/core/src/main/java/net/jpountz/lz4/LZ4JNIFastDecompressor.java +++ b/core/src/main/java/net/jpountz/lz4/LZ4JNIFastDecompressor.java @@ -16,7 +16,6 @@ package net.jpountz.lz4; import java.nio.ByteBuffer; - import net.jpountz.util.ByteBufferUtils; import net.jpountz.util.SafeUtils; diff --git a/core/src/main/java/net/jpountz/lz4/LZ4JNISafeDecompressor.java b/core/src/main/java/net/jpountz/lz4/LZ4JNISafeDecompressor.java index d948c988..d0404903 100644 --- a/core/src/main/java/net/jpountz/lz4/LZ4JNISafeDecompressor.java +++ b/core/src/main/java/net/jpountz/lz4/LZ4JNISafeDecompressor.java @@ -16,7 +16,6 @@ package net.jpountz.lz4; import java.nio.ByteBuffer; - import net.jpountz.util.ByteBufferUtils; import net.jpountz.util.SafeUtils; diff --git a/core/src/main/java/net/jpountz/lz4/LZ4JavaSafeCompressor.java b/core/src/main/java/net/jpountz/lz4/LZ4JavaSafeCompressor.java index 06d635d6..254f2097 100644 --- a/core/src/main/java/net/jpountz/lz4/LZ4JavaSafeCompressor.java +++ b/core/src/main/java/net/jpountz/lz4/LZ4JavaSafeCompressor.java @@ -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. */ diff --git a/core/src/main/java/net/jpountz/lz4/LZ4JavaSafeFastDecompressor.java b/core/src/main/java/net/jpountz/lz4/LZ4JavaSafeFastDecompressor.java index f9354d67..35278009 100644 --- a/core/src/main/java/net/jpountz/lz4/LZ4JavaSafeFastDecompressor.java +++ b/core/src/main/java/net/jpountz/lz4/LZ4JavaSafeFastDecompressor.java @@ -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. */ diff --git a/core/src/main/java/net/jpountz/lz4/LZ4JavaSafeSafeDecompressor.java b/core/src/main/java/net/jpountz/lz4/LZ4JavaSafeSafeDecompressor.java index 2e77203c..24625dfa 100644 --- a/core/src/main/java/net/jpountz/lz4/LZ4JavaSafeSafeDecompressor.java +++ b/core/src/main/java/net/jpountz/lz4/LZ4JavaSafeSafeDecompressor.java @@ -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. */ diff --git a/core/src/main/java/net/jpountz/lz4/LZ4JavaUnsafeCompressor.java b/core/src/main/java/net/jpountz/lz4/LZ4JavaUnsafeCompressor.java index b52fb521..2da8100d 100644 --- a/core/src/main/java/net/jpountz/lz4/LZ4JavaUnsafeCompressor.java +++ b/core/src/main/java/net/jpountz/lz4/LZ4JavaUnsafeCompressor.java @@ -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. */ diff --git a/core/src/main/java/net/jpountz/lz4/LZ4JavaUnsafeFastDecompressor.java b/core/src/main/java/net/jpountz/lz4/LZ4JavaUnsafeFastDecompressor.java index ca26a4a8..f29e90b3 100644 --- a/core/src/main/java/net/jpountz/lz4/LZ4JavaUnsafeFastDecompressor.java +++ b/core/src/main/java/net/jpountz/lz4/LZ4JavaUnsafeFastDecompressor.java @@ -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. */ diff --git a/core/src/main/java/net/jpountz/lz4/LZ4JavaUnsafeSafeDecompressor.java b/core/src/main/java/net/jpountz/lz4/LZ4JavaUnsafeSafeDecompressor.java index 2bf83e51..5df579b8 100644 --- a/core/src/main/java/net/jpountz/lz4/LZ4JavaUnsafeSafeDecompressor.java +++ b/core/src/main/java/net/jpountz/lz4/LZ4JavaUnsafeSafeDecompressor.java @@ -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. */ diff --git a/core/src/main/java/net/jpountz/lz4/LZ4OutputStream.java b/core/src/main/java/net/jpountz/lz4/LZ4OutputStream.java index af16abab..cd7813fe 100644 --- a/core/src/main/java/net/jpountz/lz4/LZ4OutputStream.java +++ b/core/src/main/java/net/jpountz/lz4/LZ4OutputStream.java @@ -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(); diff --git a/core/src/main/java/net/jpountz/lz4/LZ4SafeUtils.java b/core/src/main/java/net/jpountz/lz4/LZ4SafeUtils.java index 7842bd77..66ffc807 100644 --- a/core/src/main/java/net/jpountz/lz4/LZ4SafeUtils.java +++ b/core/src/main/java/net/jpountz/lz4/LZ4SafeUtils.java @@ -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 { ; diff --git a/core/src/main/java/net/jpountz/lz4/LZ4StreamHelper.java b/core/src/main/java/net/jpountz/lz4/LZ4StreamHelper.java index 1f42692f..cce21c58 100644 --- a/core/src/main/java/net/jpountz/lz4/LZ4StreamHelper.java +++ b/core/src/main/java/net/jpountz/lz4/LZ4StreamHelper.java @@ -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 { diff --git a/core/src/main/java/net/jpountz/lz4/LZ4StreamTest.java b/core/src/main/java/net/jpountz/lz4/LZ4StreamTest.java index ca2d7cf7..d3d270f2 100644 --- a/core/src/main/java/net/jpountz/lz4/LZ4StreamTest.java +++ b/core/src/main/java/net/jpountz/lz4/LZ4StreamTest.java @@ -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; diff --git a/core/src/main/java/net/jpountz/util/LZ4UnsafeUtils.java b/core/src/main/java/net/jpountz/lz4/LZ4UnsafeUtils.java similarity index 99% rename from core/src/main/java/net/jpountz/util/LZ4UnsafeUtils.java rename to core/src/main/java/net/jpountz/lz4/LZ4UnsafeUtils.java index a5ad7834..6eb08ab6 100644 --- a/core/src/main/java/net/jpountz/util/LZ4UnsafeUtils.java +++ b/core/src/main/java/net/jpountz/lz4/LZ4UnsafeUtils.java @@ -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 { ; diff --git a/core/src/main/java/net/jpountz/lz4/LZ4Utils.java b/core/src/main/java/net/jpountz/lz4/LZ4Utils.java index a6a84d6a..5661c417 100644 --- a/core/src/main/java/net/jpountz/lz4/LZ4Utils.java +++ b/core/src/main/java/net/jpountz/lz4/LZ4Utils.java @@ -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 { ; diff --git a/core/src/main/java/net/jpountz/util/Native.java b/core/src/main/java/net/jpountz/util/Native.java index d4a8707b..af728479 100644 --- a/core/src/main/java/net/jpountz/util/Native.java +++ b/core/src/main/java/net/jpountz/util/Native.java @@ -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."); diff --git a/core/src/main/java/net/jpountz/util/UnsafeUtils.java b/core/src/main/java/net/jpountz/util/UnsafeUtils.java index 30231ef1..6d673b9e 100644 --- a/core/src/main/java/net/jpountz/util/UnsafeUtils.java +++ b/core/src/main/java/net/jpountz/util/UnsafeUtils.java @@ -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 { ; diff --git a/core/src/main/java/net/jpountz/xxhash/AbstractStreamingXXHash32Java.java b/core/src/main/java/net/jpountz/xxhash/AbstractStreamingXXHash32Java.java deleted file mode 100644 index 3dd3ed4f..00000000 --- a/core/src/main/java/net/jpountz/xxhash/AbstractStreamingXXHash32Java.java +++ /dev/null @@ -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; - } - -} diff --git a/core/src/main/java/net/jpountz/xxhash/AbstractStreamingXXHash64Java.java b/core/src/main/java/net/jpountz/xxhash/AbstractStreamingXXHash64Java.java deleted file mode 100644 index 97e294dd..00000000 --- a/core/src/main/java/net/jpountz/xxhash/AbstractStreamingXXHash64Java.java +++ /dev/null @@ -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; - } - -} diff --git a/core/src/main/java/net/jpountz/xxhash/StreamingXXHash32.java b/core/src/main/java/net/jpountz/xxhash/StreamingXXHash32.java deleted file mode 100644 index c59f0346..00000000 --- a/core/src/main/java/net/jpountz/xxhash/StreamingXXHash32.java +++ /dev/null @@ -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}. - *

- * This API is compatible with the {@link XXHash32 block API} and the following - * code samples are equivalent: - *

- *   int hash(XXHashFactory xxhashFactory, byte[] buf, int off, int len, int seed) {
- *     return xxhashFactory.hash32().hash(buf, off, len, seed);
- *   }
- * 
- *
- *   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();
- *   }
- * 
- *

- * Instances of this class are not 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(); - } - - }; - } - -} \ No newline at end of file diff --git a/core/src/main/java/net/jpountz/xxhash/StreamingXXHash32JNI.java b/core/src/main/java/net/jpountz/xxhash/StreamingXXHash32JNI.java deleted file mode 100644 index e9b58fb4..00000000 --- a/core/src/main/java/net/jpountz/xxhash/StreamingXXHash32JNI.java +++ /dev/null @@ -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; - } - -} diff --git a/core/src/main/java/net/jpountz/xxhash/StreamingXXHash64.java b/core/src/main/java/net/jpountz/xxhash/StreamingXXHash64.java deleted file mode 100644 index c68fb4d1..00000000 --- a/core/src/main/java/net/jpountz/xxhash/StreamingXXHash64.java +++ /dev/null @@ -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}. - *

- * This API is compatible with the {@link XXHash64 block API} and the following - * code samples are equivalent: - *

- *   long hash(XXHashFactory xxhashFactory, byte[] buf, int off, int len, long seed) {
- *     return xxhashFactory.hash64().hash(buf, off, len, seed);
- *   }
- * 
- *
- *   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();
- *   }
- * 
- *

- * Instances of this class are not 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(); - } - - }; - } - -} \ No newline at end of file diff --git a/core/src/main/java/net/jpountz/xxhash/StreamingXXHash64JNI.java b/core/src/main/java/net/jpountz/xxhash/StreamingXXHash64JNI.java deleted file mode 100644 index b7ab1acd..00000000 --- a/core/src/main/java/net/jpountz/xxhash/StreamingXXHash64JNI.java +++ /dev/null @@ -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; - } - -} diff --git a/core/src/main/java/net/jpountz/xxhash/XXHash32.java b/core/src/main/java/net/jpountz/xxhash/XXHash32.java deleted file mode 100644 index 5d211436..00000000 --- a/core/src/main/java/net/jpountz/xxhash/XXHash32.java +++ /dev/null @@ -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. - *

- * Instances of this class are thread-safe. - */ -public abstract class XXHash32 { - - /** - * Compute the 32-bits hash of buf[off:off+len] using seed - * seed. - */ - 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(); - } - -} diff --git a/core/src/main/java/net/jpountz/xxhash/XXHash32JNI.java b/core/src/main/java/net/jpountz/xxhash/XXHash32JNI.java deleted file mode 100644 index 4b713d11..00000000 --- a/core/src/main/java/net/jpountz/xxhash/XXHash32JNI.java +++ /dev/null @@ -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); - } - } - -} diff --git a/core/src/main/java/net/jpountz/xxhash/XXHash64.java b/core/src/main/java/net/jpountz/xxhash/XXHash64.java deleted file mode 100644 index 3ab73ddc..00000000 --- a/core/src/main/java/net/jpountz/xxhash/XXHash64.java +++ /dev/null @@ -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. - *

- * Instances of this class are thread-safe. - */ -public abstract class XXHash64 { - - /** - * Compute the 64-bits hash of buf[off:off+len] using seed - * seed. - */ - 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(); - } - -} diff --git a/core/src/main/java/net/jpountz/xxhash/XXHash64JNI.java b/core/src/main/java/net/jpountz/xxhash/XXHash64JNI.java deleted file mode 100644 index d952e1e5..00000000 --- a/core/src/main/java/net/jpountz/xxhash/XXHash64JNI.java +++ /dev/null @@ -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); - } - } - -} diff --git a/core/src/main/java/net/jpountz/xxhash/XXHashConstants.java b/core/src/main/java/net/jpountz/xxhash/XXHashConstants.java deleted file mode 100644 index 2e887dfd..00000000 --- a/core/src/main/java/net/jpountz/xxhash/XXHashConstants.java +++ /dev/null @@ -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; -} diff --git a/core/src/main/java/net/jpountz/xxhash/XXHashFactory.java b/core/src/main/java/net/jpountz/xxhash/XXHashFactory.java deleted file mode 100644 index ab03dff1..00000000 --- a/core/src/main/java/net/jpountz/xxhash/XXHashFactory.java +++ /dev/null @@ -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. - *

- * This class has 3 instances

    - *
  • a {@link #nativeInstance() native} instance which is a JNI binding to - * the original LZ4 C implementation. - *
  • a {@link #safeInstance() safe Java} instance which is a pure Java port - * of the original C library,
  • - *
  • an {@link #unsafeInstance() unsafe Java} instance which is a Java port - * using the unofficial {@link sun.misc.Unsafe} API. - *
- *

- * 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. - *

- * 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. - *

- * Please note that this instance has some traps you should be aware of:

    - *
  1. 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. - *
  2. 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. - *
- */ - 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. - *

- * 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 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; - } - -} diff --git a/core/src/main/java/net/jpountz/xxhash/XXHashJNI.java b/core/src/main/java/net/jpountz/xxhash/XXHashJNI.java deleted file mode 100644 index 125e640b..00000000 --- a/core/src/main/java/net/jpountz/xxhash/XXHashJNI.java +++ /dev/null @@ -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); -} diff --git a/core/src/main/java/net/jpountz/xxhash/package.html b/core/src/main/java/net/jpountz/xxhash/package.html deleted file mode 100644 index f595d25a..00000000 --- a/core/src/main/java/net/jpountz/xxhash/package.html +++ /dev/null @@ -1,65 +0,0 @@ - - - - - - - -

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.

- -

Streaming hashing is a little slower but doesn't require to load the whole -stream into memory.

- -

Sample block usage:

- -
-    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);
-
- -

Sample streaming usage:

- -
-    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();
-
- - - diff --git a/forge/.gradle/gradle.log b/forge/.gradle/gradle.log index e69de29b..d7ab305b 100644 --- a/forge/.gradle/gradle.log +++ b/forge/.gradle/gradle.log @@ -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 diff --git a/forge/src/main/java/com/boydti/fawe/forge/v1_8/SpongeChunk_1_8.java b/forge/src/main/java/com/boydti/fawe/forge/v1_8/SpongeChunk_1_8.java index 47032911..46b68d64 100644 --- a/forge/src/main/java/com/boydti/fawe/forge/v1_8/SpongeChunk_1_8.java +++ b/forge/src/main/java/com/boydti/fawe/forge/v1_8/SpongeChunk_1_8.java @@ -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 { @@ -29,7 +30,8 @@ public class SpongeChunk_1_8 extends FaweChunk { @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; }