/** Loads elements from a file given by a pathname, storing them in a given big array. * * @param filename a filename. * @param array a big array which will be filled with data from the specified file. * @return the number of elements actually read from the given file (it might be less than the array length if the file is too short). */ public static long loadInts(final CharSequence filename, final int[][] array) throws IOException { return loadInts(new File(filename.toString()), array); } /** Loads elements from a file given by a {@link File} object, storing them in a new big array.
/** Loads elements from a file given by a pathname, storing them in a given array. * * @param filename a filename. * @param array an array which will be filled with data from the specified file. * @return the number of elements actually read from the given file (it might be less than the array length if the file is too short). */ public static int loadInts(final CharSequence filename, final int[] array) throws IOException { return loadInts(new File(filename.toString()), array); } /** Loads elements from a file given by a {@link File} object, storing them in a new array.
/** Creates a new instance. * * @param classFile name of the class file. * @param keepOnlySame whether to keep nodes in the same class. */ public NodeClassFilter(final String classFile, final boolean keepOnlySame) { try { nodeClass = BinIO.loadInts(classFile); } catch (final IOException e) { throw new RuntimeException(e); } this.keepOnlySame = keepOnlySame; }
/** Loads elements from a file given by a pathname, storing them in a given array fragment. * * @param filename a filename. * @param array an array which will be filled with data from the specified file. * @param offset the index of the first element of {@code array} to be filled. * @param length the number of elements of {@code array} to be filled. * @return the number of elements actually read from the given file (it might be less than {@code length} if the file is too short). */ public static int loadInts(final CharSequence filename, final int[] array, final int offset, final int length) throws IOException { return loadInts(new File(filename.toString()), array, offset, length); } /** Loads elements from a file given by a {@link File} object, storing them in a given array.
/** Loads elements from a file given by a pathname, storing them in a given big-array fragment. * * @param filename a filename. * @param array an array which will be filled with data from the specified file. * @param offset the index of the first element of {@code array} to be filled. * @param length the number of elements of {@code array} to be filled. * @return the number of elements actually read from the given file (it might be less than {@code length} if the file is too short). */ public static long loadInts(final CharSequence filename, final int[][] array, final long offset, final long length) throws IOException { return loadInts(new File(filename.toString()), array, offset, length); } /** Loads elements from a file given by a {@link File} object, storing them in a given big array.
/** Loads elements from a file given by a filename, storing them in a new array. * * <p>Note that the length of the returned array will be computed * dividing the specified file size by the number of bytes used to * represent each element. * * @param filename a filename. * @return an array filled with the content of the specified file. */ public static int[] loadInts(final CharSequence filename) throws IOException { return loadInts(new File(filename.toString())); } /** Stores an array fragment to a given data output.
static void fillArrayFromResource( final String resource, final int array[] ) throws IOException { final String resouceFullPath = "/it/unimi/dsi/io/" + resource; final InputStream ris = InputBitStream.class.getResourceAsStream( resouceFullPath ); if ( ris == null ) throw new IOException( "Cannot open resource " + resouceFullPath ); DataInputStream dis = new DataInputStream( new FastBufferedInputStream( ris ) ); BinIO.loadInts( dis, array, 0, array.length ); dis.close(); if ( ASSERTS ) { final int actualLength = IntIterators.unwrap( BinIO.asIntIterator( new DataInputStream( InputBitStream.class.getResourceAsStream( resouceFullPath ) ) ) ).length; assert array.length == actualLength : resource + " is long " + actualLength + " but we think it should rather be " + array.length; } }
static void fillArrayFromResource( final String resource, final int array[] ) throws IOException { final String resouceFullPath = "/it/unimi/dsi/io/" + resource; final InputStream ris = InputBitStream.class.getResourceAsStream( resouceFullPath ); if ( ris == null ) throw new IOException( "Cannot open resource " + resouceFullPath ); DataInputStream dis = new DataInputStream( new FastBufferedInputStream( ris ) ); BinIO.loadInts( dis, array, 0, array.length ); dis.close(); if ( ASSERTS ) { final int actualLength = IntIterators.unwrap( BinIO.asIntIterator( new DataInputStream( InputBitStream.class.getResourceAsStream( resouceFullPath ) ) ) ).length; assert array.length == actualLength : resource + " is long " + actualLength + " but we think it should rather be " + array.length; } }
static void fillArrayFromResource(final String resource, final int array[]) throws IOException { final String resouceFullPath = "/it/unimi/dsi/io/" + resource; final InputStream ris = InputBitStream.class.getResourceAsStream(resouceFullPath); if (ris == null) throw new IOException("Cannot open resource " + resouceFullPath); DataInputStream dis = new DataInputStream(new FastBufferedInputStream(ris)); BinIO.loadInts(dis, array, 0, array.length); dis.close(); assert checkLength(resource, array, resouceFullPath); }
position = null; position = new int[ oldLength + POSITIONS_EMERGENCY_INCREMENT ]; BinIO.loadInts( temp, position ); temp.delete();
position = null; position = new int[ oldLength + POSITIONS_EMERGENCY_INCREMENT ]; BinIO.loadInts( temp, position ); temp.delete();
position = null; position = new int[ oldLength + POSITIONS_EMERGENCY_INCREMENT ]; BinIO.loadInts( temp, position ); temp.delete();
position = null; position = new int[ oldLength + POSITIONS_EMERGENCY_INCREMENT ]; BinIO.loadInts( temp, position ); temp.delete();
/** Creates a new immutable subgraph by loading the supergraph, delegating the * actual loading to the class specified in the <code>supergraphclass</code> property within the property * file (named <code><var>basename</var>.properties</code>), and loading the subgraph array in memory. * The exact load method to be used depends on the <code>method</code> argument. * * @param method the method to be used to load the supergraph. * @param basename the basename of the graph. * @param pl the progress logger; it can be <code>null</code>. * @return an immutable subgraph containing the specified graph. */ protected static ImmutableGraph load(final LoadMethod method, final CharSequence basename, final ProgressLogger pl) throws IOException { final FileInputStream propertyFile = new FileInputStream(basename + PROPERTIES_EXTENSION); final Properties properties = new Properties(); properties.load(propertyFile); propertyFile.close(); final String graphClassName = properties.getProperty(ImmutableGraph.GRAPHCLASS_PROPERTY_KEY); if (! graphClassName.equals(ImmutableSubgraph.class.getName())) throw new IOException("This class (" + ImmutableSubgraph.class.getName() + ") cannot load a graph stored using " + graphClassName); final String supergraphBasename = properties.getProperty(SUPERGRAPHBASENAME_PROPERTY_KEY); if (supergraphBasename == null) throw new IOException("This property file does not specify the required property supergraphbasename"); final ImmutableGraph supergraph = ImmutableGraph.load(method, supergraphBasename, null, pl); if (pl != null) pl.start("Reading nodes..."); final String nodes = properties.getProperty(SUBGRAPHNODES_PROPERTY_KEY); final ImmutableSubgraph isg = new ImmutableSubgraph(supergraph, BinIO.loadInts(nodes != null ? nodes : basename + ".nodes")); if (pl != null) { pl.count = isg.numNodes(); pl.done(); } isg.basename = new MutableString(basename); return isg; }
final int[] sccsize = new File(basename + ".sccsizes").exists() ? BinIO.loadInts(basename + ".sccsizes") : null;
final int[] weight = weightFile != null ? BinIO.loadInts(weightFile) : null;
public static void main( final String[] arg ) throws IOException, ClassNotFoundException, JSAPException { SimpleJSAP jsap = new SimpleJSAP( PermutedFrontCodedStringList.class.getName(), "Builds a permuted front-coded list of strings using a given front-coded string list and permutation", new Parameter[] { new Switch( "invert", 'i', "invert", "Invert permutation before creating the permuted list." ), new UnflaggedOption( "list", JSAP.STRING_PARSER, JSAP.REQUIRED, "A front-coded string list." ), new UnflaggedOption( "permutation", JSAP.STRING_PARSER, JSAP.REQUIRED, "A permutation for the indices of the list." ), new UnflaggedOption( "permutedList", JSAP.STRING_PARSER, JSAP.REQUIRED, "A the filename for the resulting permuted list." ), } ); JSAPResult jsapResult = jsap.parse( arg ); if ( jsap.messagePrinted() ) return; int[] basePermutation = BinIO.loadInts( jsapResult.getString( "permutation" ) ), permutation; if ( jsapResult.getBoolean( "invert" ) ) { int i = basePermutation.length; permutation = new int[ i ]; while( i-- != 0 ) permutation[ basePermutation[ i ] ] = i; } else permutation = basePermutation; basePermutation = null; BinIO.storeObject( new PermutedFrontCodedStringList( (FrontCodedStringList)BinIO.loadObject( jsapResult.getString( "list" ) ), permutation ), jsapResult.getString( "permutedList" ) ); } }
public static void main( final String[] arg ) throws IOException, ClassNotFoundException, JSAPException { SimpleJSAP jsap = new SimpleJSAP( PermutedFrontCodedStringList.class.getName(), "Builds a permuted front-coded list of strings using a given front-coded string list and permutation", new Parameter[] { new Switch( "invert", 'i', "invert", "Invert permutation before creating the permuted list." ), new UnflaggedOption( "list", JSAP.STRING_PARSER, JSAP.REQUIRED, "A front-coded string list." ), new UnflaggedOption( "permutation", JSAP.STRING_PARSER, JSAP.REQUIRED, "A permutation for the indices of the list." ), new UnflaggedOption( "permutedList", JSAP.STRING_PARSER, JSAP.REQUIRED, "A the filename for the resulting permuted list." ), } ); JSAPResult jsapResult = jsap.parse( arg ); if ( jsap.messagePrinted() ) return; int[] basePermutation = BinIO.loadInts( jsapResult.getString( "permutation" ) ), permutation; if ( jsapResult.getBoolean( "invert" ) ) { int i = basePermutation.length; permutation = new int[ i ]; while( i-- != 0 ) permutation[ basePermutation[ i ] ] = i; } else permutation = basePermutation; basePermutation = null; BinIO.storeObject( new PermutedFrontCodedStringList( (FrontCodedStringList)BinIO.loadObject( jsapResult.getString( "list" ) ), permutation ), jsapResult.getString( "permutedList" ) ); } }
public static void main(final String[] arg) throws IOException, ClassNotFoundException, JSAPException { SimpleJSAP jsap = new SimpleJSAP(PermutedFrontCodedStringList.class.getName(), "Builds a permuted front-coded list of strings using a given front-coded string list and a permutation (either in text or binary format).", new Parameter[] { new Switch("invert", 'i', "invert", "Invert permutation before creating the permuted list."), new Switch("text", 't', "text", "The permutation is a text file."), new UnflaggedOption("list", JSAP.STRING_PARSER, JSAP.REQUIRED, "A front-coded string list."), new UnflaggedOption("permutation", JSAP.STRING_PARSER, JSAP.REQUIRED, "A permutation for the indices of the list (in DataInput format, unless you specify --text)."), new UnflaggedOption("permutedList", JSAP.STRING_PARSER, JSAP.REQUIRED, "A the filename for the resulting permuted list."), }); JSAPResult jsapResult = jsap.parse(arg); if (jsap.messagePrinted()) return; final String permutationFile = jsapResult.getString("permutation"); final int[] permutation = jsapResult.userSpecified("text") ? IntIterators.unwrap(TextIO.asIntIterator(permutationFile)) : BinIO.loadInts(permutationFile); if (jsapResult.getBoolean("invert")) Util.invertPermutationInPlace(permutation); BinIO.storeObject( new PermutedFrontCodedStringList((FrontCodedStringList)BinIO.loadObject(jsapResult.getString("list")), permutation), jsapResult.getString("permutedList") ); } }
final int[] map = mapFile != null ? BinIO.loadInts( mapFile ) : null;