code
stringlengths
73
34.1k
label
stringclasses
1 value
public int available() { long amount = getHeader().getLength() - getPosition(); return (amount > Integer.MAX_VALUE? Integer.MAX_VALUE: (int)amount); }
java
protected void skip() throws IOException { if (this.eor) { return; } // Read to the end of the body of the record. Exhaust the stream. // Can't skip direct to end because underlying stream may be compressed // and we're calculating the digest for the record. ...
java
public GenerationFileHandler rotate(String storeSuffix, String activeSuffix) throws IOException { return rotate(storeSuffix, activeSuffix, false); }
java
public static GenerationFileHandler makeNew(String filename, boolean append, boolean shouldManifest) throws SecurityException, IOException { FileUtils.moveAsideIfExists(new File(filename)); return new GenerationFileHandler(filename, append, shouldManifest); }
java
public T next() { if (!hasNext()) { throw new NoSuchElementException(); } // 'next' is guaranteed non-null by a hasNext() which returned true T returnObj = this.next; this.next = null; return returnObj; }
java
public static byte[] readToNull(InputStream is, int maxSize) throws IOException { byte[] bytes = new byte[maxSize]; int i = 0; while(i < maxSize) { int b = is.read(); if(b == -1) { throw new EOFException("NO NULL"); } bytes[i] = (byte) (b & 0xff); i++; if(b == 0) { return copy(bytes,0...
java
static public void main(String[] args) { if (args.length == 0) { System.out.println("Supply a Base32-encoded argument."); return; } System.out.println(" Original: " + args[0]); byte[] decoded = Base32.decode(args[0]); System.out.print(" Hex: "); ...
java
public void readHeader(InputStream in) throws IOException { CRC32 crc = new CRC32(); crc.reset(); if (!testGzipMagic(in, crc)) { throw new NoGzipMagicException(); } this.length += 2; if (readByte(in, crc) != Deflater.DEFLATED) { throw new IOExcepti...
java
private int readInt(InputStream in, CRC32 crc) throws IOException { int s = readShort(in, crc); return ((readShort(in, crc) << 16) & 0xffff0000) | s; }
java
public String getHostBasename() throws URIException { // caching eliminated because this is rarely used // (only benefits legacy DomainScope, which should // be retired). Saves 4-byte object pointer in UURI // instances. return (this.getReferencedHost() == null) ? nu...
java
protected void coalesceUriStrings() { if (this.cachedString != null && this.cachedEscapedURI != null && this.cachedString.length() == this.cachedEscapedURI.length()) { // lengths will only be identical if contents are identical // (deescaping will always shrink length), s...
java
protected void coalesceHostAuthorityStrings() { if (this.cachedAuthorityMinusUserinfo != null && this.cachedHost != null && this.cachedHost.length() == this.cachedAuthorityMinusUserinfo.length()) { // lengths can only be identical if contents ...
java
public String getReferencedHost() throws URIException { String referencedHost = this.getHost(); if(referencedHost==null && this.getScheme().equals("dns")) { // extract target domain of DNS lookup String possibleHost = this.getCurrentHierPath(); if(possibleHost != null...
java
public static boolean hasScheme(String possibleUrl) { boolean result = false; for (int i = 0; i < possibleUrl.length(); i++) { char c = possibleUrl.charAt(i); if (c == ':') { if (i != 0) { result = true; } break;...
java
public void write(OutputStream out) throws IOException { for(HttpHeader header: this) { header.write(out); } out.write(CR); out.write(LF); }
java
private static boolean finishLastResponse(final HttpConnection conn) { InputStream lastResponse = conn.getLastResponseInputStream(); if(lastResponse != null) { conn.setLastResponseInputStream(null); try { lastResponse.close(); return true; ...
java
private byte [] generateARCFileMetaData(String date) throws IOException { if(date!=null && date.length()>14) { date = date.substring(0,14); } int metadataBodyLength = getMetadataLength(); // If metadata body, then the minor part of the version is '1' rather // tha...
java
protected String validateMetaLine(String metaLineStr) throws IOException { if (metaLineStr.length() > MAX_METADATA_LINE_LENGTH) { throw new IOException("Metadata line too long (" + metaLineStr.length() + ">" + MAX_METADATA_LINE_LENGTH + "): " + metaLineStr); ...
java
private void writeRecord( OutputStream out, HttpHeaders headers, byte[] contents) throws IOException { if ( contents == null ) { headers.add(CONTENT_LENGTH, "0"); } else { headers.add(CONTENT_LENGTH,String.valueOf(con...
java
public static ArchiveReader get(final String arcFileOrUrl) throws MalformedURLException, IOException { return ArchiveReaderFactory.factory.getArchiveReader(arcFileOrUrl); }
java
public int getIntegerValue() throws IOException, SaneException { // check for type agreement Preconditions.checkState(getValueType() == OptionValueType.INT, "option is not an integer"); Preconditions.checkState(getValueCount() == 1, "option is an integer array, not integer"); // Send RCP corresponding ...
java
public boolean setBooleanValue(boolean value) throws IOException, SaneException { ControlOptionResult result = writeOption(SaneWord.forInt(value ? 1 : 0)); Preconditions.checkState(result.getType() == OptionValueType.BOOLEAN); return SaneWord.fromBytes(result.getValue()).integerValue() != 0; }
java
public double setFixedValue(double value) throws IOException, SaneException { Preconditions.checkArgument( value >= -32768 && value <= 32767.9999, "value " + value + " is out of range"); SaneWord wordValue = SaneWord.forFixedPrecision(value); ControlOptionResult result = writeOption(wordValue); ...
java
public int setIntegerValue(int newValue) throws IOException, SaneException { Preconditions.checkState(getValueCount() == 1, "option is an array"); // check that this option is readable Preconditions.checkState(isWriteable()); // Send RPC corresponding to: // // SANE_Status sane_control_option ...
java
@Override public void close() throws IOException { if (!isOpen()) { throw new IOException("device is already closed"); } session.closeDevice(handle); handle = null; }
java
public List<SaneOption> listOptions() throws IOException { if (optionTitleMap == null) { groups.clear(); optionTitleMap = Maps.uniqueIndex( SaneOption.optionsFor(this), new Function<SaneOption, String>() { @Override public String appl...
java
void addOption(SaneOption option) { Preconditions.checkState(option.getGroup() == this); options.add(option); }
java
public static SaneSession withRemoteSane(InetAddress saneAddress, int port) throws IOException { return withRemoteSane(saneAddress, port, 0, TimeUnit.MILLISECONDS, 0, TimeUnit.MILLISECONDS); }
java
public List<SaneDevice> listDevices() throws IOException, SaneException { outputStream.write(SaneRpcCode.SANE_NET_GET_DEVICES); outputStream.flush(); return inputStream.readDeviceList(); }
java
@Override public void close() throws IOException { try { outputStream.write(SaneRpcCode.SANE_NET_EXIT); outputStream.close(); } finally { socket.close(); } }
java
boolean authorize(String resource) throws IOException { if (passwordProvider == null) { throw new IOException( "Authorization failed - no password provider present " + "(you must call setPasswordProvider)"); } if (passwordProvider.canAuthenticate(resource)) { // RPC code...
java
private void writePassword(String resource, String password) throws IOException { String[] resourceParts = resource.split("\\$MD5\\$"); if (resourceParts.length == 1) { // Write in clean outputStream.write(password); } else { outputStream.write("$MD5$" + SanePasswordEncoder.derivePassword(...
java
public void ignoreTileDao(TileDao tileDao) { GeoPackageOverlay tileOverlay = new GeoPackageOverlay(tileDao); linkedOverlays.add(tileOverlay); }
java
private List<Point> simplifyPoints(List<Point> points) { List<Point> simplifiedPoints = null; if (simplifyTolerance != null) { // Reproject to web mercator if not in meters if (projection != null && !projection.isUnit(Units.METRES)) { points = toWebMercator.tran...
java
public PolygonOrientation getOrientation(List<LatLng> points) { return SphericalUtil.computeSignedArea(points) >= 0 ? PolygonOrientation.COUNTERCLOCKWISE : PolygonOrientation.CLOCKWISE; }
java
public static GoogleMapShape addShapeToMap(GoogleMap map, GoogleMapShape shape) { GoogleMapShape addedShape = null; switch (shape.getShapeType()) { case LAT_LNG: addedShape = new GoogleMapShape(shape.getGeometryType(), ...
java
public static mil.nga.geopackage.map.geom.MultiPolygon addPolygonsToMap( GoogleMap map, MultiPolygonOptions polygons) { mil.nga.geopackage.map.geom.MultiPolygon multiPolygon = new mil.nga.geopackage.map.geom.MultiPolygon(); for (PolygonOptions polygonOption : polygons.getPolygonOptions()) { ...
java
public List<Marker> addPointsToMapAsMarkers(GoogleMap map, List<LatLng> points, MarkerOptions customMarkerOptions, boolean ignoreIdenticalEnds) { List<Marker> markers = new ArrayList<Marker>(); for (int i = ...
java
public PolylineMarkers addPolylineToMapAsMarkers(GoogleMap map, PolylineOptions polylineOptions, MarkerOptions polylineMarkerOptions, PolylineOptions globalPolyl...
java
public PolygonMarkers addPolygonToMapAsMarkers( GoogleMapShapeMarkers shapeMarkers, GoogleMap map, PolygonOptions polygonOptions, MarkerOptions polygonMarkerOptions, MarkerOptions polygonMarkerHoleOptions, PolygonOptions globalPolygonOptions) { PolygonMarkers pol...
java
public MultiPolylineMarkers addMultiPolylineToMapAsMarkers( GoogleMapShapeMarkers shapeMarkers, GoogleMap map, MultiPolylineOptions multiPolyline, MarkerOptions polylineMarkerOptions, PolylineOptions globalPolylineOptions) { MultiPolylineMarkers polylines = new Mu...
java
public MultiPolygonMarkers addMultiPolygonToMapAsMarkers( GoogleMapShapeMarkers shapeMarkers, GoogleMap map, MultiPolygonOptions multiPolygon, MarkerOptions polygonMarkerOptions, MarkerOptions polygonMarkerHoleOptions, PolygonOptions globalPolygonOptions) { ...
java
public List<LatLng> getPointsFromMarkers(List<Marker> markers) { List<LatLng> points = new ArrayList<LatLng>(); for (Marker marker : markers) { points.add(marker.getPosition()); } return points; }
java
public BoundingBox boundingBoxToWebMercator(BoundingBox boundingBox) { if (projection == null) { throw new GeoPackageException("Shape Converter projection is null"); } return boundingBox.transform(toWebMercator); }
java
public BoundingBox boundingBoxToWgs84(BoundingBox boundingBox) { if (projection == null) { throw new GeoPackageException("Shape Converter projection is null"); } return boundingBox.transform(toWgs84); }
java
public BoundingBox boundingBoxFromWebMercator(BoundingBox boundingBox) { if (projection == null) { throw new GeoPackageException("Shape Converter projection is null"); } return boundingBox.transform(fromWebMercator); }
java
public BoundingBox boundingBoxFromWgs84(BoundingBox boundingBox) { if (projection == null) { throw new GeoPackageException("Shape Converter projection is null"); } return boundingBox.transform(fromWgs84); }
java
public void setDateFormat(java.text.DateFormat dateFormat, java.text.DateFormat numbersDateFormat) { this.customDateFormat = dateFormat; this.secondaryDateFormat = numbersDateFormat; // update the spinner with the new date format: // the only spinner item that will be affected is the mo...
java
public void setShowPastItems(boolean enable) { if(enable && !showPastItems) { // first reset the minimum date if necessary: if(getMinDate() != null && compareCalendarDates(getMinDate(), Calendar.getInstance()) == 0) setMinDate(null); // create the yesterday a...
java
public void setShowMonthItem(boolean enable) { if(enable && !showMonthItem) { // create the in 1 month item final Calendar date = Calendar.getInstance(); date.add(Calendar.MONTH, 1); addAdapterItem(new DateItem(formatDate(date), date, R.id.date_month)); } ...
java
public void setFlags(int modeOrFlags) { setShowPastItems((modeOrFlags & ReminderDatePicker.FLAG_PAST) != 0); setShowMonthItem((modeOrFlags & ReminderDatePicker.FLAG_MONTH) != 0); setShowWeekdayNames((modeOrFlags & ReminderDatePicker.FLAG_WEEKDAY_NAMES) != 0); setShowNumbersInView((modeOr...
java
private float brightness(int color) { int r = (color >> 16) & 0xFF; int g = (color >> 8) & 0xFF; int b = color & 0xFF; int V = Math.max(b, Math.max(r, g)); return (V / 255.f); }
java
private @Nullable Calendar getNextItemDate(Calendar searchDate) { final int last = dateSpinner.getLastItemPosition(); for (int i=0; i<=last; i++) { final Calendar date = ((DateItem) dateSpinner.getItemAtPosition(i)).getDate(); // use the DateSpinner's compare method so hours and ...
java
public void setSelectedDate(Calendar date) { if(date!=null) { dateSpinner.setSelectedDate(date); timeSpinner.setSelectedTime(date.get(Calendar.HOUR_OF_DAY), date.get(Calendar.MINUTE)); // a custom selection has been set, don't select the default date: shouldSelect...
java
public void setSelectedDate(int year, int month, int day) { dateSpinner.setSelectedDate(new GregorianCalendar(year, month, day)); // a custom selection has been set, don't select the default date: shouldSelectDefault = false; }
java
public void setHideTime(boolean enable, final boolean useDarkTheme) { if(enable && !shouldHideTime) { // hide the time spinner and show a button to show it instead timeSpinner.setVisibility(GONE); ImageButton timeButton = (ImageButton) LayoutInflater.from(getContext()).inflat...
java
public void setFlags(int modeOrFlags) { // check each flag and pass it on if needed: setHideTime((modeOrFlags & FLAG_HIDE_TIME) != 0, isActivityUsingDarkTheme()); dateSpinner.setFlags(modeOrFlags); timeSpinner.setFlags(modeOrFlags); }
java
public void setTimeFormat(java.text.DateFormat timeFormat) { this.timeFormat = timeFormat; // update our pre-built timePickerDialog with the new timeFormat: initTimePickerDialog(getContext()); // save the flags and selection first: final PickerSpinnerAdapter adapter = ((PickerSp...
java
public void setShowMoreTimeItems(boolean enable) { if(enable && !showMoreTimeItems) { // create the noon and late night item: final Resources res = getResources(); // switch the afternoon item to 2pm: insertAdapterItem(new TimeItem(res.getString(R.string.time_afte...
java
public void setFlags(int modeOrFlags) { setShowMoreTimeItems((modeOrFlags & ReminderDatePicker.FLAG_MORE_TIME) != 0); setShowNumbersInView((modeOrFlags & ReminderDatePicker.FLAG_NUMBERS) != 0); }
java
public Map<String, Map<Long, FeatureShape>> getTables(String database) { Map<String, Map<Long, FeatureShape>> tables = databases.get(database); if (tables == null) { tables = new HashMap<>(); databases.put(database, tables); } return tables; }
java
public Map<Long, FeatureShape> getFeatureIds(String database, String table) { Map<String, Map<Long, FeatureShape>> tables = getTables(database); Map<Long, FeatureShape> featureIds = getFeatureIds(tables, table); return featureIds; }
java
private Map<Long, FeatureShape> getFeatureIds(Map<String, Map<Long, FeatureShape>> tables, String table) { Map<Long, FeatureShape> featureIds = tables.get(table); if (featureIds == null) { featureIds = new HashMap<>(); tables.put(table, featureIds); } return feat...
java
public FeatureShape getFeatureShape(String database, String table, long featureId) { Map<Long, FeatureShape> featureIds = getFeatureIds(database, table); FeatureShape featureShape = getFeatureShape(featureIds, featureId); return featureShape; }
java
public int getFeatureShapeCount(String database, String table, long featureId) { return getFeatureShape(database, table, featureId).count(); }
java
private FeatureShape getFeatureShape(Map<Long, FeatureShape> featureIds, long featureId) { FeatureShape featureShape = featureIds.get(featureId); if (featureShape == null) { featureShape = new FeatureShape(featureId); featureIds.put(featureId, featureShape); } re...
java
public void addMapShape(GoogleMapShape mapShape, long featureId, String database, String table) { FeatureShape featureShape = getFeatureShape(database, table, featureId); featureShape.addShape(mapShape); }
java
public void addMapMetadataShape(GoogleMapShape mapShape, long featureId, String database, String table) { FeatureShape featureShape = getFeatureShape(database, table, featureId); featureShape.addMetadataShape(mapShape); }
java
public boolean exists(long featureId, String database, String table) { boolean exists = false; Map<String, Map<Long, FeatureShape>> tables = databases.get(database); if (tables != null) { Map<Long, FeatureShape> featureIds = tables.get(table); if (featureIds != null) { ...
java
public int removeShapesWithExclusions(String database, Set<GoogleMapShapeType> excludedTypes) { int count = 0; Map<String, Map<Long, FeatureShape>> tables = getTables(database); if (tables != null) { Iterator<String> iterator = tables.keySet().iterator(); while (itera...
java
public int removeShapesWithExclusion(String database, String table, GoogleMapShapeType excludedType) { Set<GoogleMapShapeType> excludedTypes = new HashSet<>(); excludedTypes.add(excludedType); return removeShapesWithExclusions(database, table, excludedTypes); }
java
public int removeShapesWithExclusions(String database, String table, Set<GoogleMapShapeType> excludedTypes) { int count = 0; Map<Long, FeatureShape> featureIds = getFeatureIds(database, table); if (featureIds != null) { Iterator<Long> iterator = featureIds.keySet().iterator(); ...
java
public int removeShapesNotWithinMap(GoogleMap map) { int count = 0; BoundingBox boundingBox = MapUtils.getBoundingBox(map); for (String database : databases.keySet()) { count += removeShapesNotWithinMap(boundingBox, database); } return count; }
java
public int removeShapesNotWithinMap(BoundingBox boundingBox, String database) { int count = 0; Map<String, Map<Long, FeatureShape>> tables = getTables(database); if (tables != null) { for (String table : tables.keySet()) { count += removeShapesNotWithinMap(boundin...
java
public int removeShapesNotWithinMap(BoundingBox boundingBox, String database, String table) { int count = 0; Map<Long, FeatureShape> featureIds = getFeatureIds(database, table); if (featureIds != null) { List<Long> deleteFeatureIds = new ArrayList<>(); for (long feat...
java
public boolean removeFeatureShape(String database, String table, long featureId) { boolean removed = false; Map<Long, FeatureShape> featureIds = getFeatureIds(database, table); if (featureIds != null) { FeatureShape featureShape = featureIds.remove(featureId); if (featu...
java
public void remove() { switch (shapeType) { case MARKER: ((Marker) shape).remove(); break; case POLYGON: ((Polygon) shape).remove(); break; case POLYLINE: ((Polyline) shape).remove(); ...
java
public void setVisible(boolean visible) { switch (shapeType) { case MARKER_OPTIONS: ((MarkerOptions) shape).visible(visible); break; case POLYLINE_OPTIONS: ((PolylineOptions) shape).visible(visible); break; cas...
java
public void update() { switch (shapeType) { case POLYLINE_MARKERS: ((PolylineMarkers) shape).update(); break; case POLYGON_MARKERS: ((PolygonMarkers) shape).update(); break; case MULTI_POLYLINE_MARKERS: ...
java
public boolean isValid() { boolean valid = true; switch (shapeType) { case POLYLINE_MARKERS: valid = ((PolylineMarkers) shape).isValid(); break; case POLYGON_MARKERS: valid = ((PolygonMarkers) shape).isValid(); br...
java
public BoundingBox boundingBox() { BoundingBox boundingBox = new BoundingBox(Double.MAX_VALUE, Double.MAX_VALUE, -Double.MAX_VALUE, -Double.MAX_VALUE); expandBoundingBox(boundingBox); return boundingBox; }
java
public void expandBoundingBox(BoundingBox boundingBox) { switch (shapeType) { case LAT_LNG: expandBoundingBox(boundingBox, (LatLng) shape); break; case MARKER_OPTIONS: expandBoundingBox(boundingBox, ((MarkerOptions...
java
private void expandBoundingBox(BoundingBox boundingBox, LatLng latLng) { double latitude = latLng.latitude; double longitude = latLng.longitude; if (boundingBox.getMinLongitude() <= 3 * ProjectionConstants.WGS84_HALF_WORLD_LON_WIDTH && boundingBox.getMaxLongitude() >= 3 * -ProjectionConstants....
java
private void expandBoundingBox(BoundingBox boundingBox, List<LatLng> latLngs) { for (LatLng latLng : latLngs) { expandBoundingBox(boundingBox, latLng); } }
java
private void expandBoundingBoxMarkers(BoundingBox boundingBox, List<Marker> markers) { for (Marker marker : markers) { expandBoundingBox(boundingBox, marker.getPosition()); } }
java
public void setBoundingBox(BoundingBox boundingBox, Projection projection) { ProjectionTransform projectionToWebMercator = projection .getTransformation(ProjectionConstants.EPSG_WEB_MERCATOR); webMercatorBoundingBox = boundingBox .transform(projectionToWebMercator); }
java
public BoundingBox getBoundingBox(Projection projection) { ProjectionTransform webMercatorToProjection = ProjectionFactory .getProjection(ProjectionConstants.EPSG_WEB_MERCATOR) .getTransformation(projection); return webMercatorBoundingBox .transform(webMer...
java
public boolean hasTile(int x, int y, int zoom) { // Check if generating tiles for the zoom level and is within the bounding box boolean hasTile = isWithinBounds(x, y, zoom); if (hasTile) { // Check if there is a tile to retrieve hasTile = hasTileToRetrieve(x, y, zoom); ...
java
public boolean isWithinBounds(int x, int y, int zoom) { return isWithinZoom(zoom) && isWithinBoundingBox(x, y, zoom); }
java
public boolean isWithinZoom(float zoom) { return (minZoom == null || zoom >= minZoom) && (maxZoom == null || zoom <= maxZoom); }
java
public boolean isWithinBoundingBox(int x, int y, int zoom) { boolean withinBounds = true; // If a bounding box is set, check if it overlaps with the request if (webMercatorBoundingBox != null) { // Get the bounding box of the requested tile BoundingBox tileWebMercatorBo...
java
public boolean isOnAtCurrentZoom(GoogleMap map, LatLng latLng) { float zoom = MapUtils.getCurrentZoom(map); boolean on = isOnAtCurrentZoom(zoom, latLng); return on; }
java
public boolean isOnAtCurrentZoom(double zoom, LatLng latLng) { Point point = new Point(latLng.longitude, latLng.latitude); TileGrid tileGrid = TileBoundingBoxUtils.getTileGridFromWGS84(point, (int) zoom); boolean on = boundedOverlay.hasTile((int) tileGrid.getMinX(), (int) tileGrid.getMinY(), (...
java
public BoundingBox buildClickBoundingBox(LatLng latLng, BoundingBox mapBounds) { // Get the screen width and height a click occurs from a feature double width = TileBoundingBoxMapUtils.getLongitudeDistance(mapBounds) * screenClickPercentage; double height = TileBoundingBoxMapUtils.getLatitudeDi...
java
public FeatureIndexResults queryFeatures(BoundingBox boundingBox) { FeatureIndexResults results = queryFeatures(boundingBox, null); return results; }
java
public FeatureIndexResults queryFeatures(BoundingBox boundingBox, Projection projection) { if (projection == null) { projection = ProjectionFactory.getProjection(ProjectionConstants.EPSG_WORLD_GEODETIC_SYSTEM); } // Query for features FeatureIndexManager indexManager = feat...
java
public static double getToleranceDistance(View view, GoogleMap map) { BoundingBox boundingBox = getBoundingBox(map); double boundingBoxWidth = TileBoundingBoxMapUtils.getLongitudeDistance(boundingBox); double boundingBoxHeight = TileBoundingBoxMapUtils.getLatitudeDistance(boundingBox); ...
java
public static BoundingBox getBoundingBox(GoogleMap map) { LatLngBounds visibleBounds = map.getProjection() .getVisibleRegion().latLngBounds; LatLng southwest = visibleBounds.southwest; LatLng northeast = visibleBounds.northeast; double minLatitude = southwest.latitude; ...
java
public static BoundingBox buildClickBoundingBox(LatLng latLng, View view, GoogleMap map, float screenClickPercentage) { LatLngBoundingBox latLngBoundingBox = buildClickLatLngBoundingBox(latLng, view, map, screenClickPercentage); // Create the bounding box to query for features BoundingBox boun...
java
public static LatLngBounds buildClickLatLngBounds(LatLng latLng, View view, GoogleMap map, float screenClickPercentage) { LatLngBoundingBox latLngBoundingBox = buildClickLatLngBoundingBox(latLng, view, map, screenClickPercentage); double southWestLongitude = Math.min(latLngBoundingBox.getLeftCoordinat...
java